You are here

protected function Candidates::getCandidatesFor in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony-cmf/routing/Candidates/Candidates.php \Symfony\Cmf\Component\Routing\Candidates\Candidates::getCandidatesFor()

Handle a possible format extension and split the $url on "/".

$prefix is prepended to every candidate generated.

Parameters

string $url The URL to split.:

string $prefix A prefix to prepend to every pattern.:

Return value

array Paths that could represent routes that match $url and are child of $prefix.

1 call to Candidates::getCandidatesFor()
Candidates::getCandidates in vendor/symfony-cmf/routing/Candidates/Candidates.php

File

vendor/symfony-cmf/routing/Candidates/Candidates.php, line 129

Class

Candidates
A straightforward strategy that splits the URL on "/".

Namespace

Symfony\Cmf\Component\Routing\Candidates

Code

protected function getCandidatesFor($url, $prefix = '') {
  $candidates = array();
  if ('/' !== $url) {

    // handle format extension, like .html or .json
    if (preg_match('/(.+)\\.[a-z]+$/i', $url, $matches)) {
      $candidates[] = $prefix . $url;
      $url = $matches[1];
    }
    $part = $url;
    $count = 0;
    while (false !== ($pos = strrpos($part, '/'))) {
      if (++$count > $this->limit) {
        return $candidates;
      }
      $candidates[] = $prefix . $part;
      $part = substr($url, 0, $pos);
    }
  }
  $candidates[] = $prefix ?: '/';
  return $candidates;
}