本文整理匯總了PHP中Symfony\Component\DependencyInjection\DefinitionDecorator::setClass方法的典型用法代碼示例。如果您正苦於以下問題:PHP DefinitionDecorator::setClass方法的具體用法?PHP DefinitionDecorator::setClass怎麽用?PHP DefinitionDecorator::setClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DependencyInjection\DefinitionDecorator
的用法示例。
在下文中一共展示了DefinitionDecorator::setClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: process
public function process(ContainerBuilder $container)
{
if (!($container->hasDefinition('fragment.listener') && $container->hasDefinition('ezpublish.decorated_fragment_renderer'))) {
return null;
}
$fragmentListenerDef = $container->findDefinition('fragment.listener');
$fragmentListenerDef->setFactoryService('ezpublish.fragment_listener.factory')->setFactoryMethod('buildFragmentListener')->addArgument('%fragment.listener.class%');
// Looping over all fragment renderers to decorate them
// This is to make sure they are siteaccess aware (siteaccess is serialized in rendered path).
foreach ($container->findTaggedServiceIds('kernel.fragment_renderer') as $id => $attributes) {
$renamedId = "{$id}.inner";
$definition = $container->getDefinition($id);
$public = $definition->isPublic();
$tags = $definition->getTags();
$definition->setPublic(false);
$container->setDefinition($renamedId, $definition);
$decoratedDef = new DefinitionDecorator('ezpublish.decorated_fragment_renderer');
$decoratedDef->setArguments(array(new Reference($renamedId)));
$decoratedDef->setPublic($public);
$decoratedDef->setTags($tags);
// Special treatment for inline fragment renderer, to fit ESI renderer constructor type hinting (forced to InlineFragmentRenderer)
if ($id === 'fragment.renderer.inline') {
$decoratedDef->setClass($container->getParameter('ezpublish.decorated_fragment_renderer.inline.class'));
}
$container->setDefinition($id, $decoratedDef);
}
}
示例2: createConverter
private function createConverter($name, array $config, ContainerBuilder $container)
{
$environment = new DefinitionDecorator($config['environment']);
$environment->setPublic(false);
$environment->setClass($container->getDefinition($config['environment'])->getClass());
$environment->addMethodCall('mergeConfig', [$config['config']]);
$environment->addTag('webuni_commonmark.environment.extensions', $config['extensions']);
// $environment->addTag('webuni_commonmark.environment', ['parent' => $config['environment'], 'extensions' => [$config['extensions']]);
$environmentName = 'webuni_commonmark.' . $name . '_environment' . $config['environment'];
$container->setDefinition($environmentName, $environment);
$parser = new DefinitionDecorator($config['parser']);
$parser->setPublic(false);
$parser->setClass($container->getDefinition($config['parser'])->getClass());
$parser->replaceArgument(0, new Reference($environmentName));
$renderer = new DefinitionDecorator($config['renderer']);
$renderer->setPublic(false);
$renderer->setClass($container->getDefinition($config['renderer'])->getClass());
$renderer->replaceArgument(0, new Reference($environmentName));
$converter = new DefinitionDecorator($config['converter']);
$converter->setPublic(true);
$converter->setClass($container->getDefinition($config['converter'])->getClass());
$converter->replaceArgument(0, $parser);
$converter->replaceArgument(1, $renderer);
$converterName = 'webuni_commonmark.' . $name . '_converter';
$container->setDefinition($converterName, $converter);
return $converterName;
}
示例3: process
/**
* @inheritdoc
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('qimnet.crud.configuration.repository')) {
return;
}
$repository = $container->getDefinition('qimnet.crud.configuration.repository');
$defaults = $container->getParameter('qimnet.crud.defaults');
foreach ($container->getParameter('qimnet.crud.services') as $name => $configuration) {
$options = $configuration['options'] + array('name' => $name) + $defaults['options'];
$configuration = $configuration + $defaults;
$serviceId = 'qimnet.crud.configuration.' . strtolower($name);
$definition = new DefinitionDecorator('qimnet.crud.configuration');
foreach (array('object_manager_factory', 'security_context_factory', 'path_generator_factory') as $index => $key) {
if ($configuration[$key]) {
$definition->replaceArgument($index, new Reference($configuration[$key]));
}
}
$definition->addArgument($options);
if ($configuration['class']) {
$definition->setClass($configuration['class']);
}
$definition->addTag('qimnet.crud.configuration', array('alias' => $name, 'object_class' => $options['object_class'], 'worker' => $configuration['worker'], 'redirection_manager' => $configuration['redirection_manager']));
$container->setDefinition($serviceId, $definition);
}
$taggedServices = $container->findTaggedServiceIds('qimnet.crud.configuration');
foreach ($taggedServices as $id => $attributes) {
$repository->addMethodCall('add', array($attributes[0]['alias'], $attributes[0]['object_class'], $id, $attributes[0]['worker'], $attributes[0]['redirection_manager']));
}
}
示例4: testMenu
public function testMenu()
{
$definition = new DefinitionDecorator('lug.ui.menu.builder');
$definition->setClass($class = $this->createMenuBuilderClassMock());
$this->container->setDefinition($menuName = 'lug.ui.menu.test', $definition);
$this->compileContainer();
$this->assertInstanceOf($class, $this->container->get($menuName));
}
示例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: setupProviderService
/**
* @param ContainerBuilder $container
* @param string $name
* @param string $options
*/
private function setupProviderService(ContainerBuilder $container, $name, $options)
{
$type = $options['type'];
unset($options['type']);
$container->setParameter("vss_oauth_extension.providers.{$name}.client_id", $options['client_id']);
$definition = new DefinitionDecorator('vss_oauth_extension.providers.generic.oauth2');
$definition->setClass("%vss_oauth_extension.providers.{$type}.class%");
$container->setDefinition('vss_oauth_extension.providers.' . $name, $definition);
$definition->replaceArgument(1, $options)->replaceArgument(2, $name);
}
示例7: convert
/**
* Converts class hierarchy metadata to definition instances.
*
* @param ClassHierarchyMetadata $metadata
* @return array an array of Definition instances
*/
public function convert(ClassHierarchyMetadata $metadata)
{
static $count = 0;
$definitions = array();
$previous = null;
foreach ($metadata->classMetadata as $classMetadata) {
if (null === $previous && null === $classMetadata->parent) {
$definition = new Definition();
} else {
$definition = new DefinitionDecorator($classMetadata->parent ?: $previous->id);
}
$definition->setClass($classMetadata->name);
if (null !== $classMetadata->scope) {
$definition->setScope($classMetadata->scope);
}
if (null !== $classMetadata->public) {
$definition->setPublic($classMetadata->public);
}
if (null !== $classMetadata->abstract) {
$definition->setAbstract($classMetadata->abstract);
}
if (null !== $classMetadata->lazy) {
$definition->setLazy($classMetadata->lazy);
}
if (null !== $classMetadata->arguments) {
$definition->setArguments($classMetadata->arguments);
}
$definition->setMethodCalls($classMetadata->methodCalls);
$definition->setTags($classMetadata->tags);
$definition->setProperties($classMetadata->properties);
if (null !== $classMetadata->decorates) {
if (!method_exists($definition, 'setDecoratedService')) {
throw new InvalidAnnotationException(sprintf("decorations require symfony >=2.8 on class %s", $classMetadata->name));
}
$definition->setDecoratedService($classMetadata->decorates, $classMetadata->decoration_inner_name);
}
if (null !== $classMetadata->deprecated && method_exists($definition, 'setDeprecated')) {
$definition->setDeprecated(true, $classMetadata->deprecated);
}
if (null === $classMetadata->id) {
$classMetadata->id = '_jms_di_extra.unnamed.service_' . $count++;
}
if (0 !== count($classMetadata->initMethods)) {
foreach ($classMetadata->initMethods as $initMethod) {
$definition->addMethodCall($initMethod);
}
} elseif (null !== $classMetadata->initMethod) {
@trigger_error('ClassMetadata::$initMethod is deprecated since version 1.7 and will be removed in 2.0. Use ClassMetadata::$initMethods instead.', E_USER_DEPRECATED);
$definition->addMethodCall($classMetadata->initMethod);
}
$definitions[$classMetadata->id] = $definition;
$previous = $classMetadata;
}
return $definitions;
}
示例8: testConstructorWithInheritance
public function testConstructorWithInheritance()
{
$container = $this->getContainer(array(), array(__DIR__ . '/../../Functional/Bundle/TestBundle/Inheritance'));
$container->set('foo', $foo = new \stdClass());
$container->set('bar', $bar = new \stdClass());
$this->process($container);
$this->assertTrue($container->hasDefinition('concrete_class'));
$this->assertTrue($container->hasDefinition('abstract_class'));
$def = new DefinitionDecorator('abstract_class');
$def->setClass('JMS\\DiExtraBundle\\Tests\\Functional\\Bundle\\TestBundle\\Inheritance\\ConcreteClass');
$def->addArgument(new Reference('foo'));
$def->addArgument(new Reference('bar'));
$this->assertEquals($def, $container->getDefinition('concrete_class'));
}
示例9: registerContainerConfiguration
public function registerContainerConfiguration(LoaderInterface $loader)
{
parent::registerContainerConfiguration($loader);
$loader->load(function (ContainerBuilder $container) {
$container->setParameter('database_user', 'test');
$container->setParameter('database_password', 'test');
$container->setParameter('database_host', 'test');
$container->setParameter('broadway.saga.mongodb.storage_suffix', 'test');
$lockingRepositoryDefinition = new DefinitionDecorator('simgroep_event_sourcing.locking_repository');
$lockingRepositoryDefinition->setClass('Simgroep\\EventSourcing\\Repository\\TestAssets\\Aggregate');
$lockingRepositoryDefinition->addArgument('Simgroep\\EventSourcing\\Repository\\TestAssets\\Aggregate');
$container->setDefinition('locking_repository', $lockingRepositoryDefinition);
});
}
示例10: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$this->hasMigrationsBundle($container)) {
return;
}
if ($this->hasOrm($container)) {
// Use Doctrine mapping (enhanced by our listeners) for schema if ORM is installed
$provider = new Definition('Doctrine\\DBAL\\Migrations\\Provider\\OrmSchemaProvider', [$container->findDefinition('doctrine.orm.entity_manager')]);
} else {
// Migrations schema provider must implement interface (only available if bundle is installed)
$provider = new DefinitionDecorator('contao.doctrine.dca_schema_provider');
$provider->setClass('Contao\\CoreBundle\\Doctrine\\Schema\\MigrationsSchemaProvider');
$this->registerDiffCommand($container, $provider);
}
$container->setDefinition('contao.doctrine.schema_provider', $provider);
}
示例11: createOwnerService
/**
* Creates a resource owner service.
*
* @example code
* $extension = $container->getExtension('glory_oauth');
* $extension->createOwnerService($container,$name,[]);
*
* @param ContainerBuilder $container The container builder
* @param string $name The name of the service
* @param array $options Additional options of the service
*/
public function createOwnerService(ContainerBuilder $container, $name, array $options)
{
$ownerId = 'glory_oauth.owner.' . $name;
// alias services
if (isset($options['service'])) {
// set the appropriate name for aliased services, compiler pass depends on it
$container->setAlias($ownerId, $options['service']);
} else {
$type = $options['type'];
unset($options['type']);
$definition = new DefinitionDecorator('glory_oauth.owner.abstract_' . GloryOAuthSupport::getOwnerType($type));
$definition->setClass("%glory_oauth.owner.{$type}.class%");
$container->setDefinition($ownerId, $definition);
$definition->replaceArgument(2, $options)->replaceArgument(3, $name);
}
$container->getDefinition('glory_oauth.ownermap')->addMethodCall('addOwner', array($name, new Reference($ownerId)));
}
示例12: load
/** {@inheritdoc} */
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('error-handler-services.xml');
$container->setParameter('error_handler.stage', $config['stage']);
$container->setParameter('error_handler.root_dir', $config['root_dir']);
$shutdownSeverity = strtoupper($config['shutdown_severity']);
$container->setParameter('error_handler.shutdown_severity', $shutdownSeverity);
$baseErrorHandler = $container->getDefinition('base_error_handler');
$baseErrorHandler->replaceArgument(0, Severity::$SEVERITIES[$shutdownSeverity]);
$errorHandler = $container->getDefinition('error_handler');
foreach ($config['categories'] as $categoryName => $categoryConfiguration) {
if (empty($categoryConfiguration['handlers'])) {
continue;
}
foreach ($categoryConfiguration['handlers'] as $handlerName => $handlerConfiguration) {
$handlerClass = $container->getParameter(sprintf('error_handler.handler_%s.class', $handlerName));
$handlerId = sprintf('error_handler.handler.%s.%s', $categoryName, $handlerName);
$handlerDefinition = new DefinitionDecorator('error_handler.abstract.handler');
$handlerDefinition->setClass($handlerClass);
$handlerDefinition->setPublic(false);
$handlerDefinition->setLazy(true);
switch ($handlerName) {
case 'bugsnag':
$handlerDefinition->addArgument($handlerConfiguration['apiKey']);
if (isset($handlerConfiguration['endpoint'])) {
$handlerDefinition->addMethodCall('setEndpoint', array($handlerConfiguration['endpoint']));
}
if (isset($handlerConfiguration['useSSL'])) {
$handlerDefinition->addMethodCall('setUseSSL', array($handlerConfiguration['useSSL']));
}
break;
case 'raven':
$handlerDefinition->addArgument($handlerConfiguration['endpoint']);
break;
}
$container->setDefinition($handlerId, $handlerDefinition);
$errorHandler->addMethodCall('addHandler', array(new Reference($handlerId), array($categoryName)));
}
}
}
示例13: convert
/**
* Converts class hierarchy metadata to definition instances.
*
* @param ClassHierarchyMetadata $metadata
* @return array an array of Definition instances
*/
public function convert(ClassHierarchyMetadata $metadata)
{
static $count = 0;
$definitions = array();
$previous = null;
foreach ($metadata->classMetadata as $classMetadata) {
if (null === $previous && null === $classMetadata->parent) {
$definition = new Definition();
} else {
$definition = new DefinitionDecorator($classMetadata->parent ?: $previous->id);
}
$definition->setClass($classMetadata->name);
if (null !== $classMetadata->scope) {
$definition->setScope($classMetadata->scope);
}
if (null !== $classMetadata->public) {
$definition->setPublic($classMetadata->public);
}
if (null !== $classMetadata->abstract) {
$definition->setAbstract($classMetadata->abstract);
}
if (null !== $classMetadata->arguments) {
$definition->setArguments($classMetadata->arguments);
}
$definition->setMethodCalls($classMetadata->methodCalls);
$definition->setTags($classMetadata->tags);
$definition->setProperties($classMetadata->properties);
if (null === $classMetadata->id) {
$classMetadata->id = '_jms_di_extra.unnamed.service_' . $count++;
}
if ($classMetadata->initMethod) {
if (!method_exists($definition, 'setInitMethod')) {
throw new \RuntimeException(sprintf('@AfterSetup is not available on your Symfony version.'));
}
$definition->setInitMethod($classMetadata->initMethod);
}
$definitions[$classMetadata->id] = $definition;
$previous = $classMetadata;
}
return $definitions;
}
示例14: createResourceOwnerService
/**
* Creates a resource owner service.
*
* @param ContainerBuilder $container The container builder
* @param string $name The name of the service
* @param array $options Additional options of the service
*/
public function createResourceOwnerService(ContainerBuilder $container, $name, array $options)
{
// alias services
if (isset($options['service'])) {
// set the appropriate name for aliased services, compiler pass depends on it
$container->setAlias('hwi_oauth.resource_owner.' . $name, $options['service']);
} else {
$type = $options['type'];
unset($options['type']);
$definition = new DefinitionDecorator('hwi_oauth.abstract_resource_owner.' . Configuration::getResourceOwnerType($type));
$definition->setClass("%hwi_oauth.resource_owner.{$type}.class%");
$container->setDefinition('hwi_oauth.resource_owner.' . $name, $definition);
$definition->replaceArgument(2, $options)->replaceArgument(3, $name);
}
}
示例15: configureResultCache
private function configureResultCache(array $config, ContainerBuilder $container, Definition $configurationDef)
{
$cacheClass = null;
$cacheId = null;
if (isset($config['class'])) {
$cacheClass = $config['class'];
} elseif (isset($config['id'])) {
$cacheId = $config['id'];
} else {
$cacheClass = "Doctrine\\Common\\Cache\\ArrayCache";
}
if (null !== $cacheClass) {
$cacheId = 'kassko_data_mapper.result_cache';
$cacheDef = new DefinitionDecorator('kassko_data_mapper.result_cache.prototype');
$cacheDef->setClass($cacheClass)->setPublic(false);
$container->setDefinition($cacheId, $cacheDef);
}
$cacheAdapterId = $cacheId . '_adapter';
$cacheAdapterDef = new Definition($config['adapter_class'], [new Reference($cacheId)]);
$container->setDefinition($cacheAdapterId, $cacheAdapterDef);
$cacheConfigId = 'kassko_data_mapper.result_cache_configuration';
$cacheConfigDef = new DefinitionDecorator('kassko_data_mapper.configuration.cache.prototype');
$cacheConfigDef->addMethodCall('setCache', [new Reference($cacheAdapterId)]);
$cacheConfigDef->addMethodCall('setLifeTime', [$config['life_time']]);
$cacheConfigDef->addMethodCall('setShared', [$config['is_shared']]);
$container->setDefinition($cacheConfigId, $cacheConfigDef);
$configurationDef->addMethodCall('setResultCacheConfig', [new Reference($cacheConfigId)]);
}