Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / symfony / dependency-injection / Compiler / CheckDefinitionValidityPass.php
index e54ee60abbcaf1c2e3eb6f0d9c1541fb27d31cc3..a1967802f6a30d37a8eebd2d935f8b0704822331 100644 (file)
@@ -11,8 +11,8 @@
 
 namespace Symfony\Component\DependencyInjection\Compiler;
 
-use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Exception\EnvParameterException;
 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
 
 /**
@@ -24,8 +24,6 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
  *
  * - non synthetic, non abstract services always have a class set
  * - synthetic services are always public
- * - synthetic services are always of non-prototype scope
- * - shared services are always of non-prototype scope
  *
  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  */
@@ -34,45 +32,41 @@ class CheckDefinitionValidityPass implements CompilerPassInterface
     /**
      * Processes the ContainerBuilder to validate the Definition.
      *
-     * @param ContainerBuilder $container
-     *
      * @throws RuntimeException When the Definition is invalid
      */
     public function process(ContainerBuilder $container)
     {
         foreach ($container->getDefinitions() as $id => $definition) {
             // synthetic service is public
-            if ($definition->isSynthetic() && !$definition->isPublic()) {
+            if ($definition->isSynthetic() && !($definition->isPublic() || $definition->isPrivate())) {
                 throw new RuntimeException(sprintf('A synthetic service ("%s") must be public.', $id));
             }
 
-            // synthetic service has non-prototype scope
-            if ($definition->isSynthetic() && ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) {
-                throw new RuntimeException(sprintf('A synthetic service ("%s") cannot be of scope "prototype".', $id));
-            }
-
-            // shared service has non-prototype scope
-            if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) {
-                throw new RuntimeException(sprintf('A shared service ("%s") cannot be of scope "prototype".', $id));
-            }
-
-            if ($definition->getFactory() && ($definition->getFactoryClass(false) || $definition->getFactoryService(false) || $definition->getFactoryMethod(false))) {
-                throw new RuntimeException(sprintf('A service ("%s") can use either the old or the new factory syntax, not both.', $id));
-            }
-
             // non-synthetic, non-abstract service has class
             if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) {
-                if ($definition->getFactory() || $definition->getFactoryClass(false) || $definition->getFactoryService(false)) {
+                if ($definition->getFactory()) {
                     throw new RuntimeException(sprintf('Please add the class to service "%s" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.', $id));
                 }
+                if (class_exists($id) || interface_exists($id, false)) {
+                    if (0 === strpos($id, '\\') && 1 < substr_count($id, '\\')) {
+                        throw new RuntimeException(sprintf(
+                            'The definition for "%s" has no class attribute, and appears to reference a class or interface. '
+                            .'Please specify the class attribute explicitly or remove the leading backslash by renaming '
+                            .'the service to "%s" to get rid of this error.',
+                            $id, substr($id, 1)
+                        ));
+                    }
 
-                throw new RuntimeException(sprintf(
-                    'The definition for "%s" has no class. If you intend to inject '
-                   .'this service dynamically at runtime, please mark it as synthetic=true. '
-                   .'If this is an abstract definition solely used by child definitions, '
-                   .'please add abstract=true, otherwise specify a class to get rid of this error.',
-                   $id
-                ));
+                    throw new RuntimeException(sprintf(
+                         'The definition for "%s" has no class attribute, and appears to reference a '
+                        .'class or interface in the global namespace. Leaving out the "class" attribute '
+                        .'is only allowed for namespaced classes. Please specify the class attribute '
+                        .'explicitly to get rid of this error.',
+                        $id
+                    ));
+                }
+
+                throw new RuntimeException(sprintf('The definition for "%s" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an abstract definition solely used by child definitions, please add abstract=true, otherwise specify a class to get rid of this error.', $id));
             }
 
             // tag attribute values must be scalars
@@ -85,6 +79,22 @@ class CheckDefinitionValidityPass implements CompilerPassInterface
                     }
                 }
             }
+
+            if ($definition->isPublic() && !$definition->isPrivate()) {
+                $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
+                if (null !== $usedEnvs) {
+                    throw new EnvParameterException(array($resolvedId), null, 'A service name ("%s") cannot contain dynamic values.');
+                }
+            }
+        }
+
+        foreach ($container->getAliases() as $id => $alias) {
+            if ($alias->isPublic() && !$alias->isPrivate()) {
+                $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
+                if (null !== $usedEnvs) {
+                    throw new EnvParameterException(array($resolvedId), null, 'An alias name ("%s") cannot contain dynamic values.');
+                }
+            }
         }
     }
 }