コード例 #1
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;
 }
コード例 #2
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;
 }
コード例 #3
0
 /**
  * {@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']);
 }
コード例 #4
0
ファイル: ConfigurationTest.php プロジェクト: Clon450/batata
 /**
  * @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());
 }
コード例 #5
0
 private function generateProxyClass($proxyClassName, ReflectionClass $baseClass, ReflectionClass $superClass, array $proxyParameters)
 {
     $className = $this->configuration->getClassNameInflector()->getUserClassName($baseClass->getName());
     $phpClass = new ClassGenerator($proxyClassName);
     $this->getGenerator()->generate(new ReflectionClass($className), $phpClass, $superClass);
     $phpClass = $this->configuration->getClassSignatureGenerator()->addSignature($phpClass, $proxyParameters);
     $this->configuration->getGeneratorStrategy()->generate($phpClass);
     $this->configuration->getProxyAutoloader()->__invoke($proxyClassName);
 }
コード例 #6
0
 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);
 }
コード例 #7
0
 /**
  * Generates the provided `$proxyClassName` from the given `$className` and `$proxyParameters`
  *
  * @param string  $proxyClassName
  * @param string  $className
  * @param array   $proxyParameters
  * @param mixed[] $proxyOptions
  *
  * @return void
  */
 private function generateProxyClass($proxyClassName, $className, array $proxyParameters, array $proxyOptions = [])
 {
     $className = $this->configuration->getClassNameInflector()->getUserClassName($className);
     $phpClass = new ClassGenerator($proxyClassName);
     $this->getGenerator()->generate(new ReflectionClass($className), $phpClass, $proxyOptions);
     $phpClass = $this->configuration->getClassSignatureGenerator()->addSignature($phpClass, $proxyParameters);
     $this->configuration->getGeneratorStrategy()->generate($phpClass, $proxyOptions);
     $autoloader = $this->configuration->getProxyAutoloader();
     $autoloader($proxyClassName);
 }
コード例 #8
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());
 }
コード例 #9
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);
 }
コード例 #10
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);
 }
コード例 #11
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);
 }
コード例 #12
0
 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);
 }
コード例 #13
0
 /**
  * @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;
 }
コード例 #14
0
 /**
  * @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());
     }
 }
コード例 #15
0
ファイル: ProxyFactory.php プロジェクト: dmelo/PHP-DI
 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);
 }
コード例 #16
0
 /**
  * {@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);
 }
コード例 #17
0
 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;
 }
コード例 #18
0
 /**
  * @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);
 }
コード例 #19
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);
 }
コード例 #20
0
ファイル: ContainerBuilder.php プロジェクト: jewelhuq/fraym
 /**
  * @return LazyLoadingValueHolderFactory
  */
 private function buildProxyFactory()
 {
     $config = new Configuration();
     // TODO useless since ProxyManager 0.5, line kept for compatibility with previous versions
     $config->setAutoGenerateProxies(true);
     if ($this->writeProxiesToFile) {
         $config->setProxiesTargetDir($this->proxyDirectory);
         spl_autoload_register($config->getProxyAutoloader());
     } else {
         $config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     }
     return new LazyLoadingValueHolderFactory($config);
 }
コード例 #21
0
ファイル: ServiceManager.php プロジェクト: marcyniu/ai
 /**
  * Create the lazy services delegator factory.
  *
  * Creates the lazy services delegator factory based on the lazy_services
  * configuration present.
  *
  * @return Proxy\LazyServiceFactory
  * @throws ServiceNotCreatedException when the lazy service class_map
  *     configuration is missing
  */
 private function createLazyServiceDelegatorFactory()
 {
     if ($this->lazyServicesDelegator) {
         return $this->lazyServicesDelegator;
     }
     if (!isset($this->lazyServices['class_map'])) {
         throw new ServiceNotCreatedException('Missing "class_map" config key in "lazy_services"');
     }
     $factoryConfig = new ProxyConfiguration();
     if (isset($this->lazyServices['proxies_namespace'])) {
         $factoryConfig->setProxiesNamespace($this->lazyServices['proxies_namespace']);
     }
     if (isset($this->lazyServices['proxies_target_dir'])) {
         $factoryConfig->setProxiesTargetDir($this->lazyServices['proxies_target_dir']);
     }
     if (!isset($this->lazyServices['write_proxy_files']) || !$this->lazyServices['write_proxy_files']) {
         $factoryConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     }
     spl_autoload_register($factoryConfig->getProxyAutoloader());
     $this->lazyServicesDelegator = new Proxy\LazyServiceFactory(new LazyLoadingValueHolderFactory($factoryConfig), $this->lazyServices['class_map']);
     return $this->lazyServicesDelegator;
 }