Author: Johannes M. Schmitt (schmittjoh@gmail.com)
示例#1
0
 /**
  * Adds a scope to the container.
  *
  * @param ScopeInterface $scope
  *
  * @throws InvalidArgumentException
  *
  * @deprecated since version 2.8, to be removed in 3.0.
  */
 public function addScope(ScopeInterface $scope)
 {
     $name = $scope->getName();
     $parentScope = $scope->getParentName();
     if ('request' !== $name) {
         @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
     }
     if (self::SCOPE_CONTAINER === $name || self::SCOPE_PROTOTYPE === $name) {
         throw new InvalidArgumentException(sprintf('The scope "%s" is reserved.', $name));
     }
     if (isset($this->scopes[$name])) {
         throw new InvalidArgumentException(sprintf('A scope with name "%s" already exists.', $name));
     }
     if (self::SCOPE_CONTAINER !== $parentScope && !isset($this->scopes[$parentScope])) {
         throw new InvalidArgumentException(sprintf('The parent scope "%s" does not exist, or is invalid.', $parentScope));
     }
     $this->scopes[$name] = $parentScope;
     $this->scopeChildren[$name] = array();
     // normalize the child relations
     while ($parentScope !== self::SCOPE_CONTAINER) {
         $this->scopeChildren[$parentScope][] = $name;
         $parentScope = $this->scopes[$parentScope];
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function addScope(ScopeInterface $scope)
 {
     $name = $scope->getName();
     if ('request' !== $name) {
         @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
     }
     throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__));
 }
示例#3
0
 /**
  * Adds a scope to the container.
  *
  * @param ScopeInterface $scope
  *
  * @throws InvalidArgumentException
  *
  * @api
  */
 public function addScope(ScopeInterface $scope)
 {
     $name = $scope->getName();
     $parentScope = $scope->getParentName();
     if (self::SCOPE_CONTAINER === $name || self::SCOPE_PROTOTYPE === $name) {
         throw new InvalidArgumentException(sprintf('The scope "%s" is reserved.', $name));
     }
     if (isset($this->scopes[$name])) {
         throw new InvalidArgumentException(sprintf('A scope with name "%s" already exists.', $name));
     }
     if (self::SCOPE_CONTAINER !== $parentScope && !isset($this->scopes[$parentScope])) {
         throw new InvalidArgumentException(sprintf('The parent scope "%s" does not exist, or is invalid.', $parentScope));
     }
     $this->scopes[$name] = $parentScope;
     $this->scopeChildren[$name] = array();
     // normalize the child relations
     while ($parentScope !== self::SCOPE_CONTAINER) {
         $this->scopeChildren[$parentScope][] = $name;
         $parentScope = $this->scopes[$parentScope];
     }
 }
示例#4
0
文件: Container.php 项目: seytar/psx
 public function addScope(ScopeInterface $scope)
 {
     $this->scopes[] = $scope->getName();
     $this->services[$scope->getName()] = array();
     $this->parameters[$scope->getName()] = array();
 }