PHP code example of guanguans / laravel-proxy-manager
1. Go to this page and download the library: Download guanguans/laravel-proxy-manager 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/ */
guanguans / laravel-proxy-manager example snippets
namespace App;
use App\Foo;
use Guanguans\LaravelProxyManager\Facades\ProxyManager;
use SebastianBergmann\Timer\ResourceUsageFormatter;
use SebastianBergmann\Timer\Timer;
class Foo
{
/** @var string */
private $bar;
public function __construct(string $bar = 'bar')
{
$this->bar = $bar;
sleep(3);
}
public function getBar(): string
{
return $this->bar;
}
}
//ProxyManager::bindLazyLoadingValueHolderProxy(Foo::class);
ProxyManager::singletonLazyLoadingValueHolderProxy(Foo::class);
$formatter = new ResourceUsageFormatter();
$timer = new Timer();
$timer->start();
$timer->start();
// The constructor of the original class is not triggered when the proxy class is initialized
dump($foo = app(Foo::class), $formatter->resourceUsage($timer->stop()));
// The constructor of the original class will only be triggered when it is actually called
dump($foo->getBar(), $formatter->resourceUsage($timer->stop()));