本文整理汇总了PHP中Symfony\Component\DependencyInjection\Definition::setClass方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::setClass方法的具体用法?PHP Definition::setClass怎么用?PHP Definition::setClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\Definition
的用法示例。
在下文中一共展示了Definition::setClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadRegistrationSubscriber
private function loadRegistrationSubscriber(ContainerBuilder $container, array $config)
{
$definition = new Definition();
if (array_key_exists('class', $config)) {
$definition->setClass($config['class']);
} else {
$definition->setClass('Tahoe\\Bundle\\MultiTenancyBundle\\EventSubscriber\\RegistrationSubscriber');
}
$definition->addTag('kernel.event_subscriber');
if (array_key_exists('manager', $config)) {
$definition->addArgument(new Reference($config['manager']));
} else {
$definition->addArgument(new Reference('tahoe.multi_tenancy.registration_manager'));
}
if (array_key_exists('router', $config)) {
$definition->addMethodCall('setRouter', array(new Reference($config['router'])));
} else {
$definition->addMethodCall('setRouter', array(new Reference('tahoe.multi_tenancy.tenant_aware_router')));
}
if (array_key_exists('redirect_route', $config)) {
$container->setParameter(sprintf("%s.registration_subscriber.redirect_route", $this->getAlias()), $config['redirect_route']);
} else {
// default parameter
$container->setParameter(sprintf("%s.registration_subscriber.redirect_route", $this->getAlias()), 'dashboard');
}
// we add the definition to the container
$container->setDefinition('tahoe.multi_tenancy.registration_subscriber', $definition);
}
示例2: addFormType
protected function addFormType(array $config, ContainerBuilder $container, $method)
{
$fullMethod = 'multisafepay_' . $method;
$definition = new Definition();
$definition->setClass('%ruudk_payment_multisafepay.form.default_type.class%');
$definition->addArgument($fullMethod);
if ($method === 'ideal') {
$definition->setClass('%ruudk_payment_multisafepay.form.ideal_type.class%');
$definition->addArgument(sprintf('%%ruudk_payment_multisafepay.ideal.issuers.%s%%', $config['test'] ? 'test' : 'live'));
}
$definition->addTag('payment.method_form_type');
$definition->addTag('form.type', array('alias' => $fullMethod));
$container->setDefinition(sprintf('ruudk_payment_multisafepay.form.%s_type', $method), $definition);
}
示例3: addFormType
protected function addFormType(array $config, ContainerBuilder $container, $method)
{
$mollieMethod = 'mollie_' . $method;
$definition = new Definition();
$definition->setClass('%ruudk_payment_mollie.form.mollie_type.class%');
$definition->addArgument($mollieMethod);
if ($method === 'ideal') {
$definition->setClass('%ruudk_payment_mollie.form.ideal_type.class%');
$definition->addArgument(sprintf('%%ruudk_payment_mollie.ideal.issuers.%s%%', substr($config['api_key'], 0, 4) == 'live' ? 'live' : 'test'));
}
$definition->addTag('payment.method_form_type');
$definition->addTag('form.type', array('alias' => $mollieMethod));
$container->setDefinition(sprintf('ruudk_payment_mollie.form.%s_type', $method), $definition);
}
示例4: addFormType
protected function addFormType(ContainerBuilder $container, $method)
{
$mollieMethod = 'mollie_' . $method;
$definition = new Definition();
$definition->setClass('%ruudk_payment_mollie.form.mollie_type.class%');
$definition->addArgument($mollieMethod);
if ($method === 'ideal') {
$definition->setClass('%ruudk_payment_mollie.form.ideal_type.class%');
$definition->addArgument('%kernel.cache_dir%');
}
$definition->addTag('payment.method_form_type');
$definition->addTag('form.type', array('alias' => $mollieMethod));
$container->setDefinition(sprintf('ruudk_payment_mollie.form.%s_type', $method), $definition);
}
示例5: process
public function process(ContainerBuilder $container)
{
$extensions = $container->findTaggedServiceIds('neoclient.extension_class');
$commandManager = $container->getDefinition('neoclient.command_manager');
$httpClient = $container->getDefinition('neoclient.http_client');
$requestBuilder = $container->getDefinition('neoclient.request_builder');
$extManager = $container->getDefinition('neoclient.extension_manager');
foreach ($extensions as $id => $params) {
$definition = $container->getDefinition($id);
$class = $definition->getClass();
$commands = $class::getAvailableCommands();
$extManager->addMethodCall('addExtension', array($class));
foreach ($commands as $alias => $props) {
if (array_key_exists($alias, $this->registeredCommands)) {
throw new \InvalidArgumentException(sprintf('The command with alias "%s" already exist', $alias));
}
$def = new Definition();
$def->setClass($props['class']);
$def->addArgument($httpClient);
$def->addArgument($requestBuilder);
$container->setDefinition(sprintf('neoclient.command.%s', $alias), $def);
$commandManager->addMethodCall('registerCommand', array($alias, $def));
$this->registeredCommands[$alias] = true;
}
}
$customCommands = $container->findTaggedServiceIds('neoclient.custom_command');
foreach ($customCommands as $id => $params) {
$def = $container->getDefinition($id);
$def->addArgument($httpClient);
$class = $def->getClass();
$commandManager->addMethodCall('registerCommand', array($params[0][0], $def));
}
}
示例6: createTransportDefinition
/**
* creates a transport definitions based on config
*
* @param ContainerBuilder $container
* @param array $config
* @param Definition $typeDef
* @return Definition
* @author Daniel Wendlandt
*/
private function createTransportDefinition(ContainerBuilder $container, array $config, Definition $typeDef)
{
$transportDef = new Definition();
$transportDef->setPublic(false);
switch ($config['protocol']) {
case 'thrift':
$transportDef->setClass($container->getParameter('elastification_php_client.transport.thrift.class'));
break;
default:
$transportDef->setClass($container->getParameter('elastification_php_client.transport.http.class'));
break;
}
$transportDef->setArguments(array($typeDef));
$container->setDefinition(ElastificationPhpClientExtension::SERVICE_TRANSPORT_KEY, $transportDef);
return $transportDef;
}
示例7: load
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
foreach ($config['connections'] as $name => $values) {
$def = new Definition();
$def->setClass($container->getParameter('agentsib_sphinx.connection.class'));
$params = array('host' => $values['host'], 'port' => $values['port']);
if ($values['socket']) {
$params['socket'] = $values['socket'];
}
$def->setArguments(array($name, $values['driver'], $params));
$def->addMethodCall('addLogger', array(new Reference('agentsib_sphinx.logger')));
$container->setDefinition(sprintf('agentsib_sphinx.%s.connection', $name), $def);
$helperDef = new DefinitionDecorator('agentsib_sphinx.factory.helper');
$helperDef->setFactoryClass($container->getParameter('agentsib_sphinx.helper.class'));
$helperDef->setFactoryMethod('create');
$helperDef->addArgument(new Reference(sprintf('agentsib_sphinx.%s.connection', $name)));
$helperDef->setPublic(true);
$container->setDefinition(sprintf('agentsib_sphinx.%s.helper', $name), $helperDef);
if ($name == $config['default_connection']) {
$container->setAlias('agentsib_sphinx.connection', sprintf('agentsib_sphinx.%s.connection', $name));
$container->setAlias('agentsib_sphinx.helper', sprintf('agentsib_sphinx.%s.helper', $name));
}
}
}
示例8: it_should_not_override_default_theme_factory
public function it_should_not_override_default_theme_factory(ContainerBuilder $container, Definition $definition)
{
$container->hasDefinition('sylius.factory.theme')->willReturn(false);
$container->getDefinition('sylius.factory.theme')->shouldNotBeCalled();
$definition->setClass(ThemeFactory::class)->shouldNotBeCalled();
$this->process($container)->shouldReturn(null);
}
示例9: notify
public function notify(\Exception $exception)
{
if (!$exception instanceof ServiceNotFoundException) {
return;
}
$serviceId = $exception->getId();
$guessedFqcn = $this->guessFqcn($serviceId);
$definition = new Definition();
$definition->setClass($guessedFqcn);
$containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions([$serviceId => $definition]);
$dumper = new YamlDumper($containerBuilder);
$result = $dumper->dump();
$message = sprintf('Service `%s` missing. Define it in your services.yml:', $serviceId);
$this->output->writeln('--- ' . $message . PHP_EOL);
$this->output->write($result, true);
$errorMessages = ['Service ' . $serviceId . ' was not found.'];
$formatter = new FormatterHelper();
$formattedBlock = $formatter->formatBlock($errorMessages, 'error', true);
$this->output->writeln('');
$this->output->writeln($formattedBlock);
$this->output->writeln('');
$question = sprintf('<question>Do you want to create a specification for %s? (Y/n)</question>', $guessedFqcn);
$dialog = new DialogHelper();
if ($dialog->askConfirmation($this->output, $question, true)) {
$this->specRunner->runDescCommand($guessedFqcn);
}
}
示例10: testDumpOptimizationString
public function testDumpOptimizationString()
{
$definition = new Definition();
$definition->setClass('stdClass');
$definition->addArgument(array(
'only dot' => '.',
'concatenation as value' => '.\'\'.',
'concatenation from the start value' => '\'\'.',
'.' => 'dot as a key',
'.\'\'.' => 'concatenation as a key',
'\'\'.' =>'concatenation from the start key',
'optimize concatenation' => "string1%some_string%string2",
'optimize concatenation with empty string' => "string1%empty_value%string2",
'optimize concatenation from the start' => '%empty_value%start',
'optimize concatenation at the end' => 'end%empty_value%',
));
$container = new ContainerBuilder();
$container->setDefinition('test', $definition);
$container->setParameter('empty_value', '');
$container->setParameter('some_string', '-');
$container->compile();
$dumper = new PhpDumper($container);
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services10.php', $dumper->dump(), '->dump() dumps an empty container as an empty PHP class');
}
示例11: buildTranslationStorageDefinition
/**
* Build the 'lexik_translation.translation_storage' service definition.
*
* @param ContainerBuilder $container
* @param string $storage
* @param string $objectManager
*/
protected function buildTranslationStorageDefinition(ContainerBuilder $container, $storage, $objectManager)
{
$container->setParameter('lexik_translation.storage.type', $storage);
if ('orm' == $storage) {
if (isset($objectManager)) {
$objectManagerReference = new Reference(sprintf('doctrine.orm.%s_entity_manager', $objectManager));
} else {
$objectManagerReference = new Reference('doctrine.orm.entity_manager');
}
} else {
if ('mongodb' == $storage) {
if (isset($objectManager)) {
$objectManagerReference = new Reference(sprintf('doctrine_mongodb.odm.%s_document_manager', $objectManager));
} else {
$objectManagerReference = new Reference('doctrine.odm.mongodb.document_manager');
}
} else {
if ('propel' == $storage) {
// In the Propel case the object_manager setting is used for the connection name
if (isset($objectManager)) {
$objectManagerReference = $objectManager;
} else {
$objectManagerReference = null;
}
} else {
throw new \RuntimeException(sprintf('Unsupported storage "%s".', $storage));
}
}
}
$storageDefinition = new Definition();
$storageDefinition->setClass(new Parameter(sprintf('lexik_translation.%s.translation_storage.class', $storage)));
$storageDefinition->setArguments(array($objectManagerReference, array('trans_unit' => new Parameter(sprintf('lexik_translation.%s.trans_unit.class', $storage)), 'translation' => new Parameter(sprintf('lexik_translation.%s.translation.class', $storage)), 'file' => new Parameter(sprintf('lexik_translation.%s.file.class', $storage)))));
$container->setDefinition('lexik_translation.translation_storage', $storageDefinition);
}
示例12: testProviderIsAdded
public function testProviderIsAdded()
{
$targetService = new Definition();
$targetService->setClass('Faker\\Generator');
$provider = $this->getMock('Acme\\Faker\\Provider\\CustomFakeDataProvider');
$providerService = new Definition();
$providerService->setClass(get_class($provider));
$providerService->addTag('bazinga_faker.provider');
$builder = new ContainerBuilder();
$builder->addDefinitions(array('faker.generator' => $targetService, 'acme.faker.provider.custom' => $providerService));
$builder->addCompilerPass(new AddProvidersPass());
$builder->compile();
$this->assertNotEmpty($builder->getServiceIds(), 'The services have been injected.');
$this->assertNotEmpty($builder->get('faker.generator'), 'The faker.generator service has been injected.');
$this->assertNotEmpty($builder->get('acme.faker.provider.custom'), 'The provider service has been injected.');
/*
* Schema:
*
* [0] The list of methods.
* [0] The name of the method to call.
* [1] The arguments to pass into the method call.
* [0] First argument to pass into the method call.
* ...
*/
$targetMethodCalls = $builder->getDefinition('faker.generator')->getMethodCalls();
$this->assertNotEmpty($targetMethodCalls, 'The faker.generator service got method calls added.');
$this->assertEquals('addProvider', $targetMethodCalls[0][0], 'The faker.generator service got a provider added.');
$this->assertEquals('acme.faker.provider.custom', $targetMethodCalls[0][1][0], 'The faker.generator service got the correct provider added.');
}
示例13: compileDefinition
/**
* Compiles the $id service's $definition with all the aspects provided.
*
* @param string $id
* @param \Symfony\Component\DependencyInjection\Definition $definition
*/
protected function compileDefinition($id, Definition $definition)
{
$refClass = new ReflectionClass($definition->getClass());
$aspectGenerator = new AspectGenerator($this->annotationReader, $this->annotationClassName);
if ($aspectGenerator->hasAnnotation($refClass)) {
$pg = new ProxyGenerator($refClass, array($aspectGenerator));
$filename = $this->proxyDirectory . '/' . str_replace('\\', '-', $refClass->name) . '.php';
$pg->writeClass($filename);
$definition->setClass($pg->getClassName($refClass));
$definition->setFile($filename);
$definition->setClass($pg->getClassName($refClass));
foreach ($this->serviceNames as $serviceName) {
$definition->addArgument(new Reference($serviceName));
}
}
}
示例14: it_should_not_override_default_theme_assets_installer
public function it_should_not_override_default_theme_assets_installer(ContainerBuilder $container, Definition $definition)
{
$container->hasDefinition('sylius.theme.asset.assets_installer')->willReturn(false);
$container->getDefinition('sylius.theme.asset.assets_installer')->shouldNotBeCalled();
$definition->setClass(AssetsInstaller::class)->shouldNotBeCalled();
$this->process($container)->shouldReturn(null);
}
示例15: registerResponseListener
protected function registerResponseListener(ContainerBuilder $container)
{
$definition = new Definition();
$definition->setClass($container->getParameter('xsolve.cookie_acknowledgement_bar.event_listener.class'));
$definition->addArgument(new Reference('xsolve.cookie_acknowledgement_bar.service'));
$definition->addTag('kernel.event_listener', array('event' => 'kernel.response', 'method' => 'onKernelResponse'));
$container->setDefinition('xsolve.cookie_acknowledgement_bar.event_listener', $definition);
}
开发者ID:vladab,项目名称:cookie-acknowledgement-bundle,代码行数:8,代码来源:XsolveCookieAcknowledgementExtension.php