You are here

class RouteContentEnhancer in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony-cmf/routing/Enhancer/RouteContentEnhancer.php \Symfony\Cmf\Component\Routing\Enhancer\RouteContentEnhancer

This enhancer sets the content to target field if the route provides content.

Only works with RouteObjectInterface routes that can return a referenced content.

@author David Buchmann

Hierarchy

Expanded class hierarchy of RouteContentEnhancer

1 file declares its use of RouteContentEnhancer
RouteContentEnhancerTest.php in vendor/symfony-cmf/routing/Tests/Enhancer/RouteContentEnhancerTest.php

File

vendor/symfony-cmf/routing/Enhancer/RouteContentEnhancer.php, line 26

Namespace

Symfony\Cmf\Component\Routing\Enhancer
View source
class RouteContentEnhancer implements RouteEnhancerInterface {

  /**
   * @var string field for the route class
   */
  protected $routefield;

  /**
   * @var string field to write hashmap lookup result into
   */
  protected $target;

  /**
   * @param string $routefield the field name of the route class
   * @param string $target     the field name to set from the map
   * @param array  $hashmap    the map of class names to field values
   */
  public function __construct($routefield, $target) {
    $this->routefield = $routefield;
    $this->target = $target;
  }

  /**
   * If the route has a non-null content and if that content class is in the
   * injected map, returns that controller.
   *
   * {@inheritDoc}
   */
  public function enhance(array $defaults, Request $request) {
    if (isset($defaults[$this->target])) {

      // no need to do anything
      return $defaults;
    }
    if (!isset($defaults[$this->routefield]) || !$defaults[$this->routefield] instanceof RouteObjectInterface) {

      // we can't determine the content
      return $defaults;
    }

    /** @var $route RouteObjectInterface */
    $route = $defaults[$this->routefield];
    $content = $route
      ->getContent();
    if (!$content) {

      // we have no content
      return $defaults;
    }
    $defaults[$this->target] = $content;
    return $defaults;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteContentEnhancer::$routefield protected property
RouteContentEnhancer::$target protected property
RouteContentEnhancer::enhance public function If the route has a non-null content and if that content class is in the injected map, returns that controller. Overrides RouteEnhancerInterface::enhance
RouteContentEnhancer::__construct public function