Symfony\Component\DependencyInjection\ContainerBuilder::hasDefinition PHP Method

hasDefinition() public method

Returns true if a service definition exists under the given identifier.
public hasDefinition ( string $id ) : boolean
$id string The service identifier
return boolean true if the service definition exists, false otherwise
    public function hasDefinition($id)
    {
        return isset($this->definitions[strtolower($id)]);
    }

Usage Example

Esempio n. 1
0
 /**
  * @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)]);
 }
All Usage Examples Of Symfony\Component\DependencyInjection\ContainerBuilder::hasDefinition