本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::findDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::findDefinition方法的具体用法?PHP ContainerBuilder::findDefinition怎么用?PHP ContainerBuilder::findDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::findDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
// loaders
$loaders = array();
$loadersReferences = array();
foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
$loaders[$id][] = $attributes[0]['alias'];
$loadersReferences[$attributes[0]['alias']] = new Reference($id);
if (isset($attributes[0]['legacy-alias'])) {
$loaders[$id][] = $attributes[0]['legacy-alias'];
$loadersReferences[$attributes[0]['legacy-alias']] = new Reference($id);
}
}
if ($container->hasDefinition('lexik_translation.translator')) {
$container->findDefinition('lexik_translation.translator')->replaceArgument(2, $loaders);
}
if ($container->hasDefinition('lexik_translation.importer.file')) {
$container->findDefinition('lexik_translation.importer.file')->replaceArgument(0, $loadersReferences);
}
// exporters
if ($container->hasDefinition('lexik_translation.exporter_collector')) {
foreach ($container->findTaggedServiceIds('lexik_translation.exporter') as $id => $attributes) {
$container->getDefinition('lexik_translation.exporter_collector')->addMethodCall('addExporter', array($id, new Reference($id)));
}
}
}
示例2: process
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('translator.writer') || !$container->hasDefinition('translator.real')) {
return;
}
$translatorRealDefinition = $container->findDefinition('translator.real');
$translatorDefinition = $container->findDefinition('translator.writer');
$translatorDefinition->replaceArgument(2, $translatorRealDefinition->getArgument(2));
foreach($translatorRealDefinition->getMethodCalls() as $methodCall) {
$translatorDefinition->addMethodCall($methodCall[0], $methodCall[1]);
// use resources from translator.real to add available locales
if ('addResource' === $methodCall[0]) {
// $methodCall[1][2] is the locale
// @see FrameworkBundle\DependencyInjection\FrameworkExtension::registerTranslatorConfiguration
$translatorDefinition->addMethodCall('addLocale', array($methodCall[1][2]));
}
}
foreach($container->findTaggedServiceIds('knplabs_translator.dumper') as $id => $attributes) {
$translatorDefinition->addMethodCall('addDumper', array($container->getDefinition($id)));
}
}
示例3: process
public function process(ContainerBuilder $container)
{
if ($container->has('fos_rest.serializer')) {
$class = $container->getParameterBag()->resolveValue($container->findDefinition('fos_rest.serializer')->getClass());
if (!is_subclass_of($class, 'FOS\\RestBundle\\Serializer\\Serializer')) {
throw new \InvalidArgumentException(sprintf('"fos_rest.serializer" must implement FOS\\RestBundle\\Serializer\\Serializer (instance of "%s" given).', $class));
}
return;
}
if (!$container->has('serializer') && !$container->has('jms_serializer.serializer')) {
throw new \InvalidArgumentException('Neither a service called "jms_serializer.serializer" nor "serializer" is available and no serializer is explicitly configured. You must either enable the JMSSerializerBundle, enable the FrameworkBundle serializer or configure a custom serializer.');
}
if ($container->has('serializer')) {
$class = $container->getParameterBag()->resolveValue($container->findDefinition('serializer')->getClass());
if (is_subclass_of($class, 'Symfony\\Component\\Serializer\\SerializerInterface')) {
$container->setAlias('fos_rest.serializer', 'fos_rest.serializer.symfony');
$container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
} elseif (is_subclass_of($class, 'JMS\\Serializer\\SerializerInterface')) {
$container->setAlias('fos_rest.serializer', 'fos_rest.serializer.jms');
} elseif (is_subclass_of($class, 'FOS\\RestBundle\\Serializer\\Serializer')) {
$container->setAlias('fos_rest.serializer', 'serializer');
} else {
throw new \InvalidArgumentException(sprintf('"fos_rest.serializer" must implement FOS\\RestBundle\\Serializer\\Serializer (instance of "%s" given).', $class));
}
return;
} else {
$container->removeDefinition('fos_rest.serializer.exception_wrapper_normalizer');
}
if ($container->has('jms_serializer.serializer')) {
$container->setAlias('fos_rest.serializer', 'fos_rest.serializer.jms');
} else {
$container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
}
}
示例4: process
public function process(ContainerBuilder $container)
{
// log
$definition = $container->findDefinition('csa_guzzle.subscriber.log');
$logServiceId = $container->getParameter('csa_guzzle.subscriber.log.service');
if ($container->hasDefinition($logServiceId)) {
$definition->replaceArgument(0, new Reference($logServiceId));
}
$channel = $container->getParameter('csa_guzzle.subscriber.log.channel');
if (!empty($channel)) {
$definition->clearTag('monolog.logger');
$definition->addTag('monolog.logger', array('channel' => $channel));
}
// Cache
$cacheServiceId = $container->getParameter('csa_guzzle.subscriber.cache.service');
if ($container->hasDefinition($cacheServiceId)) {
$container->setDefinition('csa_guzzle.cache_storage', new Definition('%csa_guzzle.cache_storage.class%', array(new Reference($cacheServiceId), $container->getParameter('csa_guzzle.subscriber.cache.prefix'))));
$cacheSubscriber = new Definition('%csa_guzzle.subscriber.cache.class%', array(new Reference('csa_guzzle.cache_storage'), $container->getParameter('csa_guzzle.subscriber.cache.enable')));
$cacheSubscriber->addTag('csa_guzzle.subscriber');
$container->setDefinition('csa_guzzle.subscriber.cache', $cacheSubscriber);
}
// get all Guzzle subscribers
$subscribers = $container->findTaggedServiceIds('csa_guzzle.subscriber');
if (!count($subscribers)) {
return;
}
// Factory
$factory = $container->findDefinition('csa_guzzle.client_factory');
$arg = [];
foreach ($subscribers as $subscriber => $options) {
$arg[] = new Reference($subscriber);
}
$factory->replaceArgument(1, $arg);
}
示例5: process
public function process(ContainerBuilder $container)
{
$clearSpoolsId = 'long_running.swift_mailer.clear_spools';
if (!$container->has($clearSpoolsId)) {
return;
}
if (!$container->hasAlias('swiftmailer.mailer') || $container->getParameter('swiftmailer.mailers') === []) {
return;
}
$spoolServiceReferences = [];
$realTransportServiceReferences = [];
$mailers = $container->getParameter('swiftmailer.mailers');
foreach ($mailers as $name => $mailer) {
if ($container->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name))) {
$transport = sprintf('swiftmailer.mailer.%s.transport', $name);
$transportDefinition = $container->findDefinition($transport);
if (is_a($transportDefinition->getClass(), 'Swift_Transport_SpoolTransport', true)) {
$spool = sprintf('swiftmailer.mailer.%s.spool', $name);
$spoolDefinition = $container->findDefinition($spool);
if (is_a($spoolDefinition->getClass(), 'Swift_MemorySpool', true)) {
$realTransport = sprintf('swiftmailer.mailer.%s.transport.real', $name);
$spoolServiceReferences[$name] = new Reference($spool);
$realTransportServiceReferences[$name] = new Reference($realTransport);
}
}
}
}
$definition = $container->getDefinition($clearSpoolsId);
$definition->replaceArgument(0, $spoolServiceReferences);
$definition->replaceArgument(1, $realTransportServiceReferences);
}
示例6: process
public function process(ContainerBuilder $container)
{
$tags = $container->findTaggedServiceIds('cmf_media.upload_editor_helper');
if (count($tags) > 0) {
if ($container->has('cmf_media.upload_file_helper')) {
$manager = $container->findDefinition('cmf_media.upload_file_helper');
foreach ($tags as $id => $tag) {
$manager->addMethodCall('addEditorHelper', array($tag[0]['alias'], new Reference($id)));
}
}
if ($container->has('cmf_media.upload_image_helper')) {
$manager = $container->findDefinition('cmf_media.upload_image_helper');
foreach ($tags as $id => $tag) {
$manager->addMethodCall('addEditorHelper', array($tag[0]['alias'], new Reference($id)));
}
}
}
$tags = $container->findTaggedServiceIds('cmf_media.browser_file_helper');
if (count($tags) > 0) {
if ($container->has('cmf_media.browser_file_helper')) {
$manager = $container->findDefinition('cmf_media.browser_file_helper');
foreach ($tags as $id => $tag) {
$manager->addMethodCall('addEditorHelper', array($tag[0]['editor'], $tag[0]['browser'], new Reference($id)));
}
}
}
}
示例7: load
/**
* @param array $configs
* @param ContainerBuilder $container
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$this->copyValuesFromParentToProject('locales', $config);
$this->copyValuesFromParentToProject('domains', $config);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
if ($config['auto_add_assets']) {
$loader->load('autoAdd.yml');
}
$container->setParameter('translation.toolbar.allow_edit', $config['allow_edit']);
/*
* Set an alias for the adapter
*/
$adapter = $config['http_adapter'];
if ($adapter === 'guzzle5' || $adapter === 'guzzle6') {
//Use one of our adapters
$adapter = 'happyr.translation.http_adapter.' . $adapter;
}
$container->setAlias('happyr.translation.http_adapter', $adapter);
$targetDir = rtrim($config['target_dir'], '/');
$container->findDefinition('happyr.translation.filesystem')->replaceArgument(2, $targetDir);
/*
* Set alias for the translation service
*/
$container->setAlias('happyr.translation', 'happyr.translation.service.' . $config['translation_service']);
$container->findDefinition('happyr.translation.service.loco')->replaceArgument(2, $config['projects'])->replaceArgument(3, $targetDir);
}
示例8: get
/**
* @param $id
*
* @return string|null
*/
public function get($id)
{
if (!$this->has($id)) {
return;
}
return $this->container->findDefinition($id)->getClass();
}
示例9: handleConfiguration
protected function handleConfiguration($config, ContainerBuilder $container)
{
if (!isset($config['features'])) {
return;
}
if (!$container->hasDefinition('hotflo_feature_toggle.feature_container')) {
return;
}
$featureToggleContainerDefinition = $container->findDefinition('hotflo_feature_toggle.feature_toggle_container');
foreach ($config['toggles'] as $toggle => $properties) {
if ($properties['type'] == 'service') {
$container->setAlias('hotflo_feature_toggle.toggle.' . $toggle, $properties['service']);
} else {
if (!class_exists($properties['class'])) {
throw new InvalidConfigurationException(sprintf('Class \'%s\' not found.', $properties['class']));
}
$toggleDefinition = new Definition($properties['class']);
$toggleDefinition->addArgument($properties['options']);
$container->setDefinition('hotflo_feature_toggle.toggle.' . $toggle, $toggleDefinition);
}
$featureToggleContainerDefinition->addMethodCall('addFeatureToggle', [new Reference('hotflo_feature_toggle.toggle.' . $toggle), $toggle]);
}
$featureContainerDefinition = $container->findDefinition('hotflo_feature_toggle.feature_container');
foreach ($config['features'] as $feature => $properties) {
$featureDefinition = new Definition('JoshuaEstes\\Component\\FeatureToggle\\Feature');
$featureDefinition->addArgument($properties['options']);
$featureDefinition->addMethodCall('setKey', [$feature]);
$featureDefinition->addMethodCall('setToggle', [new Reference('hotflo_feature_toggle.toggle.' . $properties['toggle'])]);
$container->setDefinition('hotflo_feature_toggle.feature.' . $feature, $featureDefinition);
$featureContainerDefinition->addMethodCall('addFeature', [new Reference('hotflo_feature_toggle.feature.' . $feature)]);
}
}
示例10: process
public function process(ContainerBuilder $container)
{
if (!($container->hasDefinition('security.authentication.provider.dao') && $container->hasDefinition('security.authentication.provider.anonymous'))) {
return;
}
$configResolverRef = new Reference('ezpublish.config.resolver');
$repositoryReference = new Reference('ezpublish.api.repository');
// Inject the Repository in the authentication provider.
// We need it for checking user credentials
$daoAuthenticationProviderDef = $container->findDefinition('security.authentication.provider.dao');
$daoAuthenticationProviderDef->addMethodCall('setRepository', array($repositoryReference));
$anonymousAuthenticationProviderDef = $container->findDefinition('security.authentication.provider.anonymous');
$anonymousAuthenticationProviderDef->addMethodCall('setRepository', array($repositoryReference));
$anonymousAuthenticationProviderDef->addMethodCall('setConfigResolver', array($configResolverRef));
if (!$container->hasDefinition('security.http_utils')) {
return;
}
$httpUtilsDef = $container->findDefinition('security.http_utils');
$httpUtilsDef->addMethodCall('setSiteAccess', array(new Reference('ezpublish.siteaccess')));
if (!$container->hasDefinition('security.authentication.success_handler')) {
return;
}
$successHandlerDef = $container->getDefinition('security.authentication.success_handler');
$successHandlerDef->addMethodCall('setConfigResolver', array($configResolverRef));
}
示例11: registerLoggerConfiguration
/**
* Loads the logger configuration.
*
* Usage example:
*
* <zend:logger priority="info" path="/path/to/some.log" />
*
* @param array $config An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
protected function registerLoggerConfiguration($config, ContainerBuilder $container)
{
$config = $config['logger'];
if (!$container->hasDefinition('zend.logger')) {
$loader = new XmlFileLoader($container, __DIR__.'/../Resources/config');
$loader->load('logger.xml');
$container->setAlias('logger', 'zend.logger');
}
if (isset($config['priority'])) {
$container->setParameter('zend.logger.priority', is_int($config['priority']) ? $config['priority'] : constant('\\Zend\\Log\\Logger::'.strtoupper($config['priority'])));
}
if (isset($config['path'])) {
$container->setParameter('zend.logger.path', $config['path']);
}
if (isset($config['log_errors'])) {
$definition = $container->findDefinition('zend.logger');
if (false === $config['log_errors'] && $definition->hasMethodCall('registerErrorHandler')) {
$container->findDefinition('zend.logger')->removeMethodCall('registerErrorHandler');
}
else {
$container->findDefinition('zend.logger')->addMethodCall('registerErrorHandler');
}
}
}
示例12: processClient
/**
* @param array $config
* @param ContainerBuilder $container
*/
private function processClient(array $config, ContainerBuilder $container)
{
if (null === $config['client']) {
return;
}
$container->findDefinition('nexy_paybox_direct.sdk')->addArgument($container->findDefinition('nexy_paybox_direct.http_client.' . $config['client']));
}
示例13: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$configuration = new Configuration();
$processor = new Processor();
$config = $processor->processConfiguration($configuration, $configs);
if ($config['pdf']['enabled']) {
$loader->load('pdf.xml');
$container->setParameter('knp_snappy.pdf.binary', $config['pdf']['binary']);
$container->setParameter('knp_snappy.pdf.options', $config['pdf']['options']);
$container->setParameter('knp_snappy.pdf.env', $config['pdf']['env']);
if (!empty($config['temporary_folder'])) {
$container->findDefinition('knp_snappy.pdf.internal_generator')->addMethodCall('setTemporaryFolder', array($config['temporary_folder']));
}
}
if ($config['image']['enabled']) {
$loader->load('image.xml');
$container->setParameter('knp_snappy.image.binary', $config['image']['binary']);
$container->setParameter('knp_snappy.image.options', $config['image']['options']);
$container->setParameter('knp_snappy.image.env', $config['image']['env']);
if (!empty($config['temporary_folder'])) {
$container->findDefinition('knp_snappy.image.internal_generator')->addMethodCall('setTemporaryFolder', array($config['temporary_folder']));
}
}
}
示例14: process
public function process( ContainerBuilder $container )
{
if ( !$container->hasAlias( 'session.storage' ) )
{
return;
}
$sessionStorageAlias = $container->getAlias( 'session.storage' );
$sessionStorageProxyDef = $container->findDefinition( 'ezpublish_legacy.session_storage_proxy' );
$sessionStorageProxyDef->replaceArgument( 1, new Reference( (string)$sessionStorageAlias ) );
$container->setAlias( 'session.storage', 'ezpublish_legacy.session_storage_proxy' );
if ( $container->hasAlias( 'session.handler' ) )
{
$sessionHandlerAlias = $container->getAlias( 'session.handler' );
$interfaces = class_implements( $container->findDefinition( (string)$sessionHandlerAlias ) );
// Only swap session handler if it implements appropriate interface.
if ( isset( $interfaces['SessionHandlerInterface'] ) )
{
$sessionHandlerProxyDef = $container->findDefinition( 'ezpublish_legacy.session_handler_proxy' );
$sessionHandlerProxyDef->replaceArgument( 1, new Reference( (string)$sessionHandlerAlias ) );
$container->setAlias( 'session.handler', 'ezpublish_legacy.session_handler_proxy' );
}
}
}
示例15: buildServiceProxyFactoryDefinition
private function buildServiceProxyFactoryDefinition($taggedServiceName, $tagParameters)
{
$definition = $this->container->findDefinition($taggedServiceName);
$factoryDefinition = new Definition();
$factoryDefinition->setFactory([new Reference('openclassrooms.service_proxy.service_proxy_factory'), 'create']);
$factoryDefinition->setArguments([$definition, $tagParameters[0]]);
$this->container->setDefinition($taggedServiceName, $factoryDefinition);
}