本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::hasDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::hasDefinition方法的具体用法?PHP ContainerBuilder::hasDefinition怎么用?PHP ContainerBuilder::hasDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::hasDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processDefinition
/**
* @param Definition $definition
*/
protected function processDefinition(Definition $definition)
{
if ($definition->isSynthetic()) {
return;
}
if ($definition->getFactoryService() || $definition->getFactoryClass()) {
return;
}
if ($file = $definition->getFile()) {
require_once $file;
}
if (!class_exists($definition->getClass())) {
return;
}
$class = new \ReflectionClass($definition->getClass());
if (!$class->implementsInterface(static::INTERFACE_CLASS)) {
return;
}
$metadata = $this->getMetadataFactory()->getMetadataForClass($definition->getClass());
if (!$metadata instanceof ClassMetadata) {
return;
}
$namespace = $metadata->getNamespace() ?: static::ROOT_NAMESPACE;
$serviceName = static::PROVIDER_PREFIX . substr(sha1($namespace), 0, 10);
if (!$this->container->hasDefinition($serviceName)) {
$cacher = new Definition('Werkint\\Bundle\\CacheBundle\\Service\\CacheProvider', [$this->container->getParameter('kernel.cache_dir') . '/werkint_cache']);
$cacher->setPublic(true);
$cacher->addMethodCall('setNamespace', [$namespace]);
$this->container->setDefinition($serviceName, $cacher);
}
$definition->addMethodCall('setCacheProvider', [new Reference($serviceName)]);
}
示例2: 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));
}
示例3: 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)));
}
}
示例4: process
/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('ezpublish.chain_router')) {
return;
}
$chainRouter = $container->getDefinition('ezpublish.chain_router');
// Enforce default router to be part of the routing chain
// The default router will be given the highest priority so that it will be used by default
if ($container->hasDefinition('router.default')) {
$defaultRouter = $container->getDefinition('router.default');
$defaultRouter->addMethodCall('setSiteAccess', array(new Reference('ezpublish.siteaccess')));
$defaultRouter->addMethodCall('setConfigResolver', array(new Reference('ezpublish.config.resolver')));
$defaultRouter->addMethodCall('setNonSiteAccessAwareRoutes', array('%ezpublish.default_router.non_siteaccess_aware_routes%'));
$defaultRouter->addMethodCall('setLegacyAwareRoutes', array('%ezpublish.default_router.legacy_aware_routes%'));
$defaultRouter->addMethodCall('setSiteAccessRouter', array(new Reference('ezpublish.siteaccess_router')));
if (!$defaultRouter->hasTag('router')) {
$defaultRouter->addTag('router', array('priority' => 255));
}
}
foreach ($container->findTaggedServiceIds('router') as $id => $attributes) {
$priority = isset($attributes[0]['priority']) ? (int) $attributes[0]['priority'] : 0;
// Priority range is between -255 (the lowest) and 255 (the highest)
if ($priority > 255) {
$priority = 255;
}
if ($priority < -255) {
$priority = -255;
}
$chainRouter->addMethodCall('add', array(new Reference($id), $priority));
}
}
示例5: testLoad
public function testLoad()
{
$config = [['toggles' => ['generic' => ['type' => 'service', 'service' => 'hotflo_feature_toggle.generic_feature_toggle']], 'features' => ['my_feature' => ['toggle' => 'generic', 'options' => ['key' => 'value']], 'my_second_feature' => ['toggle' => 'generic']]]];
$this->extension->load($config, $this->container);
$this->assertTrue($this->container->hasDefinition('hotflo_feature_toggle.feature.my_feature'));
$this->assertTrue($this->container->hasDefinition('hotflo_feature_toggle.feature.my_second_feature'));
}
示例6: 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);
}
示例7: process
/**
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition(self::CONTENT_PROVIDER_MANAGER_SERVICE)) {
return;
}
$contentProviderManagerDefinition = $container->getDefinition(self::CONTENT_PROVIDER_MANAGER_SERVICE);
$taggedServices = $container->findTaggedServiceIds(self::CONTENT_PROVIDER_TAG);
foreach ($taggedServices as $id => $attributes) {
if ($container->hasDefinition($id)) {
$container->getDefinition($id)->setPublic(false);
}
$isEnabled = true;
foreach ($attributes as $attribute) {
if (array_key_exists('enabled', $attribute)) {
$isEnabled = !empty($attribute['enabled']);
break;
}
}
$contentProviderManagerDefinition->addMethodCall('addContentProvider', array(new Reference($id), $isEnabled));
}
if ($container->hasDefinition(self::TWIG_SERVICE_KEY)) {
$twig = $container->getDefinition(self::TWIG_SERVICE_KEY);
$twig->addMethodCall('addGlobal', ['oro_ui_content_provider_manager', new Reference(self::CONTENT_PROVIDER_MANAGER_SERVICE)]);
}
}
示例8: process
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('teckhouse_analytics.menu_builder.default')) {
return;
}
if (!$container->hasDefinition('teckhouse_analytics.widget_manager.default')) {
return;
}
$menuDefinition = $container->getDefinition('teckhouse_analytics.menu_builder');
$wdigetManagerDefinition = $container->getDefinition('teckhouse_analytics.widget_manager');
$taggedServices = $container->findTaggedServiceIds('teckhouse_analytics.widget');
// $config = $container->getParameter('teckhouse_analytics');
//
// foreach ($taggedServices as $id => $tagAttributes) {
// foreach ($tagAttributes as $attributes) {
//
// $widget = new Reference($id);
//
// $menuDefinition->addMethodCall(
// 'addMenuWidgetItem', array($widget, $attributes["group"], $attributes["label"])
// );
//
// $wdigetManagerDefinition->addMethodCall(
// 'setWidget', array($widget, $id)
// );
// }
// }
}
示例9: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('profiler')) {
// the Symfony Profiler is disabled
return;
}
$datagridEvents = [DatagridEvent\PreBuild::NAME, DatagridEvent\BuildAfter::NAME, DatagridEvent\BuildBefore::NAME, DatagridEvent\OrmResultBefore::NAME, DatagridEvent\OrmResultAfter::NAME, DatagridEvent\GridViewsLoadEvent::EVENT_NAME];
$datagridEventListeners = [];
$eventListeners = $container->findTaggedServiceIds('kernel.event_listener');
foreach ($eventListeners as $serviceId => $tags) {
foreach ($tags as $tag) {
if (isset($tag['event']) && 0 === strpos($tag['event'], 'oro_datagrid') && !in_array($tag['event'], $datagridEvents, true)) {
$datagridEventListeners[] = $serviceId;
}
}
}
$datagridEventListeners = array_unique($datagridEventListeners);
foreach ($datagridEventListeners as $serviceId) {
if ($container->hasDefinition($serviceId)) {
$serviceDef = $container->getDefinition($serviceId);
if (!$serviceDef->isLazy()) {
$serviceDef->setLazy(true);
}
}
}
}
示例10: process
public function process(ContainerBuilder $container)
{
$loaderRefs = array();
$loaderAliases = array();
$exporterRefs = array();
// look for all tagged translation file loaders, inject them into the importer
foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
$loaderAliases[$id][] = $attributes[0]['alias'];
$loaderRefs[$attributes[0]['alias']] = new Reference($id);
if (isset($attributes[0]['legacy-alias'])) {
$loaderAliases[$id][] = $attributes[0]['legacy-alias'];
$loaderRefs[$attributes[0]['legacy-alias']] = new Reference($id);
}
}
if ($container->hasDefinition('kunstmaan_translator.service.importer.importer')) {
$container->getDefinition('kunstmaan_translator.service.importer.importer')->addMethodCall('setLoaders', array($loaderRefs));
}
if ($container->hasDefinition('kunstmaan_translator.service.translator.translator')) {
$container->getDefinition('kunstmaan_translator.service.translator.translator')->replaceArgument(2, $loaderAliases);
}
// add all exporter into the translation exporter
foreach ($container->findTaggedServiceIds('translation.exporter') as $id => $attributes) {
$exporterRefs[$attributes[0]['alias']] = new Reference($id);
}
if ($container->hasDefinition('kunstmaan_translator.service.exporter.exporter')) {
$container->getDefinition('kunstmaan_translator.service.exporter.exporter')->addMethodCall('setExporters', array($exporterRefs));
}
}
示例11: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$chainProviderServiceId = $this->getChainProviderServiceId();
if (!$container->hasDefinition($chainProviderServiceId)) {
return;
}
// find providers
$providers = [];
$taggedServices = $container->findTaggedServiceIds($this->getProviderTagName());
foreach ($taggedServices as $id => $attributes) {
if ($container->hasDefinition($id)) {
$container->getDefinition($id)->setPublic(false);
}
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
$providers[$priority][] = new Reference($id);
}
if (empty($providers)) {
return;
}
// sort by priority and flatten
ksort($providers);
$providers = call_user_func_array('array_merge', $providers);
// register
$serviceDef = $container->getDefinition($chainProviderServiceId);
foreach ($providers as $provider) {
$serviceDef->addMethodCall('addProvider', [$provider]);
}
}
示例12: process
/**
* Configure core with all admin services
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('sfs.admin.routing_loader') || !$container->hasDefinition('sfs.admin.menu_builder')) {
return;
}
$core = $container->getDefinition('sfs.admin.core');
$menuBuilder = $container->getDefinition('sfs.admin.menu_builder');
/**
* Handles the admin Resources, connected to an entity
*/
$taggedServices = $container->findTaggedServiceIds('sfs_admin.resource');
foreach ($taggedServices as $id => $tagAttributes) {
// id is the current admin's service name with the tag 'sfs_admin.resource' and being looped
foreach ($tagAttributes as $attributes) {
$container->getDefinition($id)->addMethodCall('setContainer', array(new Reference('service_container')));
$container->getDefinition($id)->addMethodCall('setFilterForm');
$core->addMethodCall('addAdmin', array($id, $attributes));
$menuBuilder->addMethodCall('addResource', array($attributes));
}
}
/**
*
*/
$taggedServices = $container->findTaggedServiceIds('sfs_admin.menu.topbar');
foreach ($taggedServices as $id => $tagAttributes) {
$menuBuilder->addMethodCall('addTopbarBlock', array($id));
}
}
示例13: attachProviders
/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function attachProviders(ContainerBuilder $container)
{
#set slugify service
$serviceId = $container->getParameter('bruery.media.slugify_service');
$galleryPool = $container->getDefinition('bruery.media.gallery.pool');
$galleryPool->addMethodCall('setSlugify', array(new Reference($serviceId)));
$galleryHasMediaPool = $container->getDefinition('bruery.media.gallery_has_media.pool');
$galleryHasMediaPool->addMethodCall('setSlugify', array(new Reference($serviceId)));
foreach ($container->findTaggedServiceIds('bruery.media.gallery_provider') as $id => $attributes) {
$galleryPool->addMethodCall('addProvider', array($id, new Reference($id)));
}
foreach ($container->findTaggedServiceIds('bruery.media.gallery_has_media_provider') as $id => $attributes) {
$galleryHasMediaPool->addMethodCall('addProvider', array($id, new Reference($id)));
}
$collections = $container->getParameter('bruery.media.gallery.provider.collections');
foreach ($collections as $name => $settings) {
if ($settings['gallery']['provider']) {
$galleryPool->addMethodCall('addCollection', array($name, $settings['gallery']['provider'], array()));
if ($container->hasDefinition($settings['gallery']['provider'])) {
$provider = $container->getDefinition($settings['gallery']['provider']);
$provider->addMethodCall('setSlugify', array(new Reference($serviceId)));
}
}
if ($settings['gallery_has_media']['provider']) {
$galleryHasMediaPool->addMethodCall('addCollection', array($name, $settings['gallery_has_media']['provider'], $settings['gallery_has_media']['settings']));
if ($container->hasDefinition($settings['gallery_has_media']['provider'])) {
$provider = $container->getDefinition($settings['gallery_has_media']['provider']);
$provider->addMethodCall('setSlugify', array(new Reference($serviceId)));
$provider->addMethodCall('setCategoryManager', array(new Reference('sonata.classification.manager.category')));
}
}
}
}
示例14: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('rollerworks_multi_user.user_discriminator')) {
return;
}
$requestListener = null;
$authenticationListener = null;
if ($container->hasDefinition('rollerworks_multi_user.listener.request')) {
$requestListener = $container->getDefinition('rollerworks_multi_user.listener.request');
}
if ($container->hasDefinition('rollerworks_multi_user.listener.authentication')) {
$authenticationListener = $container->getDefinition('rollerworks_multi_user.listener.authentication');
}
$userDiscriminator = $container->getDefinition('rollerworks_multi_user.user_discriminator');
foreach ($container->findTaggedServiceIds('rollerworks_multi_user.user_system') as $id => $attributes) {
$name = $attributes[0]['alias'];
if (!isset($attributes[0]['request_matcher'])) {
$requestMatcher = $this->createRequestMatcher($container, $container->getParameterBag()->resolveValue($attributes[0]['path']), $container->getParameterBag()->resolveValue($attributes[0]['host']));
} else {
$requestMatcher = new Reference($attributes[0]['request_matcher']);
}
if ($authenticationListener) {
$authenticationListener->addMethodCall('addUser', array($name, $container->getParameterBag()->resolveValue($attributes[0]['class'])));
}
if ($requestListener) {
$requestListener->addMethodCall('addUser', array($name, $requestMatcher));
}
$userDiscriminator->addMethodCall('addUser', array($name, new Reference($id)));
}
}
示例15: loadConfigs
/**
* Process the adaptor config configuration.
*
* @param array $config
* @param ContainerBuilder $container
*/
protected function loadConfigs(array $config, ContainerBuilder $container)
{
foreach ($config['configs'] as $name => $arguments) {
if (!$arguments['enabled']) {
continue;
}
$id = 'integrated_channel.config.memory.' . $name;
if ($container->hasDefinition($id)) {
continue;
}
// first create the options and for that we need a unique service id
do {
$id_options = $id . '.options.' . uniqid();
} while ($container->hasDefinition($id_options));
$definition = new Definition('%integrated_channel.config.options.class%');
$definition->setPublic(false);
$definition->setArguments([$arguments['options']]);
$container->setDefinition($id_options, $definition);
// create the config it self
$definition = new Definition('%integrated_channel.config.class%');
$definition->setArguments([$name, $arguments['adaptor'], new Reference($id_options)]);
if ($arguments['channel']) {
foreach ($arguments['channel'] as $channel) {
$definition->addTag('integrated_channel.config', ['channel' => $channel]);
}
} else {
$definition->addTag('integrated_channel.config');
}
$container->setDefinition($id, $definition);
}
}
开发者ID:integratedfordevelopers,项目名称:integrated-channel-bundle,代码行数:37,代码来源:IntegratedChannelExtension.php