protected function getUri(ResourceDOInterface $resourceDO)
 {
     $uri = $resourceDO->getName() . '.' . $resourceDO->getType();
     $query = [];
     if (ResourceDOInterface::DEFAULT_VARIANT !== $resourceDO->getVariant()) {
         $query['var'] = $resourceDO->getVariant();
     }
     if (ResourceDOInterface::DEFAULT_NAME_ALTERNATIVE !== $resourceDO->getNameAlternative()) {
         $query['alt'] = $resourceDO->getNameAlternative();
     }
     if (ResourceDOInterface::DEFAULT_VERSION !== $resourceDO->getVersion()) {
         $query['v'] = $resourceDO->getVersion();
     }
     $query = http_build_query($query, null, '&', PHP_QUERY_RFC3986);
     // RFC for correct spaces
     if ($query) {
         $uri .= '?' . $query;
     }
     return $uri;
 }
Пример #2
0
 /**
  * @param ResourceDOInterface|ResourceImageDOInterface $resourceDO
  * @return mixed
  */
 protected function generate(ResourceDOInterface $resourceDO)
 {
     // Do not generate image when resizing or cropping is requested
     if ($this->resourceDO->getDimension()) {
         // If recreation for current size is asked, just remove previous file
         // Without this next middlewares will try to resize exist file
         if ($this->resourceDO->isRecreate()) {
             $this->filesystem->delete($this->resourceDO->getFilePath());
         }
         return null;
     }
     $query = $resourceDO->getName() . ' ' . $resourceDO->getNameAlternative();
     $content = $this->generator->generate($query);
     return $content;
 }
Пример #3
0
 /**
  * @param ResourceDOInterface $resourceDO
  * @return mixed
  * @throws ErrorException
  */
 protected function generate(ResourceDOInterface $resourceDO)
 {
     /** @var Manager $generator */
     $generator = $this->generator;
     // If a body is exist, it will be used as the text for voicing
     $body = $resourceDO->getBody();
     // If an alternative name is exist, it will be used when body is empty
     $alternative = $resourceDO->getNameAlternative();
     // The main resource name will be used, if no body and no alt exist
     $voiceText = $body ?: ($alternative ?: $resourceDO->getName());
     $this->selectLanguage($voiceText);
     $content = $generator->read($voiceText);
     $headers = $generator->getHeaders();
     if (!array_key_exists('http_code', (array) $headers) || $headers['http_code'] != 200) {
         throw new ErrorException('Wrong http response code from voice provider ' . get_class($this->generator->getAdapter()) . ': ' . $headers['http_code'] . '; Requested text: ' . $resourceDO->getName());
     }
     return $content;
 }