Parcourir la source

[DependencyInjection] added some missing accessors

Fabien Potencier il y a 15 ans
Parent
commit
7e2d6c0043

+ 31 - 0
src/Symfony/Components/DependencyInjection/BuilderConfiguration.php

@@ -157,6 +157,37 @@ class BuilderConfiguration
     return $this->aliases;
   }
 
+  /**
+   * Returns true if a service alias exists.
+   *
+   * @param  string  $alias The alias
+   *
+   * @return Boolean true if the alias exists, false otherwise
+   */
+  public function hasAlias($alias)
+  {
+    return array_key_exists($alias, $this->aliases);
+  }
+
+  /**
+   * Gets the service id for a given alias.
+   *
+   * @param  string $alias The alias
+   *
+   * @return string The aliased id
+   *
+   * @throws \InvalidArgumentException if the service alias does not exist
+   */
+  public function getAlias($alias)
+  {
+    if (!$this->hasAlias($alias))
+    {
+      throw new \InvalidArgumentException(sprintf('The service alias "%s" does not exist.', $alias));
+    }
+
+    return $this->aliases[$alias];
+  }
+
   /**
    * Sets a definition.
    *