PHP code example of hyperf / lazy-loader-incubator
1. Go to this page and download the library: Download hyperf/lazy-loader-incubator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hyperf / lazy-loader-incubator example snippets
// app/Service/UserInterface
interface UserInterface {
public function work();
}
// app/Service/UserService
class UserService implements UserInterface{
public function work()
{
return 'working...';
}
}
// app/Controller/IndexController
namespace App\Controller;
use App\Service\UserInterface;
use Hyperf\Di\Annotation\Inject;
class IndexController {
#[Inject(lazy: true)]
private UserInterface $userService;
public function index() {
return $this->userService->work();
}
}
// runtime/container/proxy/Hyperf_Lazy_UserService_xxx.php
namespace HyperfLazy\UserService;
/**
* Be careful: This is a lazy proxy, not the real HyperfTest\Stub\FooService from container.
*
* {@inheritdoc}
*/
class Foo extends \App\Service\UserService
{
use \Hyperf\Di\LazyLoader\LazyProxyTrait;
const PROXY_TARGET = 'HyperfTest\\Stub\\FooService';
public function work()
{
return $this->__call(__FUNCTION__, func_get_args());
}
}