コード例 #1
0
ファイル: CmfPlugin.php プロジェクト: nitronet/fwk-cmf
 /**
  * Adds Plugin's services to the existing Container
  *
  * @param Container $container App's Services Container
  *
  * @return void
  */
 public function loadServices(Container $container)
 {
     // service
     $defService = new ClassDefinition('Nitronet\\Fwk\\CMF\\CmfService', array($this->cfg('config', ':packageDir/site/site.yml'), $this->providers, $this->routesProviders));
     $container->set($this->cfg('serviceName', 'cmf'), $defService);
     unset($this->providers, $this->routesProviders);
 }
コード例 #2
0
ファイル: ArrayDefinitionTest.php プロジェクト: fwk/di
 protected function getContainer()
 {
     $container = new Container();
     $container->set('testRef', 'testReferenceOk');
     $container->setProperty('propTest', 'testPropertyOk');
     return $container;
 }
コード例 #3
0
 public function render($pageName, Container $services, Context $context, array $config, array $params = array())
 {
     $template = $this->calculateTemplate($pageName, $context, $config);
     $pagesPath = $this->path->calculate(array($config['directories']['pages']));
     $path = str_replace($pagesPath, '', $template);
     return $services->get($this->twig)->render($path, $params);
 }
コード例 #4
0
ファイル: ResultTypePlugin.php プロジェクト: fwk/core
 /**
  * Apply Plugin's services to the existing Container
  *
  * @param Container $container App's Services Container
  *
  * @return void
  */
 public function loadServices(Container $container)
 {
     $definition = new ClassDefinition('\\Fwk\\Core\\Components\\ResultType\\ResultTypeService', array(), true);
     foreach ($this->types as $name => $type) {
         $definition->addMethodCall('addType', array($name, $type));
     }
     $container->set(self::SERVICE_NAME, $definition, true);
 }
コード例 #5
0
ファイル: ViewHelperPlugin.php プロジェクト: fwk/core
 /**
  * Apply Plugin's services to the existing Container
  *
  * @param Container $container App's Services Container
  *
  * @return void
  */
 public function loadServices(Container $container)
 {
     $definition = new ClassDefinition('\\Fwk\\Core\\Components\\ViewHelper\\ViewHelperService', array($this->propName, $this->throwExceptions), true);
     foreach ($this->helpers as $name => $helper) {
         $definition->addMethodCall('add', array($name, $helper));
     }
     $container->set(self::SERVICE_NAME, $definition, true);
 }
コード例 #6
0
ファイル: CallableDefinitionTest.php プロジェクト: fwk/di
 protected function getContainer()
 {
     $container = new Container();
     $container['className'] = '\\stdClass';
     $container->set('temp.dir', function ($c) {
         return sys_get_temp_dir();
     });
     return $container;
 }
コード例 #7
0
ファイル: LazyClassDefinition.php プロジェクト: fwk/di
 /**
  * Instanciates $this->className and return the instance.
  * 
  * @param Container   $container The Di Container
  * @param null|string $name      Name of the current definition (if any)
  * 
  * @return VirtualProxyInterface
  * @throws Exceptions\InvalidClassDefinitionException
  */
 public function invoke(Container $container, $name = null)
 {
     $proxy = $this->getProxyFactory()->createProxy($container->propertizeString($this->className), function (&$wrappedInstance, LazyLoadingInterface $proxy) use($container, $name) {
         $wrappedInstance = parent::invoke($container, $name);
         $proxy->setProxyInitializer(null);
         return true;
     });
     return $proxy;
 }
コード例 #8
0
 public function loadServices(Container $container)
 {
     // the ViewHelper
     $defViewHelper = new ClassDefinition('Nitronet\\Fwk\\Assetic\\AssetViewHelper', array($this->cfg('serviceName', 'assetic'), 'url', $this->cfg('debug', false), $this->cfg('action')));
     $container->set('assetic.ViewHelper', $defViewHelper, true);
     // filter manager
     $defFilterManager = new ClassDefinition('Assetic\\FilterManager');
     $container->set('assetic.FilterManager', $defFilterManager, true);
     // cssrewrite filter
     if ($this->cfg('cssrewrite', true) === true) {
         $defCssRewriteFilter = new ClassDefinition('Nitronet\\Fwk\\Assetic\\Filters\\CssRewriteFilter', array('@assetic.ViewHelper'));
         $container->set('assetic.CssRewriteFilter', $defCssRewriteFilter, true);
         $defFilterManager->addMethodCall('set', array('cssrewrite', '@assetic.CssRewriteFilter'));
     }
     // asset factory
     $defAssetFactory = new ClassDefinition('Assetic\\Factory\\AssetFactory', array($this->cfg('directory', null), $this->cfg('debug', false)));
     $defAssetFactory->addMethodCall('setFilterManager', array('@assetic.FilterManager'));
     $container->set('assetic.AssetFactory', $defAssetFactory, true);
     // service
     $defService = new ClassDefinition('Nitronet\\Fwk\\Assetic\\AssetsService', array('@assetic.AssetFactory'));
     $defService->addMethodCall('addShortcuts', array($this->shortcuts));
     $container->set($this->cfg('serviceName', 'assetic'), $defService, true);
     // caching
     if ($this->cfg('cache', false) === true) {
         $defFilesystemCache = new ClassDefinition('Assetic\\Cache\\FilesystemCache', array($this->cfg('cacheDir', sys_get_temp_dir())));
         $container->set('assetic.FilesystemCache', $defFilesystemCache, true);
         $defCacheBustingWorker = new ClassDefinition('Assetic\\Factory\\Worker\\CacheBustingWorker', array($this->cfg('cacheStrategy', 'content')));
         $container->set('assetic.CacheBustingWorker', $defCacheBustingWorker, true);
         $defAssetFactory->addMethodCall('addWorker', array('@assetic.CacheBustingWorker'));
         $defService->addArgument('@assetic.FilesystemCache');
         $defService->addArgument($this->cfg('cacheDir', sys_get_temp_dir()));
     }
     $container->setProperty('asseticServiceName', $this->cfg('serviceName', 'assetic'));
 }
コード例 #9
0
ファイル: GeneralEventsTest.php プロジェクト: fwk/di
 public function testDataReferenceInEvents()
 {
     $this->object->on('beforeServiceLoaded', function (BeforeServiceLoadedEvent $event) {
         $data = $event->getDefinition()->getData();
         $data['testTwo'] = "test";
         $event->getDefinition()->setData($data);
     });
     $self = $this;
     $this->object->on('afterServiceLoaded', function (AfterServiceLoadedEvent $event) use($self) {
         $data = $event->getDefinition()->getData();
         $self->assertTrue(isset($data['testTwo']));
     });
     $this->object->set('service.with.data', "da service", false, array('testOne' => true));
     $this->object->get('service.with.data');
 }
コード例 #10
0
ファイル: TwigPlugin.php プロジェクト: nitronet/fwk-twig
 public function loadServices(Container $container)
 {
     // twig loader
     $defLoader = new ClassDefinition('\\Twig_Loader_Filesystem', array($this->cfg('directory', null)));
     $container->set('twig.Loader', $defLoader);
     // twig
     $defTwig = new ClassDefinition('\\Twig_Environment', array('@twig.Loader', $this->cfg('twig', array())));
     $container->set($this->cfg('serviceName', 'twig'), $defTwig, true);
     // debug
     if ($this->cfg('debug', false) == true) {
         $defDebugExt = new ClassDefinition('\\Twig_Extension_Debug');
         $container->set('twig.DebugExtension', $defDebugExt);
         $defTwig->addMethodCall('addExtension', array('@twig.DebugExtension'));
     }
 }
コード例 #11
0
 /**
  * Adds Plugin's services to the existing Container
  *
  * @param Container $container App's Services Container
  *
  * @return void
  */
 public function loadServices(Container $container)
 {
     // service
     $defService = new ClassDefinition('Nitronet\\Fwk\\Comments\\CommentsService', array('@' . $this->cfg('dbService', 'db'), array('threadsTable' => $this->cfg('threadsTable', 'comments_threads'), 'threadEntity' => $this->cfg('threadEntity', 'Nitronet\\Fwk\\Comments\\Model\\Thread'), 'commentsTable' => $this->cfg('commentsTable', 'comments'), 'commentEntity' => $this->cfg('commentEntity', 'Nitronet\\Fwk\\Comments\\Model\\Comment'), 'autoThread' => $this->cfg('autoThread', false), 'autoApprove' => $this->cfg('autoApprove', true), 'dateFormat' => $this->cfg('dateFormat', 'Y-m-d H:i:s'))));
     $container->set($this->cfg('serviceName', 'comments'), $defService, true);
     $container->setProperty('commentsServiceName', $this->cfg('serviceName', 'comments'));
     $container->setProperty('sessionServiceName', $this->cfg('sessionService', 'session'));
     $container->setProperty('sessionServiceName', $this->cfg('rendererService', 'formRenderer'));
     $container->setProperty('commentForm', $this->cfg('commentForm', 'Nitronet\\Fwk\\Comments\\Forms\\AnonymousCommentForm'));
 }
コード例 #12
0
ファイル: ContainerTest.php プロジェクト: fwk/di
 public function testServicesSearch()
 {
     $this->object->set('testDef', ScalarDefinition::factory('definitionDataTest')->setData(array('dataOne' => true, 'text' => 'hello John')));
     $this->object->set('testDef2', ScalarDefinition::factory('definitionDataTest')->setData(array('dataOne' => false, 'text' => 'hello Doe')));
     $this->object->set('testDef3', ScalarDefinition::factory('definitionDataTest')->setData(array('dataTwo' => false, 'text' => 'Hey guys!')));
     $results = $this->object->search(array('dataOne' => true));
     $this->assertEquals(1, count($results));
     $this->assertArrayHasKey('testDef', $results);
     $results = $this->object->search(array('dataOne' => false));
     $this->assertEquals(1, count($results));
     $this->assertArrayHasKey('testDef2', $results);
     $results = $this->object->search(array('nothing'));
     $this->assertEquals(0, count($results));
     $results = $this->object->search(array('text' => 'hello*'));
     $this->assertEquals(2, count($results));
     $this->assertArrayHasKey('testDef', $results);
     $this->assertArrayHasKey('testDef2', $results);
     $results = $this->object->search(array('text' => '*guys?'));
     $this->assertEquals(1, count($results));
     $this->assertArrayHasKey('testDef3', $results);
 }
コード例 #13
0
ファイル: ClassDefinition.php プロジェクト: fwk/di
 /**
  * Instanciates the class ($this->className) 
  * 
  * @param Container   $container  The Di Container
  * @param null|string $definition Name of the current definition (if any)
  * 
  * @return object
  * @throws Exceptions\ClassNotFoundException
  * @throws Exceptions\InvalidClassDefinitionException
  */
 protected function newInstance(Container $container, $definition = null)
 {
     if (is_string($this->className) && strpos($this->className, ':') >= 0) {
         $this->className = $container->propertizeString($this->className);
     }
     if (!class_exists($this->className, true)) {
         throw new Exceptions\ClassNotFoundException($this->className);
     }
     $reflect = new \ReflectionClass($this->className);
     if (null !== $reflect->getConstructor()) {
         $args = array();
         try {
             $args = $this->getConstructorArguments($container, $definition);
         } catch (Exception $exp) {
             throw new InvalidClassDefinitionException($this->className, $definition, $exp);
         }
         $return = $reflect->newInstanceArgs($args);
     } else {
         $return = new $this->className();
     }
     return $return;
 }
コード例 #14
0
 public function registerService($name, $serviceName)
 {
     $this->services->set('cms.ds.' . $name, new Reference($serviceName));
     $this->sources[$name] = 'cms.ds.' . $name;
 }
コード例 #15
0
ファイル: CommandsListener.php プロジェクト: nitronet/fwk-cmf
 /**
  * 
  * @param \Fwk\Di\Container $container
  * 
  * @return \Symfony\Component\Console\Application
  */
 protected function getConsoleApplication(Container $container)
 {
     return $container->get($this->consoleService);
 }
コード例 #16
0
ファイル: UrlRewriterPlugin.php プロジェクト: fwk/core
 /**
  * Apply Plugin's services to the existing Container
  *
  * @param Container $container App's Services Container
  *
  * @return void
  */
 public function loadServices(Container $container)
 {
     $container->set(self::SERVICE_NAME, new ClassDefinition('\\Fwk\\Core\\Components\\UrlRewriter\\UrlRewriterService', array()), true);
 }
コード例 #17
0
ファイル: ApplicationTest.php プロジェクト: fwk/core
 public function loadServices(Container $container)
 {
     $container->set('pluginService', new \stdClass());
     return $container;
 }
コード例 #18
0
ファイル: AbstractArgsDefinition.php プロジェクト: fwk/di
 /**
  * Transform arguments to their real value if they are instance of InvokableInterface
  * or a @reference.
  * 
  * @param array<mixed> $args       List of arguments
  * @param Container    $container  The Di Container
  * @param null|string  $definition Name of the current definition (if any)
  * 
  * @return array<mixed>
  * @throws Exceptions\InvalidArgumentException
  */
 protected function propertizeArguments(array $args, Container $container, $definition = null)
 {
     $return = array();
     foreach ($args as $idx => $arg) {
         $arg = $this->transformValueType($arg);
         if (is_string($arg)) {
             $arg = $container->propertizeString($arg);
         }
         if (is_string($arg) && strpos($arg, '@', 0) === 0) {
             $arg = new Reference(substr($arg, 1));
         } elseif (is_array($arg)) {
             $arg = $this->propertizeArguments($arg, $container, $definition);
         }
         try {
             $return[$idx] = $arg instanceof InvokableInterface ? $arg->invoke($container, $definition) : $arg;
         } catch (\Fwk\Di\Exception $exp) {
             throw new Exceptions\InvalidArgumentException($idx, $definition, $exp);
         }
     }
     return $return;
 }
コード例 #19
0
ファイル: AbstractDefinition.php プロジェクト: fwk/di
 /**
  * Transforms a wildcard to a regex
  *
  * @param string $value
  *
  * @return string
  * @throws Exceptions\SearchException
  */
 protected function searchQueryToRegex($value, Container $container)
 {
     $original = $value;
     $value = $container->propertizeString($value);
     if (!is_string($value)) {
         throw new Exceptions\SearchException("Invalid Query: '{$original}' because of a non-string value.");
     }
     if (empty($value)) {
         return "/(.+){1,}/";
     }
     return '/^' . str_replace(array('?', '*'), array('(.+){1}', '(.+){1,}'), $value) . '$/';
 }
コード例 #20
0
ファイル: Reference.php プロジェクト: fwk/di
 /**
  * Return the value of the referenced Definition
  * 
  * @param Container   $container The Di Container
  * @param null|string $name      Name of the current definition (if any)
  * 
  * @return mixed
  */
 public function invoke(Container $container, $name = null)
 {
     try {
         $return = $container->get($this->name);
     } catch (DefinitionNotFoundException $exp) {
         throw new InvalidReferenceException($this->name, $name, $exp);
     }
     return $return;
 }
コード例 #21
0
ファイル: ContainerBuilder.php プロジェクト: fwk/di
 /**
  * Converts XML definitions from parsing results
  *
  * @param array     $listeners Parsing results
  * @param Container $container The Di Container
  *
  * @return void
  */
 protected function applyListeners(array $listeners, Container $container)
 {
     foreach ($listeners as $infos) {
         $class = $infos['class'];
         $service = $infos['service'];
         if (empty($class) && empty($service)) {
             throw new Exception('Invalid Xml Listener: either "class" or "service" attribute must be defined.');
         }
         if (!empty($class)) {
             $def = new ClassDefinition($class);
             $container->addListener($def->invoke($container));
             continue;
         }
         if (!$container->has($service)) {
             throw new Exception(sprintf('Invalid Xml Listener service ID: "%s"', $service));
         }
         $container->addListener($container->get($service));
     }
 }
コード例 #22
0
ファイル: RequestMatcherPlugin.php プロジェクト: fwk/core
 /**
  * Apply Plugin's services to the existing Container
  *
  * @param Container $container App's Services Container
  *
  * @return void
  */
 public function loadServices(Container $container)
 {
     $container->set(self::SERVICE_NAME, new ClassDefinition('\\Fwk\\Core\\Components\\RequestMatcher\\RequestMatcher', array($this->actionRegex)), true);
 }