public function testCreateWithQuery()
 {
     $binding = new ResourceBinding('/path/*', Foo::clazz, array(), 'glob');
     $this->assertSame('/path/*', $binding->getQuery());
     $this->assertSame('glob', $binding->getLanguage());
     $this->assertSame(Foo::clazz, $binding->getTypeName());
 }
Ejemplo n.º 2
0
 /**
  * @param Args            $args
  * @param ResourceBinding $bindingToUpdate
  *
  * @return ResourceBinding
  */
 private function getUpdatedResourceBinding(Args $args, ResourceBinding $bindingToUpdate)
 {
     $query = $bindingToUpdate->getQuery();
     $typeName = $bindingToUpdate->getTypeName();
     $language = $bindingToUpdate->getLanguage();
     $bindingParams = $bindingToUpdate->getParameterValues();
     if ($args->isOptionSet('query')) {
         $query = $args->getOption('query');
     }
     if ($args->isOptionSet('type')) {
         $typeName = $args->getOption('type');
     }
     if ($args->isOptionSet('language')) {
         $language = $args->getOption('language');
     }
     $this->parseParams($args, $bindingParams);
     $this->unsetParams($args, $bindingParams);
     return new ResourceBinding(Path::makeAbsolute($query, $this->currentPath), $typeName, $bindingParams, $language, $bindingToUpdate->getUuid());
 }
 private function bindingToMapping(ResourceBinding $binding)
 {
     return new AssetMapping(substr($binding->getQuery(), 0, -8), $binding->getParameterValue(DiscoveryUrlGenerator::SERVER_PARAMETER), $binding->getParameterValue(DiscoveryUrlGenerator::PATH_PARAMETER), $binding->getUuid());
 }
 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, '/'));
 }