/** * Get a container with collector that contains passed widgets * * @param $widgets * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getContainerWithCollectorMock($widgets) { $collector = new TypeCollector(); foreach ($widgets as $widget) { $collector->add($widget); } $container = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\ContainerInterface')->getMock(); $container->method('get')->willReturn($collector); return $container; }
function testTypeCollector() { $collector = new TypeCollector($this->getContainerMock()); $collector->add('alias1', 'id1'); $collector->add('alias2', 'id2'); $type1 = $collector->getType('alias1'); $type2 = $collector->getType('alias2'); static::assertInstanceOf(TypeInterface::class, $type1); static::assertInstanceOf(TypeInterface::class, $type2); $this->assertEquals('alias1', $type1->getType('id1')); $this->assertEquals('alias2', $type2->getType('id2')); }
protected function getUrls() { /** @var SitemapUrl[] $urls */ $urls = []; foreach ($this->configuration as $name => $configuration) { if (!isset($configuration['type'])) { throw new \InvalidArgumentException(sprintf('SitemapCollector "%s" has not type', $name)); } $type = $configuration['type']; /** @var CollectorInterface $collector */ $collector = $this->collector->getType($type); $collector = clone $collector; $collector->setOptions($configuration); $urls = array_merge($urls, $collector->getUrls()); } return $urls; }
public function createMenu(array $options) { parent::createMenu($options); $name = 'list'; if (isset($options['name'])) { $name = $options['name']; } $menu = $this->getFactory()->createItem($name); foreach ($this->menu as $name => $itemOptions) { /** @var MenuBuilderInterface $menuBuilder */ $menuBuilder = $this->menuItemTypeCollector->getType($itemOptions['type']); $itemOptions['name'] = $name; if ($menuBuilder->isGranted()) { $menu->addChild($menuBuilder->createMenu($itemOptions)); } } return $menu; }
/** * @return ItemConfiguration[] */ public function getItemConfigurations() { if ($this->itemConfigurations !== null) { return $this->itemConfigurations; } $itemConfigurations = []; foreach ($this->items as $name => $item) { $type = 'base'; if (array_key_exists('type', $item)) { $type = $item['type']; } /** @var ConfigurationInterface $configurationType */ $configurationType = $this->collector->getType($type); $itemConfigurations[] = $configurationType->configure($name, $item); } $this->itemConfigurations = $itemConfigurations; return $itemConfigurations; }
public function create(RequestConfigurationInterface $configuration, MetadataInterface $metadata = null, $newResource = null, Form $form = null, $defaultType = null) { $viewerType = $configuration->getViewerType() ? $configuration->getViewerType() : $defaultType; /** @var ViewerInterface $viewer */ $viewer = $this->collector->getType($viewerType); $viewer = clone $viewer; $viewer->setContainer($this->container); $viewer->setConfiguration($configuration); if ($metadata) { $viewer->setMetadata($metadata); } if ($form) { $viewer->setForm($form); } if ($newResource) { $viewer->setResource($newResource); } $optionAccessor = new OptionAccessor(); $viewer->configureOptions($optionAccessor); $optionAccessor->resolve($configuration->getViewerOptions()); $viewer->setOptionAccessor($optionAccessor); return $viewer; }
public function resolve($type) { $name = $this->resolveName($type); return $this->strategyTypeCollector->getType($name); }
/** * @return StorageInterface * @throws \Enhavo\Bundle\AppBundle\Exception\TypeNotFoundException */ public function getStorageByName($name) { return $this->storageTypeCollector->getType($name); }
/** * @return StorageInterface * @throws \Enhavo\Bundle\AppBundle\Exception\TypeNotFoundException */ public function getStorage() { return $this->storageTypeCollector->getType($this->storage); }
/** * @expectedException Enhavo\Bundle\AppBundle\Exception\TypeNotFoundException */ function testGettingNonExistingType() { $collector = new TypeCollector(); $collector->add($this->buildTypeMock('type1')); $collector->getType('NonExistingType'); }