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'); }
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')); } }
/** * 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); }
protected function getContainer() { $container = new Container(); $container->set('testRef', 'testReferenceOk'); $container->setProperty('propTest', 'testPropertyOk'); return $container; }
/** * 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); }
/** * 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); }
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')); }
protected function getContainer() { $container = new Container(); $container['className'] = '\\stdClass'; $container->set('temp.dir', function ($c) { return sys_get_temp_dir(); }); return $container; }
/** * 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')); }
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); }
public function loadServices(Container $container) { $container->set('pluginService', new \stdClass()); return $container; }
/** * Converts XML Array definitions from parsing results * * @param array $arrayDefs Parsing results * @param Container $container The Di Container * * @return void */ protected function applyArrayDefinitions(array $arrayDefs, Container $container) { foreach ($arrayDefs as $name => $infos) { $shared = (bool) $this->transformValueType($infos['shared']); $array = array(); foreach ($infos['params'] as $mnfos) { $key = empty($mnfos['key']) ? null : $mnfos['key']; $val = $this->transformValueType($mnfos['value']); if (!empty($key)) { $array[$key] = $val; } else { $array[] = $val; } } $def = ArrayDefinition::factory($array)->setShared($shared)->setData($infos['data']); $container->set($name, $def); } }
/** * 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); }
public function registerService($name, $serviceName) { $this->services->set('cms.ds.' . $name, new Reference($serviceName)); $this->sources[$name] = 'cms.ds.' . $name; }
/** * 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); }