Generator/Collection/ComponentCollection.php
public function addComponent($local_name, BaseGenerator $component, $requesting_component) {
    // Components may not be added once the collection is locked.
    if ($this->locked) {
      throw new \LogicException("Attempt to add component to locked collection.");
    }

    $key = $this->getComponentKey($component);

    if (isset($this->components[$key])) {
      throw new \Exception("Unique ID $key already in use, by component with request path {$this->requestPaths[$key]}.");
    }

    // If this is the first component, it's the root.
    if (!isset($this->rootGeneratorId)) {
      $this->rootGeneratorId = $key;

      $request_path = 'root';

      // Create the first item in the request paths array.
      $this->requestPaths[$key] = $request_path;
    }

    // If this is *a* root, keep track of it.
    if ($component instanceof \DrupalCodeBuilder\Generator\RootComponent) {
      $this->roots[$key] = TRUE;
    }

    if ($requesting_component) {
      $request_path = $this->requestPaths[$this->getComponentKey($requesting_component)] . '/' . $local_name;

      // Add to the array of request paths.
      $this->requestPaths[$key] = $request_path;

      // Add to the array of requesters.
      if (!isset($this->requesters[$key])) {
        // TODO: store multiple requesters?
        $this->requesters[$key] = $this->getComponentKey($requesting_component);
      }

      // Keep track of the nearest requesting root component.
      $closest_requesting_root = $this->determineNearestRequestingRoot($key);
      $this->requestRoots[$key] = $closest_requesting_root;

      // Add to the array of local names.
      $this->localNames[$this->getComponentKey($requesting_component)][$local_name] = $key;
    }

    // Add to the merge tags list.
    if ($merge_tag = $component->getMergeTag()) {
      // $closest_requesting_root will be set because the root component has
      // no merge tag.
      $this->mergeTags[$closest_requesting_root][$component->getType()][$component->getMergeTag()] = $key;
    }

    $this->components[$key] = $component;
  }
public function addComponent($local_name, BaseGenerator $component, $requesting_component) {
    // Components may not be added once the collection is locked.
    if ($this->locked) {
      throw new \LogicException("Attempt to add component to locked collection.");
    }

    $key = $this->getComponentKey($component);

    if (isset($this->components[$key])) {
      throw new \Exception("Unique ID $key already in use, by component with request path {$this->requestPaths[$key]}.");
    }

    // If this is the first component, it's the root.
    if (!isset($this->rootGeneratorId)) {
      $this->rootGeneratorId = $key;

      $request_path = 'root';

      // Create the first item in the request paths array.
      $this->requestPaths[$key] = $request_path;
    }

    // If this is *a* root, keep track of it.
    if ($component instanceof \DrupalCodeBuilder\Generator\RootComponent) {
      $this->roots[$key] = TRUE;
    }

    if ($requesting_component) {
      $request_path = $this->requestPaths[$this->getComponentKey($requesting_component)] . '/' . $local_name;

      // Add to the array of request paths.
      $this->requestPaths[$key] = $request_path;

      // Add to the array of requesters.
      if (!isset($this->requesters[$key])) {
        // TODO: store multiple requesters?
        $this->requesters[$key] = $this->getComponentKey($requesting_component);
      }

      // Keep track of the nearest requesting root component.
      $closest_requesting_root = $this->determineNearestRequestingRoot($key);
      $this->requestRoots[$key] = $closest_requesting_root;

      // Add to the array of local names.
      $this->localNames[$this->getComponentKey($requesting_component)][$local_name] = $key;
    }

    // Add to the merge tags list.
    if ($merge_tag = $component->getMergeTag()) {
      // $closest_requesting_root will be set because the root component has
      // no merge tag.
      $this->mergeTags[$closest_requesting_root][$component->getType()][$component->getMergeTag()] = $key;
    }

    $this->components[$key] = $component;
  }
public function addComponent ( $ local_name , BaseGenerator $ component , $ requesting_component ) { // Components may not be added once the collection is locked. if ( $ this -> locked ) { throw new \ LogicException ( "Attempt to add component to locked collection." ) ; } $ key = $ this -> getComponentKey ( $ component ) ; if ( isset ( $ this -> components [ $ key ] ) ) { throw new \ Exception ( "Unique ID $key already in use, by component with request path {$this->requestPaths[$key]}." ) ; } // If this is the first component, it's the root. if ( ! isset ( $ this -> rootGeneratorId ) ) { $ this -> rootGeneratorId = $ key ; $ request_path = 'root' ; // Create the first item in the request paths array. $ this -> requestPaths [ $ key ] = $ request_path ; } // If this is *a* root, keep track of it. if ( $ component instanceof \ DrupalCodeBuilder \ Generator \ RootComponent ) { $ this -> roots [ $ key ] = TRUE ; } if ( $ requesting_component ) { $ request_path = $ this -> requestPaths [ $ this -> getComponentKey ( $ requesting_component ) ] . '/' . $ local_name ; // Add to the array of request paths. $ this -> requestPaths [ $ key ] = $ request_path ; // Add to the array of requesters. if ( ! isset ( $ this -> requesters [ $ key ] ) ) { // TODO: store multiple requesters? $ this -> requesters [ $ key ] = $ this -> getComponentKey ( $ requesting_component ) ; } // Keep track of the nearest requesting root component. $ closest_requesting_root = $ this -> determineNearestRequestingRoot ( $ key ) ; $ this -> requestRoots [ $ key ] = $ closest_requesting_root ; // Add to the array of local names. $ this -> localNames [ $ this -> getComponentKey ( $ requesting_component ) ] [ $ local_name ] = $ key ; } // Add to the merge tags list. if ( $ merge_tag = $ component -> getMergeTag ( ) ) { // $closest_requesting_root will be set because the root component has // no merge tag. $ this -> mergeTags [ $ closest_requesting_root ] [ $ component -> getType ( ) ] [ $ component -> getMergeTag ( ) ] = $ key ; } $ this -> components [ $ key ] = $ component ; }
Adds a component to the collection.

@param $local_name
The local name for the component, that is, the name used within the
requesting components list of components to spawn, whether from
properties or from requests.
@param $component
The component to add.
@param $requesting_component
The component that requested the component being added. May be NULL if
the component being added is the root component.
Adds a component to the collection .