You are here

class SubrequestsTree in Subrequests 3.x

Same name and namespace in other branches
  1. 8.2 src/SubrequestsTree.php \Drupal\subrequests\SubrequestsTree

Value class that holds the execution tree.

Hierarchy

  • class \Drupal\subrequests\SubrequestsTree extends \Drupal\subrequests\ArrayObject

Expanded class hierarchy of SubrequestsTree

6 files declare their use of SubrequestsTree
BlueprintManager.php in src/Blueprint/BlueprintManager.php
BlueprintManagerTest.php in tests/src/Unit/Blueprint/BlueprintManagerTest.php
JsonBlueprintDenormalizer.php in src/Normalizer/JsonBlueprintDenormalizer.php
JsonBlueprintDenormalizerTest.php in tests/src/Unit/Normalizer/JsonBlueprintDenormalizerTest.php
SubrequestsManagerTest.php in tests/src/Unit/SubrequestsManagerTest.php

... See full list

File

src/SubrequestsTree.php, line 10

Namespace

Drupal\subrequests
View source
class SubrequestsTree extends \ArrayObject {

  /**
   * The master request.
   *
   * @var \Symfony\Component\HttpFoundation\Request
   */
  protected $masterRequest;

  /**
   * Adds a sequence of subrequests to the stack.
   *
   * @param \Drupal\subrequests\Subrequest[] $subrequests
   */
  public function stack($subrequests) {

    // Make sure we only push Subrequest objects.
    $this
      ->append(array_filter($subrequests, function ($subrequest) {
      return $subrequest instanceof Subrequest;
    }));
  }

  /**
   * Gets the number of levels in the stack.
   *
   * @return int
   */
  public function getNumLevels() {
    return $this
      ->count();
  }

  /**
   * Gets the lowest level.
   *
   * @return \Drupal\subrequests\Subrequest[]
   *   The subrequests in the level.
   */
  public function getLowestLevel() {
    return $this
      ->offsetGet($this
      ->count() - 1);
  }

  /**
   * Gets the master request.
   *
   * @return \Symfony\Component\HttpFoundation\Request $request
   *   The request.
   */
  public function getMasterRequest() {
    return $this->masterRequest;
  }

  /**
   * Sets the master request.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The request.
   */
  public function setMasterRequest(Request $request) {
    $this->masterRequest = $request;
  }

  /**
   * Gets all the subrequest IDs.
   *
   * @return \Drupal\subrequests\Subrequest[]
   *   All the subrequests in all levels.
   */
  public function allIds() {
    $subrequests = [];
    foreach ($this as $item) {
      $subrequests = array_merge($subrequests, array_values($item));
    }
    $all_request_ids = array_map(function (Subrequest $subrequest) {
      return $subrequest->requestId;
    }, $subrequests);
    array_unshift($all_request_ids, '<ROOT>');
    return array_unique($all_request_ids);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SubrequestsTree::$masterRequest protected property The master request.
SubrequestsTree::allIds public function Gets all the subrequest IDs.
SubrequestsTree::getLowestLevel public function Gets the lowest level.
SubrequestsTree::getMasterRequest public function Gets the master request.
SubrequestsTree::getNumLevels public function Gets the number of levels in the stack.
SubrequestsTree::setMasterRequest public function Sets the master request.
SubrequestsTree::stack public function Adds a sequence of subrequests to the stack.