Вход Регистрация
Файл: symfony-2.7/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php
Строк: 119
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyBridgeProxyManagerLazyProxyInstantiator;

use 
ProxyManagerConfiguration;
use 
ProxyManagerFactoryLazyLoadingValueHolderFactory;
use 
ProxyManagerGeneratorStrategyEvaluatingGeneratorStrategy;
use 
ProxyManagerProxyLazyLoadingInterface;
use 
SymfonyComponentDependencyInjectionContainerInterface;
use 
SymfonyComponentDependencyInjectionDefinition;
use 
SymfonyComponentDependencyInjectionLazyProxyInstantiatorInstantiatorInterface;

/**
 * Runtime lazy loading proxy generator.
 *
 * @author Marco Pivetta <ocramius@gmail.com>
 */
class RuntimeInstantiator implements InstantiatorInterface
{
    
/**
     * @var LazyLoadingValueHolderFactory
     */
    
private $factory;

    public function 
__construct()
    {
        
$config = new Configuration();
        
$config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());

        
$this->factory = new LazyLoadingValueHolderFactory($config);
    }

    
/**
     * {@inheritdoc}
     */
    
public function instantiateProxy(ContainerInterface $containerDefinition $definition$id$realInstantiator)
    {
        return 
$this->factory->createProxy(
            
$definition->getClass(),
            function (&
$wrappedInstanceLazyLoadingInterface $proxy) use ($realInstantiator) {
                
$wrappedInstance call_user_func($realInstantiator);

                
$proxy->setProxyInitializer(null);

                return 
true;
            }
        );
    }
}
Онлайн: 0
Реклама