/**
  * {@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']);
 }
示例#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;
 }
 /**
  * @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;
 }
 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());
 }
示例#6
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);
 }
示例#7
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 \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);
 }
 /**
  * @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());
     }
 }
 /**
  * @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;
 }
示例#11
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);
 }
 /**
  * {@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);
 }
示例#14
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);
 }
 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);
 }
 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);
 }
示例#18
0
文件: Writer.php 项目: bravo3/orm
 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");
     }
 }
示例#19
0
 /**
  * @covers \ProxyManager\Configuration::getProxiesTargetDir
  * @covers \ProxyManager\Configuration::setProxiesTargetDir
  */
 public function testSetGetProxiesTargetDir()
 {
     $this->assertTrue(is_dir($this->configuration->getProxiesTargetDir()));
     $this->configuration->setProxiesTargetDir(__DIR__);
     $this->assertSame(__DIR__, $this->configuration->getProxiesTargetDir());
 }
 /**
  * Creates a ProxyManager configuration instance
  *
  * @return Configuration
  */
 private function getProxyFactoryConfiguration()
 {
     $configuration = new Configuration();
     if ($this->proxyCacheDirectory) {
         $this->ensureDirectoryExists($this->proxyCacheDirectory);
         $configuration->setProxiesTargetDir($this->proxyCacheDirectory);
     }
     return $configuration;
 }
示例#21
0
 /**
  * @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);
 }
示例#22
0
 /**
  * Setter for fileCachePath
  *
  * @param string $fileCachePath
  * @return SdkClient
  */
 public function setFileCachePath($fileCachePath)
 {
     $this->proxyManagerConfig = new Configuration();
     $this->proxyManagerConfig->setProxiesTargetDir($fileCachePath);
     return $this;
 }
 /**
  * Returns the ProxyManager configuration based on the current
  * {@link \bitExpert\Disco\BeanFactoryConfiguration}.
  *
  * @return Configuration
  */
 public function getProxyManagerConfiguration() : Configuration
 {
     $proxyManagerConfiguration = new Configuration();
     $proxyManagerConfiguration->setProxiesTargetDir($this->proxyTargetDir);
     if ($this->proxyWriterGenerator instanceof GeneratorStrategyInterface) {
         $proxyManagerConfiguration->setGeneratorStrategy($this->proxyWriterGenerator);
     }
     if ($this->proxyAutoloader instanceof AutoloaderInterface) {
         $proxyManagerConfiguration->setProxyAutoloader($this->proxyAutoloader);
     }
     return $proxyManagerConfiguration;
 }
示例#24
0
 /**
  * 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;
 }