You are here

class Builder in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/stack/builder/src/Stack/Builder.php \Stack\Builder

Hierarchy

Expanded class hierarchy of Builder

1 file declares its use of Builder
SilexApplicationTest.php in vendor/stack/builder/tests/functional/SilexApplicationTest.php

File

vendor/stack/builder/src/Stack/Builder.php, line 7

Namespace

Stack
View source
class Builder {
  private $specs;
  public function __construct() {
    $this->specs = new \SplStack();
  }
  public function unshift() {
    if (func_num_args() === 0) {
      throw new \InvalidArgumentException("Missing argument(s) when calling unshift");
    }
    $spec = func_get_args();
    $this->specs
      ->unshift($spec);
    return $this;
  }
  public function push() {
    if (func_num_args() === 0) {
      throw new \InvalidArgumentException("Missing argument(s) when calling push");
    }
    $spec = func_get_args();
    $this->specs
      ->push($spec);
    return $this;
  }
  public function resolve(HttpKernelInterface $app) {
    $middlewares = array(
      $app,
    );
    foreach ($this->specs as $spec) {
      $args = $spec;
      $firstArg = array_shift($args);
      if (is_callable($firstArg)) {
        $app = $firstArg($app);
      }
      else {
        $kernelClass = $firstArg;
        array_unshift($args, $app);
        $reflection = new \ReflectionClass($kernelClass);
        $app = $reflection
          ->newInstanceArgs($args);
      }
      array_unshift($middlewares, $app);
    }
    return new StackedHttpKernel($app, $middlewares);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Builder::$specs private property
Builder::push public function
Builder::resolve public function
Builder::unshift public function
Builder::__construct public function