getStaticPrefix() public static méthode

The "static prefix" is the part of the glob up to the first wildcard "*". If the glob does not contain wildcards, the full glob is returned.
public static getStaticPrefix ( string $glob, integer $flags ) : string
$glob string The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method.
$flags integer A bitwise combination of the flag constants in this class.
Résultat string The static prefix of the glob.
 private function generateUrlForBinding(ResourceBinding $binding, $repositoryPath)
 {
     $bindingPath = Glob::getStaticPrefix($binding->getQuery());
     $webBasePath = trim($binding->getParameterValue(AssetPlugin::PATH_PARAMETER), '/');
     $webPath = substr_replace($repositoryPath, $webBasePath, 0, strlen($bindingPath));
     $targetName = $binding->getParameterValue(AssetPlugin::TARGET_PARAMETER);
     if (!$this->targets->contains($targetName)) {
         throw new CannotGenerateUrlException(sprintf('The target "%s" mapped for path "%s" does not exist.', $targetName, $repositoryPath));
     }
     $target = $this->targets->get($targetName);
     return sprintf($target->getUrlFormat(), ltrim($webPath, '/'));
 }
 /**
  * Creates a new iterator.
  *
  * @param string   $glob          The canonical glob.
  * @param Iterator $innerIterator The filtered iterator.
  * @param int      $mode          A bitwise combination of the mode constants.
  * @param int      $flags         A bitwise combination of the flag constants
  *                                in {@link Glob}.
  */
 public function __construct($glob, Iterator $innerIterator, $mode = self::FILTER_VALUE, $flags = 0)
 {
     parent::__construct(Glob::toRegEx($glob, $flags), Glob::getStaticPrefix($glob, $flags), $innerIterator, $mode);
 }
Exemple #3
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage *.css
  */
 public function testGetStaticPrefixFailsIfNotAbsolute()
 {
     Glob::getStaticPrefix('*.css');
 }
 /**
  * {@inheritdoc}
  */
 protected function getReferencesForGlob($glob, $flags = 0)
 {
     if (!Glob::isDynamic($glob)) {
         return $this->getReferencesForPath($glob);
     }
     return $this->getReferencesForRegex(Glob::getStaticPrefix($glob), Glob::toRegEx($glob), $flags);
 }
 private function generateUrlForBinding(ResourceBinding $binding, $repositoryPath)
 {
     $serverName = $binding->getParameterValue(self::SERVER_PARAMETER);
     if (!isset($this->urlFormats[$serverName])) {
         throw new CannotGenerateUrlException(sprintf('The server "%s" mapped for path "%s" does not exist.', $serverName, $repositoryPath));
     }
     $repoBasePath = Glob::getStaticPrefix($binding->getQuery());
     $serverBasePath = trim($binding->getParameterValue(self::PATH_PARAMETER), '/');
     // The server path is generated by replacing the base repository path
     // (= the path of the binding) by the stored server base path in the
     // repository path of the resource.
     //
     // Example:
     //
     // resource path: /acme/blog/public/css/style.css
     // binding path: /acme/blog/public{,/**/*}
     // repo base path: /acme/blog/public
     // server base path: /blog
     //
     // final server path: /blog/css/style.css
     $serverPath = substr_replace($repositoryPath, $serverBasePath, 0, strlen($repoBasePath));
     // The server path is inserted into the "%s" parameter of the URL format
     return sprintf($this->urlFormats[$serverName], ltrim($serverPath, '/'));
 }