本文整理汇总了PHP中Symfony\Component\DependencyInjection\Definition::setAbstract方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::setAbstract方法的具体用法?PHP Definition::setAbstract怎么用?PHP Definition::setAbstract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\Definition
的用法示例。
在下文中一共展示了Definition::setAbstract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testProcess
public function testProcess()
{
$container = new ContainerBuilder();
$simpleFactory = new Definition();
$simpleProcessor = new Definition('Test\\SimpleProcessor');
$simpleProcessor->addTag('processor');
$abstractProcessor = new Definition();
$abstractProcessor->setAbstract(true);
$abstractProcessor->addTag('processor');
$lazyProcessor = new Definition('Test\\LazyProcessor');
$lazyProcessor->setLazy(true);
$lazyProcessor->addTag('processor');
$withArgumentsProcessor = new Definition('Test\\WithArgumentsProcessor', ['test']);
$withArgumentsProcessor->addTag('processor');
$container->addDefinitions(['simple_factory' => $simpleFactory, 'simple_processor' => $simpleProcessor, 'abstract_processor' => $abstractProcessor, 'lazy_processor' => $lazyProcessor, 'with_arguments_processor' => $withArgumentsProcessor]);
$compilerPass = new CleanUpProcessorsCompilerPass('simple_factory', 'processor');
$compilerPass->process($container);
$this->assertFalse($container->hasDefinition('simple_processor'));
$this->assertTrue($container->hasDefinition('abstract_processor'));
$this->assertTrue($container->hasDefinition('lazy_processor'));
$this->assertTrue($container->hasDefinition('with_arguments_processor'));
$methodCalls = $simpleFactory->getMethodCalls();
$this->assertCount(1, $methodCalls);
$this->assertEquals(['addProcessor', ['simple_processor', 'Test\\SimpleProcessor']], $methodCalls[0]);
}
示例2: ensureAbstractDataCacheExists
/**
* Makes sure abstract service for data cache exists
*
* @param ContainerBuilder $container
*/
protected function ensureAbstractDataCacheExists(ContainerBuilder $container)
{
if (!$container->hasDefinition(self::DATA_CACHE_SERVICE)) {
$definition = new Definition('Oro\\Bundle\\CacheBundle\\Provider\\FilesystemCache', ['%kernel.cache_dir%/oro_data']);
$definition->setAbstract(true);
$container->setDefinition(self::DATA_CACHE_SERVICE, $definition);
}
}
示例3: ifDefinitionIsAbstractDefinitionSkipsValidation
/**
* @test
*/
public function ifDefinitionIsAbstractDefinitionSkipsValidation()
{
$definition = new Definition();
$definition->setAbstract(true);
$argumentValidator = $this->createMockArgumentsValidator();
$argumentValidator->expects($this->never())->method('validate');
$validator = new DefinitionArgumentsValidator($this->createMockConstructorResolver(), $argumentValidator);
$validator->validate($definition);
}
开发者ID:bendavies,项目名称:symfony-service-definition-validator,代码行数:12,代码来源:DefinitionArgumentsValidatorTest.php
示例4: testExceptionOnAbstractTaggedListener
/**
* @expectedException \InvalidArgumentException
*/
public function testExceptionOnAbstractTaggedListener()
{
$container = $this->createBuilder();
$abstractDefinition = new Definition('stdClass');
$abstractDefinition->setAbstract(true);
$abstractDefinition->addTag('doctrine.event_listener', array('event' => 'test'));
$container->setDefinition('a', $abstractDefinition);
$this->process($container);
}
示例5: registerPayloadResolver
private function registerPayloadResolver(ContainerBuilder $container)
{
$definition = new Definition(PayloadResolver::class);
$definition->setAbstract(true);
$container->setDefinition('request_object.payload_resolver', $definition);
$implDefinition = new DefinitionDecorator('request_object.payload_resolver');
$implDefinition->setClass(HttpPayloadResolver::class);
$container->setDefinition('request_object.payload_resolver.http', $implDefinition);
}
示例6: testProcessThrowAnExceptionIfTheServiceIsAbstract
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract.
*/
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
{
$container = new ContainerBuilder();
$container->addCompilerPass(new AddConsoleCommandPass());
$definition = new Definition('Symfony\\Bundle\\FrameworkBundle\\Tests\\DependencyInjection\\Compiler\\MyCommand');
$definition->addTag('console.command');
$definition->setAbstract(true);
$container->setDefinition('my-command', $definition);
$container->compile();
}
示例7: testAbstractDefinitionCanHaveNoClass
public function testAbstractDefinitionCanHaveNoClass()
{
$definition = new Definition();
$definition->setAbstract(true);
$containerBuilder = new ContainerBuilder();
$validator = new ServiceDefinitionValidator($containerBuilder, $this->createMockDefinitionArgumentsValidator(), $this->createMockMethodCallsValidator());
try {
$validator->validate($definition);
} catch (DefinitionHasNoClassException $e) {
$this->fail('Abstract definitions should be allowed to have no class');
}
}
开发者ID:bendavies,项目名称:symfony-service-definition-validator,代码行数:12,代码来源:ServiceDefinitionValidatorTest.php
示例8: testThrowsExceptionWhenCachePoolTagHasUnknownAttributes
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid "cache.pool" tag for service "app.cache_pool": accepted attributes are
*/
public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
{
$container = new ContainerBuilder();
$adapter = new Definition();
$adapter->setAbstract(true);
$adapter->addTag('cache.pool');
$container->setDefinition('app.cache_adapter', $adapter);
$cachePool = new DefinitionDecorator('app.cache_adapter');
$cachePool->addTag('cache.pool', array('foobar' => 123));
$container->setDefinition('app.cache_pool', $cachePool);
$this->cachePoolPass->process($container);
}
示例9: testCacheDefinitions
public function testCacheDefinitions()
{
$container = new ContainerBuilder();
$compiler = new CacheConfigurationPass();
$compiler->process($container);
$fileCacheDef = new Definition('Oro\\Bundle\\CacheBundle\\Provider\\FilesystemCache', ['%kernel.cache_dir%/oro']);
$fileCacheDef->setAbstract(true);
$this->assertEquals($fileCacheDef, $container->getDefinition(CacheConfigurationPass::FILE_CACHE_SERVICE));
$dataCacheDef = new Definition('Oro\\Bundle\\CacheBundle\\Provider\\FilesystemCache', ['%kernel.cache_dir%/oro_data']);
$dataCacheDef->setAbstract(true);
$this->assertEquals($dataCacheDef, $container->getDefinition(CacheConfigurationPass::DATA_CACHE_SERVICE));
}
示例10: testThrowsExceptionWhenCachePoolTagHasUnknownAttributes
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid "cache.pool" tag for service "app.cache_pool": accepted attributes are
*/
public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.name', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.root_dir', 'foo');
$adapter = new Definition();
$adapter->setAbstract(true);
$adapter->addTag('cache.pool');
$container->setDefinition('app.cache_adapter', $adapter);
$cachePool = new DefinitionDecorator('app.cache_adapter');
$cachePool->addTag('cache.pool', array('foobar' => 123));
$container->setDefinition('app.cache_pool', $cachePool);
$this->cachePoolPass->process($container);
}
示例11: testProcess
public function testProcess()
{
$inlineClass = 'Foo';
$this->container->setParameter('ezpublish.decorated_fragment_renderer.inline.class', $inlineClass);
$inlineRendererDef = new Definition($inlineClass);
$inlineRendererDef->addTag('kernel.fragment_renderer');
$esiRendererDef = new Definition();
$esiRendererDef->addTag('kernel.fragment_renderer');
$hincludeRendererDef = new Definition();
$hincludeRendererDef->addTag('kernel.fragment_renderer');
$decoratedFragmentRendererDef = new Definition();
$decoratedFragmentRendererDef->setAbstract(true);
$this->setDefinition('fragment.listener', new Definition());
$this->setDefinition('fragment.renderer.inline', $inlineRendererDef);
$this->setDefinition('fragment.renderer.esi', $esiRendererDef);
$this->setDefinition('fragment.renderer.hinclude', $hincludeRendererDef);
$this->setDefinition('ezpublish.decorated_fragment_renderer', $decoratedFragmentRendererDef);
$this->compile();
$this->assertTrue($this->container->hasDefinition('fragment.listener'));
$fragmentListenerDef = $this->container->getDefinition('fragment.listener');
$factoryArray = $fragmentListenerDef->getFactory();
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $factoryArray[0]);
$this->assertEquals('buildFragmentListener', $factoryArray[1]);
$this->assertEquals('ezpublish.fragment_listener.factory', $factoryArray[0]);
$this->assertTrue($this->container->hasDefinition('fragment.renderer.inline.inner'));
$this->assertSame($inlineRendererDef, $this->container->getDefinition('fragment.renderer.inline.inner'));
$this->assertFalse($inlineRendererDef->isPublic());
$this->assertTrue($this->container->hasDefinition('fragment.renderer.esi.inner'));
$this->assertSame($esiRendererDef, $this->container->getDefinition('fragment.renderer.esi.inner'));
$this->assertFalse($esiRendererDef->isPublic());
$this->assertTrue($this->container->hasDefinition('fragment.renderer.hinclude.inner'));
$this->assertSame($hincludeRendererDef, $this->container->getDefinition('fragment.renderer.hinclude.inner'));
$this->assertFalse($hincludeRendererDef->isPublic());
$this->assertContainerBuilderHasServiceDefinitionWithParent('fragment.renderer.inline', 'ezpublish.decorated_fragment_renderer');
$decoratedInlineDef = $this->container->getDefinition('fragment.renderer.inline');
$this->assertSame(array('kernel.fragment_renderer' => array(array())), $decoratedInlineDef->getTags());
$this->assertEquals(array(new Reference('fragment.renderer.inline.inner')), $decoratedInlineDef->getArguments());
$this->assertSame($inlineClass, $decoratedInlineDef->getClass());
$this->assertContainerBuilderHasServiceDefinitionWithParent('fragment.renderer.esi', 'ezpublish.decorated_fragment_renderer');
$decoratedEsiDef = $this->container->getDefinition('fragment.renderer.esi');
$this->assertSame(array('kernel.fragment_renderer' => array(array())), $decoratedEsiDef->getTags());
$this->assertEquals(array(new Reference('fragment.renderer.esi.inner')), $decoratedEsiDef->getArguments());
$this->assertContainerBuilderHasServiceDefinitionWithParent('fragment.renderer.hinclude', 'ezpublish.decorated_fragment_renderer');
$decoratedHincludeDef = $this->container->getDefinition('fragment.renderer.hinclude');
$this->assertSame(array('kernel.fragment_renderer' => array(array())), $decoratedHincludeDef->getTags());
$this->assertEquals(array(new Reference('fragment.renderer.hinclude.inner')), $decoratedHincludeDef->getArguments());
}
示例12: getAllParameters
private function getAllParameters()
{
$service = new Definition();
$service->setClass('stdClass');
$service->setAbstract(true);
$service->setFactoryClass('stdClass');
$service->setFactoryMethod('get');
$service->setFactoryService('service.fact');
$service->setFile('/file.php');
$service->setLazy(true);
$service->addMethodCall('methodCall1');
$service->addMethodCall('methodCall2', array('arg1', 'arg2'));
$service->addMethodCall('methodCall3', array(new Reference('arg.one')));
$service->setProperty('prop1', 'val1');
$service->setProperty('prop2', new Reference('prop.one'));
$service->setPublic(false);
$service->setScope('request');
$service->setSynchronized(true);
$service->setSynthetic(true);
return new ServiceElement('service.two', $service);
}
示例13: parseDefinition
/**
* Parses a definition.
*
* @param string $id
* @param array $service
* @param string $file
*
* @throws InvalidArgumentException When tags are invalid
*/
private function parseDefinition($id, $service, $file)
{
if (is_string($service) && 0 === strpos($service, '@')) {
$this->container->setAlias($id, substr($service, 1));
return;
} elseif (isset($service['alias'])) {
$public = !array_key_exists('public', $service) || (Boolean) $service['public'];
$this->container->setAlias($id, new Alias($service['alias'], $public));
return;
}
if (isset($service['parent'])) {
$definition = new DefinitionDecorator($service['parent']);
} else {
$definition = new Definition();
}
if (isset($service['class'])) {
$definition->setClass($service['class']);
}
if (isset($service['scope'])) {
$definition->setScope($service['scope']);
}
if (isset($service['synthetic'])) {
$definition->setSynthetic($service['synthetic']);
}
if (isset($service['public'])) {
$definition->setPublic($service['public']);
}
if (isset($service['abstract'])) {
$definition->setAbstract($service['abstract']);
}
if (isset($service['factory_class'])) {
$definition->setFactoryClass($service['factory_class']);
}
if (isset($service['factory_method'])) {
$definition->setFactoryMethod($service['factory_method']);
}
if (isset($service['factory_service'])) {
$definition->setFactoryService($service['factory_service']);
}
if (isset($service['file'])) {
$definition->setFile($service['file']);
}
if (isset($service['arguments'])) {
$definition->setArguments($this->resolveServices($service['arguments']));
}
if (isset($service['properties'])) {
$definition->setProperties($this->resolveServices($service['properties']));
}
if (isset($service['configurator'])) {
if (is_string($service['configurator'])) {
$definition->setConfigurator($service['configurator']);
} else {
$definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
}
}
if (isset($service['calls'])) {
foreach ($service['calls'] as $call) {
$args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
$definition->addMethodCall($call[0], $args);
}
}
if (isset($service['tags'])) {
if (!is_array($service['tags'])) {
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s.', $id, $file));
}
foreach ($service['tags'] as $tag) {
if (!isset($tag['name'])) {
throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
}
$name = $tag['name'];
unset($tag['name']);
//.........这里部分代码省略.........
示例14: resolveDefinition
/**
* Resolves the definition
*
* @param string $id The definition identifier
* @param DefinitionDecorator $definition
*
* @return Definition
*/
private function resolveDefinition($id, DefinitionDecorator $definition)
{
if (!$this->container->hasDefinition($parent = $definition->getParent())) {
throw new RuntimeException(sprintf('The parent definition "%s" defined for definition "%s" does not exist.', $parent, $id));
}
$parentDef = $this->container->getDefinition($parent);
if ($parentDef instanceof DefinitionDecorator) {
$parentDef = $this->resolveDefinition($parent, $parentDef);
}
$this->compiler->addLogMessage($this->formatter->formatResolveInheritance($this, $id, $parent));
$def = new Definition();
// merge in parent definition
// purposely ignored attributes: scope, abstract, tags
$def->setClass($parentDef->getClass());
$def->setArguments($parentDef->getArguments());
$def->setMethodCalls($parentDef->getMethodCalls());
$def->setProperties($parentDef->getProperties());
$def->setFactoryClass($parentDef->getFactoryClass());
$def->setFactoryMethod($parentDef->getFactoryMethod());
$def->setFactoryService($parentDef->getFactoryService());
$def->setConfigurator($parentDef->getConfigurator());
$def->setFile($parentDef->getFile());
$def->setPublic($parentDef->isPublic());
// overwrite with values specified in the decorator
$changes = $definition->getChanges();
if (isset($changes['class'])) {
$def->setClass($definition->getClass());
}
if (isset($changes['factory_class'])) {
$def->setFactoryClass($definition->getFactoryClass());
}
if (isset($changes['factory_method'])) {
$def->setFactoryMethod($definition->getFactoryMethod());
}
if (isset($changes['factory_service'])) {
$def->setFactoryService($definition->getFactoryService());
}
if (isset($changes['configurator'])) {
$def->setConfigurator($definition->getConfigurator());
}
if (isset($changes['file'])) {
$def->setFile($definition->getFile());
}
if (isset($changes['public'])) {
$def->setPublic($definition->isPublic());
}
// merge arguments
foreach ($definition->getArguments() as $k => $v) {
if (is_numeric($k)) {
$def->addArgument($v);
continue;
}
if (0 !== strpos($k, 'index_')) {
throw new RuntimeException(sprintf('Invalid argument key "%s" found.', $k));
}
$index = (int) substr($k, strlen('index_'));
$def->replaceArgument($index, $v);
}
// merge properties
foreach ($definition->getProperties() as $k => $v) {
$def->setProperty($k, $v);
}
// append method calls
if (count($calls = $definition->getMethodCalls()) > 0) {
$def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
}
// these attributes are always taken from the child
$def->setAbstract($definition->isAbstract());
$def->setScope($definition->getScope());
$def->setTags($definition->getTags());
// set new definition on container
$this->container->setDefinition($id, $def);
return $def;
}
示例15: parseDefinition
protected function parseDefinition($id, $service, $file)
{
if (is_string($service) && 0 === strpos($service, '@')) {
$this->container->setAlias($id, substr($service, 1));
return;
} else {
if (isset($service['alias'])) {
$public = !array_key_exists('public', $service) || (bool) $service['public'];
$this->container->setAlias($id, new Alias($service['alias'], $public));
return;
}
}
if (isset($service['parent'])) {
$definition = new DefinitionDecorator($service['parent']);
} else {
$definition = new Definition();
}
if (isset($service['class'])) {
$definition->setClass($service['class']);
}
if (isset($service['scope'])) {
$definition->setScope($service['scope']);
}
if (isset($service['synthetic'])) {
$definition->setSynthetic($service['synthetic']);
}
if (isset($service['public'])) {
$definition->setPublic($service['public']);
}
if (isset($service['abstract'])) {
$definition->setAbstract($service['abstract']);
}
if (isset($service['factory_method'])) {
$definition->setFactoryMethod($service['factory_method']);
}
if (isset($service['factory_service'])) {
$definition->setFactoryService($service['factory_service']);
}
if (isset($service['file'])) {
$definition->setFile($service['file']);
}
if (isset($service['arguments'])) {
$definition->setArguments($this->resolveServices($service['arguments']));
}
if (isset($service['configurator'])) {
if (is_string($service['configurator'])) {
$definition->setConfigurator($service['configurator']);
} else {
$definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
}
}
if (isset($service['calls'])) {
foreach ($service['calls'] as $call) {
$definition->addMethodCall($call[0], $this->resolveServices($call[1]));
}
}
if (isset($service['tags'])) {
foreach ($service['tags'] as $tag) {
$name = $tag['name'];
unset($tag['name']);
$definition->addTag($name, $tag);
}
}
$this->container->setDefinition($id, $definition);
}