Ejemplo n.º 1
0
 /**
  * Create a new configuration
  *
  * @param array $config
  * @param bool $devMode
  *
  * @return Configuration
  */
 public static function create(array $config, $devMode = true)
 {
     $resolver = self::buildOptionsResolver();
     $config = $resolver->resolve($config);
     $conf = new self();
     $map = new IdentityMap();
     $metadataRegistry = self::buildMetadataregistry($config, $devMode);
     foreach ($metadataRegistry->getMetadatas() as $meta) {
         $map->addClass($meta->getClass());
         if ($meta->hasAlias()) {
             $map->addAlias($meta->getAlias(), $meta->getClass());
         }
     }
     $proxyConfig = new ProxyConfig();
     if ($devMode === true) {
         $path = $config['cache'] . self::PROXIES_DIRECTORY;
         $filesystem = new Filesystem();
         if (!$filesystem->exists($path)) {
             $filesystem->mkdir($path);
         }
         $proxyConfig->setProxiesTargetDir($path);
         spl_autoload_register($proxyConfig->getProxyAutoloader());
     }
     $conf->setIdentityMap($map)->setMetadataRegistry($metadataRegistry)->setProxyFactory(new LazyLoadingGhostFactory($proxyConfig));
     return $conf;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $proxyCacheDirectory = $this->proxyConfiguration->getProxiesTargetDir();
     if (!is_dir($proxyCacheDirectory)) {
         mkdir($proxyCacheDirectory, 0777, true);
     }
 }
Ejemplo n.º 3
0
 public static function fromDefaultProxyFacyoryConfiguration(SchemaDiffProviderInterface $originalSchemaManipulator)
 {
     $proxyConfig = new Configuration();
     $proxyConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     $proxyFactory = new LazyLoadingValueHolderFactory($proxyConfig);
     return new LazySchemaDiffProvider($proxyFactory, $originalSchemaManipulator);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function __construct(Configuration $configuration = null)
 {
     if (null !== $configuration && sys_get_temp_dir() !== $configuration->getProxiesTargetDir()) {
         $fs = new Filesystem();
         $fs->mkdir($configuration->getProxiesTargetDir());
     }
     parent::__construct($configuration);
 }
Ejemplo n.º 5
0
 /**
  * @return \OpenClassrooms\ServiceProxy\ServiceProxyBuilderInterface
  */
 protected function getServiceProxyBuilder($cacheDir = null)
 {
     $serviceProxyBuilder = new ServiceProxyBuilder();
     $configuration = new Configuration();
     $configuration->setProxiesTargetDir($cacheDir);
     $serviceProxyBuilder->setProxyFactory($this->buildProxyFactory($configuration));
     return $serviceProxyBuilder;
 }
 /**
  * @param string $proxyManagerCacheDir
  *
  * @return Configuration
  *
  * @throws \InvalidArgumentException When $proxyManagerCacheDir is not a dir
  */
 protected function getProxyManagerConfiguration($proxyManagerCacheDir)
 {
     if (!is_dir($proxyManagerCacheDir)) {
         throw new \InvalidArgumentException(sprintf('"%s" is not a dir', $proxyManagerCacheDir));
     }
     $proxyConfiguration = new Configuration();
     $proxyConfiguration->setProxiesTargetDir($proxyManagerCacheDir);
     return $proxyConfiguration;
 }
Ejemplo n.º 7
0
 /**
  * Generates the provided `$proxyClassName` from the given `$className` and `$proxyParameters`
  * @param string $proxyClassName
  * @param string $className
  * @param array  $proxyParameters
  *
  * @return void
  */
 private function generateProxyClass($proxyClassName, $className, array $proxyParameters)
 {
     $className = $this->configuration->getClassNameInflector()->getUserClassName($className);
     $phpClass = new ClassGenerator($proxyClassName);
     $this->getGenerator()->generate(new ReflectionClass($className), $phpClass);
     $phpClass = $this->configuration->getClassSignatureGenerator()->addSignature($phpClass, $proxyParameters);
     $this->configuration->getGeneratorStrategy()->generate($phpClass);
     $this->configuration->getProxyAutoloader()->__invoke($proxyClassName);
 }
 public function testProxyIsInitializedCorrectly()
 {
     $config = new Configuration();
     spl_autoload_register($config->getProxyAutoloader());
     $factory = new TableProxyFactory($config, $this->manager);
     $this->assertInstanceOf('\\ProxyManager\\Proxy\\AccessInterceptorInterface', $factory->createProxy($this->table));
     $this->expectsThatProxyInitializes3PrefixInterceptors();
     $this->expectsThatProxyInitializes4SuffixInterceptors();
     $factory->addEventManagement($this->proxy);
 }
Ejemplo n.º 9
0
 private function cacheProxy()
 {
     $proxiesFolder = new Folder(sys_get_temp_dir() . DIRECTORY_SEPARATOR . SphringCacheEnum::CACHE_FOLDER . DIRECTORY_SEPARATOR . SphringCacheEnum::CACHE_FOLDER_PROXIES);
     $proxiesFolder->create();
     $proxyManagerConfiguration = new Configuration();
     $proxyManagerConfiguration->setProxiesTargetDir($proxiesFolder->absolute());
     $proxyFactory = new AccessInterceptorValueHolderFactory($proxyManagerConfiguration);
     ProxyGenerator::getInstance()->setProxyFactory($proxyFactory);
     spl_autoload_register($proxyManagerConfiguration->getProxyAutoloader());
 }
Ejemplo n.º 10
0
 /**
  * @param mixed $cacheDir
  */
 public function __construct($cacheDir = null)
 {
     // set a proxy cache for performance tuning
     $config = new Configuration();
     if (null !== $cacheDir) {
         $config->setProxiesTargetDir($cacheDir);
     }
     // then register the autoloader
     spl_autoload_register($config->getProxyAutoloader());
     $this->factory = new LazyLoadingValueHolderFactory($config);
 }
Ejemplo n.º 11
0
 /**
  * @param \GraphAware\Neo4j\OGM\Metadata\ClassMetadata $classMetadata
  * @param \GraphAware\Neo4j\OGM\EntityManager          $manager
  * @param string                                       $className
  */
 public function __construct(NodeEntityMetadata $classMetadata, EntityManager $manager, $className)
 {
     $this->classMetadata = $classMetadata;
     $this->entityManager = $manager;
     $this->className = $className;
     $config = new Configuration();
     $dir = sys_get_temp_dir();
     $config->setGeneratorStrategy(new FileWriterGeneratorStrategy(new FileLocator($dir)));
     $config->setProxiesTargetDir($dir);
     spl_autoload_register($config->getProxyAutoloader());
     $this->lazyLoadingFactory = new LazyLoadingGhostFactory($config);
 }
Ejemplo n.º 12
0
 /**
  * ProxyManagerFactory constructor.
  */
 public function __construct($cacheDir = null)
 {
     $this->cache = array();
     // set a proxy cache for performance tuning
     $config = new Configuration();
     if (!is_null($cacheDir)) {
         $config->setProxiesTargetDir($cacheDir);
     }
     // then register the autoloader
     spl_autoload_register($config->getProxyAutoloader());
     $this->factory = new AccessInterceptorValueHolderFactory($config);
 }
 /**
  * @param Container $container
  */
 public static function create(Container $container)
 {
     $proxyTargetDir = $container->getParameter('phpro.annotated_cache.params.proxies_target_dir');
     $proxyNamespace = $container->getParameter('phpro.annotated_cache.params.proxies_namespace');
     $shouldAutoload = $container->getParameter('phpro.annotated_cache.params.proxies_register_autoloader');
     // Make sure to touch the filesystem.
     $container->get('filesystem')->mkdir($proxyTargetDir);
     $configuration = new Configuration();
     $configuration->setProxiesTargetDir($proxyTargetDir);
     $configuration->setProxiesNamespace($proxyNamespace);
     if ($shouldAutoload) {
         spl_autoload_register($configuration->getProxyAutoloader());
     }
 }
Ejemplo n.º 14
0
 /**
  * proxy_instantiator constructor
  * @param string $cache_dir Cache dir for fall back when using open_basedir
  */
 public function __construct($cache_dir)
 {
     $config = new Configuration();
     // Prevent trying to write to system temp dir in case of open_basedir
     // restrictions being in effect
     $ini_wrapper = new IniGetWrapper();
     $filesystem = new filesystem();
     $tmp_dir = function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : '';
     if (empty($tmp_dir) || $ini_wrapper->getString('open_basedir') && (!$filesystem->exists($tmp_dir) || !$filesystem->is_writable($tmp_dir))) {
         $config->setProxiesTargetDir($cache_dir);
     }
     $config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     $this->factory = new LazyLoadingValueHolderFactory($config);
 }
 public function register(Slim $app)
 {
     $app->container->singleton('cache', function () {
         return new FilesystemCache('tmp/cache/db');
     });
     $app->container->singleton('connection', function () {
         $dbOptions = (require 'config/connection.config.php');
         $config = new Configuration();
         return DriverManager::getConnection($dbOptions, $config);
     });
     $app->container->singleton('log', function () {
         $logger = new Logger('echale-gas');
         $logger->pushHandler(new StreamHandler('tmp/logs/app.log', LogLevel::DEBUG));
         return $logger;
     });
     $app->container->singleton('paginator', function () use($app) {
         return new PagerfantaPaginator($app->config('defaultPageSize'));
     });
     $app->container->singleton('paginatorFactory', function () use($app) {
         return new PaginatorFactory($app->paginator);
     });
     $app->container->singleton('proxiesConfiguration', function () use($app) {
         $config = new ProxyConfiguration();
         $config->setProxiesTargetDir('tmp/cache/proxies');
         spl_autoload_register($config->getProxyAutoloader());
         return $config;
     });
     $app->urlHelper = new TwigExtension();
     $app->container->singleton('twig', function () use($app) {
         $twig = new Twig();
         $twig->parserOptions = ['charset' => 'utf-8', 'cache' => realpath('tmp/cache/twig'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true];
         $twig->parserExtensions = [$app->urlHelper, new HalRendererExtension()];
         return $twig;
     });
     $app->container->singleton('controllerEvents', function () use($app) {
         $eventManager = new EventManager();
         // Ensure rendering is performed at the end by assigning a very low priority
         $eventManager->attach('postDispatch', new RenderResourceListener($app->twig), -100);
         $eventManager->attach('renderErrors', new RenderErrorsListener($app->twig), -100);
         return $eventManager;
     });
     $app->container->singleton('controller', function () use($app) {
         $controller = new RestController($app->request(), $app->response());
         $factory = new RestControllerProxyFactory($app->proxiesConfiguration, $app->controllerEvents);
         $controller = $factory->createProxy($controller);
         $factory->addEventManagement($controller);
         return $controller;
     });
     $app->view($app->twig);
 }
 /**
  * @return Configuration
  */
 public function create($cacheDir, $dumpAutoload = false)
 {
     if (!is_dir($cacheDir)) {
         if (false === @mkdir($cacheDir, 0777, true)) {
             throw new \RuntimeException(sprintf('Could not create cache directory "%s".', $cacheDir));
         }
     }
     $configuration = new Configuration();
     $configuration->setProxiesTargetDir($cacheDir);
     if ($dumpAutoload) {
         spl_autoload_register($configuration->getProxyAutoloader());
     }
     return $configuration;
 }
Ejemplo n.º 17
0
 /**
  * Generate a proxy from a class name
  * @param  string $className
  * @return string proxy class name
  */
 protected function generateProxy($className)
 {
     if (!isset($this->generatedClasses[$className])) {
         $this->generatedClasses[$className] = $this->inflector->getProxyClassName($className, array('factory' => get_class($this)));
     }
     $proxyClassName = $this->generatedClasses[$className];
     if (!class_exists($proxyClassName)) {
         $className = $this->inflector->getUserClassName($className);
         $phpClass = new ClassGenerator($proxyClassName);
         $this->getGenerator()->generate(new ReflectionClass($className), $phpClass);
         $this->configuration->getGeneratorStrategy()->generate($phpClass);
         $this->configuration->getProxyAutoloader()->__invoke($proxyClassName);
     }
     return $proxyClassName;
 }
 /**
  * {@inheritDoc}
  *
  * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::__construct
  * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::createProxy
  * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::getGenerator
  *
  * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
  */
 public function testWillTryAutoGeneration()
 {
     $instance = new stdClass();
     $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
     $generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
     $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
     $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
     $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
     $generator->expects($this->once())->method('generate')->with($this->callback(function (ClassGenerator $targetClass) use($proxyClassName) {
         return $targetClass->getName() === $proxyClassName;
     }));
     // simulate autoloading
     $autoloader->expects($this->once())->method('__invoke')->with($proxyClassName)->will($this->returnCallback(function () use($proxyClassName) {
         eval('class ' . $proxyClassName . ' extends \\ProxyManagerTestAsset\\AccessInterceptorValueHolderMock {}');
     }));
     $this->inflector->expects($this->once())->method('getProxyClassName')->with('stdClass')->will($this->returnValue($proxyClassName));
     $this->inflector->expects($this->once())->method('getUserClassName')->with('stdClass')->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock'));
     $this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
     $this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
     $factory = new AccessInterceptorValueHolderFactory($this->config);
     /* @var $proxy \ProxyManagerTestAsset\AccessInterceptorValueHolderMock */
     $proxy = $factory->createProxy($instance, array('foo'), array('bar'));
     $this->assertInstanceOf($proxyClassName, $proxy);
     $this->assertSame($instance, $proxy->instance);
     $this->assertSame(array('foo'), $proxy->prefixInterceptors);
     $this->assertSame(array('bar'), $proxy->suffixInterceptors);
 }
 /**
  * {@inheritDoc}
  *
  * @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::__construct
  * @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::createProxy
  * @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::getGenerator
  *
  * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
  */
 public function testWillTryAutoGeneration()
 {
     $className = UniqueIdentifierGenerator::getIdentifier('foo');
     $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
     $generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
     $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
     $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
     $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
     $generator->expects($this->once())->method('generate')->with($this->callback(function (ClassGenerator $targetClass) use($proxyClassName) {
         return $targetClass->getName() === $proxyClassName;
     }));
     // simulate autoloading
     $autoloader->expects($this->once())->method('__invoke')->with($proxyClassName)->will($this->returnCallback(function () use($proxyClassName) {
         eval('class ' . $proxyClassName . ' extends \\ProxyManagerTestAsset\\LazyLoadingMock {}');
     }));
     $this->inflector->expects($this->once())->method('getProxyClassName')->with($className)->will($this->returnValue($proxyClassName));
     $this->inflector->expects($this->once())->method('getUserClassName')->with($className)->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock'));
     $factory = new LazyLoadingValueHolderFactory($this->config);
     $initializer = function () {
     };
     /* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */
     $proxy = $factory->createProxy($className, $initializer);
     $this->assertInstanceOf($proxyClassName, $proxy);
     $this->assertSame($initializer, $proxy->initializer);
 }
Ejemplo n.º 20
0
 /**
  * @covers \ProxyManager\Configuration::getProxyAutoloader
  * @covers \ProxyManager\Configuration::setProxyAutoloader
  */
 public function testSetGetProxyAutoloader()
 {
     $this->assertInstanceOf('ProxyManager\\Autoloader\\AutoloaderInterface', $this->configuration->getProxyAutoloader());
     $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
     $this->configuration->setProxyAutoloader($autoloader);
     $this->assertSame($autoloader, $this->configuration->getProxyAutoloader());
 }
Ejemplo n.º 21
0
 private function createProxyManager()
 {
     if ($this->proxyManager !== null) {
         return;
     }
     if (!class_exists('ProxyManager\\Configuration')) {
         throw new \RuntimeException('The ocramius/proxy-manager library is not installed. Lazy injection requires that library to be installed with Composer in order to work. Run "composer require ocramius/proxy-manager:~0.3".');
     }
     $config = new Configuration();
     if ($this->writeProxiesToFile) {
         $config->setProxiesTargetDir($this->proxyDirectory);
         spl_autoload_register($config->getProxyAutoloader());
     } else {
         $config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     }
     $this->proxyManager = new LazyLoadingValueHolderFactory($config);
 }
 /**
  * {@inheritDoc}
  * @return ConfigurationOptions
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var \Detail\Core\ProxyManager\Options\ConfigurationOptions $options */
     $options = $serviceLocator->get('Detail\\Core\\ProxyManager\\Options\\ConfigurationOptions');
     $factoryConfig = new Configuration();
     if ($options->getProxiesNamespace()) {
         $factoryConfig->setProxiesNamespace($options->getProxiesNamespace());
     }
     if ($options->getProxiesTargetDir()) {
         $factoryConfig->setProxiesTargetDir($options->getProxiesTargetDir());
     }
     if (!$options->getWriteProxyFiles()) {
         $factoryConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     }
     spl_autoload_register($factoryConfig->getProxyAutoloader());
     return new LazyLoadingValueHolderFactory($factoryConfig);
 }
Ejemplo n.º 23
0
 /**
  * @covers \ProxyManager\Configuration::getClassSignatureGenerator
  * @covers \ProxyManager\Configuration::setClassSignatureGenerator
  */
 public function testSetGetClassSignatureGenerator()
 {
     $this->assertInstanceOf('ProxyManager\\Signature\\ClassSignatureGeneratorInterface', $this->configuration->getClassSignatureGenerator());
     /* @var $classSignatureGenerator \ProxyManager\Signature\ClassSignatureGeneratorInterface */
     $classSignatureGenerator = $this->getMock('ProxyManager\\Signature\\ClassSignatureGeneratorInterface');
     $this->configuration->setClassSignatureGenerator($classSignatureGenerator);
     $this->assertSame($classSignatureGenerator, $this->configuration->getClassSignatureGenerator());
 }
 /**
  * {@inheritDoc}
  *
  * @return \Zend\ServiceManager\Proxy\LazyServiceFactory
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     if (!isset($config['lazy_services'])) {
         throw new Exception\InvalidArgumentException('Missing "lazy_services" config key');
     }
     $lazyServices = $config['lazy_services'];
     if (!isset($lazyServices['class_map'])) {
         throw new Exception\InvalidArgumentException('Missing "class_map" config key in "lazy_services"');
     }
     $factoryConfig = new Configuration();
     if (isset($lazyServices['proxies_target_dir'])) {
         $factoryConfig->setProxiesTargetDir($lazyServices['proxies_target_dir']);
     }
     if (!isset($lazyServices['write_proxy_files']) || !$lazyServices['write_proxy_files']) {
         $factoryConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     }
     if (isset($lazyServices['auto_generate_proxies'])) {
         $factoryConfig->setAutoGenerateProxies($lazyServices['auto_generate_proxies']);
         // register the proxy autoloader if the proxies already exist
         if (!$lazyServices['auto_generate_proxies']) {
             spl_autoload_register($factoryConfig->getProxyAutoloader());
             $factoryConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
         }
     }
     //if (!isset($lazyServicesConfig['runtime_evaluate_proxies']))
     if (isset($lazyServices['proxies_namespace'])) {
         $factoryConfig->setProxiesNamespace($lazyServices['proxies_namespace']);
     }
     return new LazyServiceFactory(new LazyLoadingValueHolderFactory($factoryConfig), $lazyServices['class_map']);
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     // Config must be available
     if (!isset($config['proxyManager'])) {
         throw new RuntimeException('Proxy Manager configuration must be defined. Did you copy the config file?');
     }
     $config = $config['proxyManager'];
     $configuration = new Configuration();
     // ProxiesTargetDir for caching, where set.
     if (isset($config['proxiesTargetDir'])) {
         // Directory cross-platform sensitivity
         str_replace('\\', DIRECTORY_SEPARATOR, $config['proxiesTargetDir']);
         $configuration->setProxiesTargetDir($config['proxiesTargetDir']);
         spl_autoload_register($configuration->getProxyAutoloader());
     }
     return $configuration;
 }
 /**
  * @param ServiceLocatorInterface $serviceLocator
  * @return LazyLoadingValueHolderFactory
  * @throws InvalidArgumentException
  */
 public function getLazyFactory(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->has('config') ? $serviceLocator->get('config') : [];
     $config['lazy_services'] = ArrayUtils::merge(isset($config['lazy_services']) ? $config['lazy_services'] : [], $config['bsb_flysystem']['adapter_manager']['lazy_services']);
     if (!isset($config['lazy_services'])) {
         throw new \InvalidArgumentException('Missing "lazy_services" config key');
     }
     $lazyServices = $config['lazy_services'];
     $factoryConfig = new Configuration();
     if (isset($lazyServices['proxies_namespace'])) {
         $factoryConfig->setProxiesNamespace($lazyServices['proxies_namespace']);
     }
     if (isset($lazyServices['proxies_target_dir'])) {
         $factoryConfig->setProxiesTargetDir($lazyServices['proxies_target_dir']);
     }
     if (!isset($lazyServices['write_proxy_files']) || !$lazyServices['write_proxy_files']) {
         $factoryConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     }
     spl_autoload_register($factoryConfig->getProxyAutoloader());
     return new LazyLoadingValueHolderFactory($factoryConfig);
 }
Ejemplo n.º 27
0
 /**
  * {@inheritDoc}
  *
  * @covers \ProxyManager\Factory\RemoteObjectFactory::__construct
  * @covers \ProxyManager\Factory\RemoteObjectFactory::createProxy
  * @covers \ProxyManager\Factory\RemoteObjectFactory::getGenerator
  *
  * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
  */
 public function testWillTryAutoGeneration()
 {
     $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
     $generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
     $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
     $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
     $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
     $generator->expects($this->once())->method('generate')->with($this->callback(function (ClassGenerator $targetClass) use($proxyClassName) {
         return $targetClass->getName() === $proxyClassName;
     }));
     // simulate autoloading
     $autoloader->expects($this->once())->method('__invoke')->with($proxyClassName)->will($this->returnCallback(function () use($proxyClassName) {
         eval('class ' . $proxyClassName . ' extends stdClass {}');
     }));
     $this->inflector->expects($this->once())->method('getProxyClassName')->with('ProxyManagerTestAsset\\BaseInterface')->will($this->returnValue($proxyClassName));
     $this->inflector->expects($this->once())->method('getUserClassName')->with('ProxyManagerTestAsset\\BaseInterface')->will($this->returnValue('stdClass'));
     $adapter = $this->getMock('ProxyManager\\Factory\\RemoteObject\\AdapterInterface');
     $factory = new RemoteObjectFactory($adapter, $this->config);
     /* @var $proxy \stdClass */
     $proxy = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter);
     $this->assertInstanceOf($proxyClassName, $proxy);
 }
Ejemplo n.º 28
0
 private function createProxyManager()
 {
     if ($this->proxyManager !== null) {
         return;
     }
     if (!class_exists('ProxyManager\\Configuration')) {
         throw new \RuntimeException('The ocramius/proxy-manager library is not installed. Lazy injection requires that library to be installed with Composer in order to work. Run "composer require ocramius/proxy-manager:~0.3".');
     }
     $config = new Configuration();
     /**
      * @todo useless since ProxyManager 0.5, line kept for compatibility with 0.3 and 0.4 which are
      * the only versions that work with PHP < 5.3.23
      * Remove when support for PHP 5.3 is dropped
      */
     $config->setAutoGenerateProxies(true);
     if ($this->writeProxiesToFile) {
         $config->setProxiesTargetDir($this->proxyDirectory);
         spl_autoload_register($config->getProxyAutoloader());
     } else {
         $config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     }
     $this->proxyManager = new LazyLoadingValueHolderFactory($config);
 }
Ejemplo n.º 29
0
 public function __construct(Entity $metadata, SerialisedData $data, EntityManager $entity_manager)
 {
     $this->metadata = $metadata;
     $this->serialised_data = $data;
     $this->entity_manager = $entity_manager;
     $conf = new Configuration();
     $conf->setProxiesTargetDir($entity_manager->getConfig()->getCacheDir());
     $conf->setProxiesNamespace(self::PROXY_NAMESPACE);
     $factory = new OrmProxyFactory($conf);
     $writer = $this;
     // Create the proxy with a Closure responsible for lazy-loading via this instance of the Writer
     $this->proxy = $factory->createProxy($metadata->getClassName(), function (LazyLoadingInterface $proxy, $method, array $parameters, &$initializer) use($writer) {
         // Hydrate the primitive data
         if (!$writer->is_hydrated) {
             $writer->hydrate();
         }
         // Hydrate foreign relatives on request
         $this->examineMethodForHydration($method);
         return true;
     });
     if (!$this->proxy) {
         throw new \RuntimeException("Unable to create proxy object of entity");
     }
 }
 /**
  * Constructor
  */
 public function __construct()
 {
     $config = new Configuration();
     $config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     $this->factory = new LazyLoadingValueHolderFactory($config);
 }