UrlGenerator.php 1.06 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
Crell's avatar
Crell committed
5
 * Contains Drupal\Core\Routing\UrlGenerator.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
 */

namespace Drupal\Core\Routing;

use Symfony\Cmf\Component\Routing\ProviderBasedGenerator;
use Symfony\Cmf\Component\Routing\RouteProviderInterface;

use Drupal\Core\Path\AliasManagerInterface;

/**
 * Description of UrlGenerator
 */
class UrlGenerator extends ProviderBasedGenerator {

  /**
   * The alias manager that will be used to alias generated URLs.
   *
   * @var AliasManagerInterface
   */
  protected $aliasManager;

  public function __construct(RouteProviderInterface $provider, AliasManagerInterface $alias_manager, LoggerInterface $logger = NULL) {
    parent::__construct($provider, $logger);

    $this->aliasManager = $alias_manager;
  }

  public function generate($name, $parameters = array(), $absolute = FALSE) {
    $path = parent::generate($name, $parameters, $absolute);

    // This method is expected to return a path with a leading /, whereas
    // the alias manager has no leading /.
    $path = '/' . $this->aliasManager->getPathAlias(trim($path, '/'));

    return $path;
  }

}