예제 #1
0
 /**
  * Get URL builder instance.
  *
  * @return \League\Urls\UrlBuilder URL builder instance.
  */
 public function urlBuilder()
 {
     if (!isset($this->_urlBuilder)) {
         $this->_urlBuilder = UrlBuilderFactory::create(Configure::read('Glide.serverConfig.base_url'), Configure::read('Glide.secureUrls') ? Security::salt() : null);
     }
     return $this->_urlBuilder;
 }
 static function startUp(KernelInterface $kernel, ModuleInfo $moduleInfo)
 {
     $kernel->onRegisterServices(function (InjectorInterface $injector) {
         $injector->delegate(Server::class, function (ResponseFactoryInterface $responseFactory, ContentServerSettings $settings) {
             return ServerFactory::create(['source' => $settings->fileArchivePath(), 'cache' => $settings->imagesCachePath(), 'response' => new PsrResponseFactory($responseFactory->makeStream(), function ($stream) use($responseFactory) {
                 return $responseFactory->makeBody('', $stream);
             })]);
         })->share(Server::class)->delegate(ContentRepositoryInterface::class, function (ContentServerSettings $settings) {
             $urlBuilder = UrlBuilderFactory::create($settings->fileBaseUrl());
             return new ContentRepository($urlBuilder);
         })->share(ContentRepositoryInterface::class)->share(ContentServerSettings::class);
     });
 }
예제 #3
0
 /**
  * @inheritdoc
  */
 protected function init()
 {
     if (!$this->options['key'] || !$this->options['secret'] || !$this->options['region'] || !$this->options['bucket']) {
         return $this->setError('Required options undefined.');
     }
     $this->s3Client = new S3Client(['credentials' => ['key' => $this->options['key'], 'secret' => $this->options['secret']], 'region' => $this->options['region'], 'version' => $this->options['version']]);
     $this->s3Adapter = new AwsS3Adapter($this->s3Client, $this->options['bucket'], $this->options['prefix'] ?: '');
     $this->root = $this->options['path'];
     $this->rootName = 's3';
     if ($this->options['glideURL']) {
         $this->urlBuilder = UrlBuilderFactory::create($this->options['glideURL'], $this->options['glideKey']);
     }
     return true;
 }
예제 #4
0
파일: Helper.php 프로젝트: haaseit/hcsf
 public static function getSignedGlideURL($file, $width = 0, $height = 0)
 {
     $urlBuilder = \League\Glide\Urls\UrlBuilderFactory::create('', HelperConfig::$secrets['glide_signkey']);
     $param = [];
     if ($width == 0 && $height == 0) {
         return false;
     }
     if ($width != 0) {
         $param['w'] = $width;
     }
     if ($height != 0) {
         $param['h'] = $height;
     }
     if ($width != 0 && $height != 0) {
         $param['fit'] = 'stretch';
     }
     return $urlBuilder->getUrl($file, $param);
 }
예제 #5
0
파일: Image.php 프로젝트: furthered/assets
 protected function getBuilder()
 {
     return UrlBuilderFactory::create($this->getBaseUrl(), 'faster-stronger');
 }
예제 #6
0
 /**
  * Get URL builder instance.
  *
  * @param \League\Urls\UrlBuilder|null $urlBuilder URL builder instance to
  *   set or null to get instance.
  *
  * @return \League\Urls\UrlBuilder URL builder instance.
  */
 public function urlBuilder($urlBuilder = null)
 {
     if ($urlBuilder !== null) {
         return $this->_urlBuilder = $urlBuilder;
     }
     if (!isset($this->_urlBuilder)) {
         $config = $this->_config;
         $this->_urlBuilder = UrlBuilderFactory::create($config['baseUrl'], $config['secureUrls'] ? $config['signKey'] ?: Security::salt() : null);
     }
     return $this->_urlBuilder;
 }
예제 #7
0
 /**
  * Prepare driver before mount volume.
  * Return true if volume is ready.
  *
  * @return bool
  **/
 protected function init()
 {
     $this->fs = $this->options['filesystem'];
     if (!$this->fs instanceof FilesystemInterface) {
         return $this->setError('A filesystem instance is required');
     }
     // flysystem cache object instance (cached adapter dose not have method like a `getCache()`.
     if (isset($this->options['fscache']) && interface_exists('\\League\\Flysystem\\Cached\\CacheInterface', false)) {
         if ($this->options['fscache'] instanceof \League\Flysystem\Cached\CacheInterface) {
             $this->fscache = $this->options['fscache'];
         }
     }
     $this->fs->addPlugin(new GetUrl());
     $this->fs->addPlugin(new HasDir());
     $this->options['icon'] = $this->options['icon'] ?: $this->getIcon();
     $this->root = $this->options['path'];
     if ($this->options['glideURL']) {
         $this->urlBuilder = UrlBuilderFactory::create($this->options['glideURL'], $this->options['glideKey']);
     }
     if ($this->options['imageManager']) {
         $this->imageManager = $this->options['imageManager'];
     } else {
         $this->imageManager = new ImageManager();
     }
     return true;
 }
예제 #8
0
 /**
  * Prepare driver before mount volume.
  * Return true if volume is ready.
  *
  * @return bool
  **/
 protected function init()
 {
     $this->fs = $this->options['filesystem'];
     if (!$this->fs instanceof FilesystemInterface) {
         return $this->setError('A filesystem instance is required');
     }
     if ($this->fs instanceof Filesystem) {
         $adapter = $this->fs->getAdapter();
         // If the Flysystem adapter already is a cache, try to determine the cache.
         if ($adapter instanceof CachedAdapter) {
             // Try to get the cache (method doesn't exist in all versions)
             if (method_exists($adapter, 'getCache')) {
                 $this->fscache = $adapter->getCache();
             } elseif ($this->options['fscache'] instanceof CacheInterface) {
                 $this->fscache = $this->options['fscache'];
             }
         } elseif ($this->options['cache']) {
             switch ($this->options['cache']) {
                 case 'session':
                     $this->fscache = new SessionStore($this->session, 'fls_cache_' . $this->id);
                     break;
                 case 'memory':
                     $this->fscache = new MemoryStore();
                     break;
             }
             if ($this->fscache) {
                 $adapter = new CachedAdapter($adapter, $this->fscache);
                 $this->fs = new Filesystem($adapter);
             }
         }
     }
     $this->fs->addPlugin(new GetUrl());
     $this->options['icon'] = $this->options['icon'] ?: (empty($this->options['rootCssClass']) ? $this->getIcon() : '');
     $this->root = $this->options['path'];
     if ($this->options['glideURL']) {
         $this->urlBuilder = UrlBuilderFactory::create($this->options['glideURL'], $this->options['glideKey']);
     }
     if ($this->options['imageManager']) {
         $this->imageManager = $this->options['imageManager'];
     } else {
         $this->imageManager = new ImageManager();
     }
     return true;
 }
예제 #9
0
 /**
  * Get the full url for the image. Glide options can be used. A security
  * key is generated to prevent unsolicited image generation.
  *
  * ```
  * $options = [
  *     'h' => 200,
  *     'w' => 300,
  *     'fit' => 'crop',
  * ]
  * ```
  *
  * @param array $options Glide compatible options
  * @return string
  */
 public function getUrl($options = [])
 {
     $urlBuilder = UrlBuilderFactory::create(Configure::read('Glide.serverConfig.base_url'), Configure::read('Glide.secureUrls') ? Security::salt() : null);
     $prefixedPath = $this->source() . DS . $this->filename;
     return $urlBuilder->getUrl($prefixedPath, $options);
 }
예제 #10
0
 /**
  * @inheritdoc
  */
 protected function init()
 {
     $this->fs = $this->options['filesystem'];
     if (!$this->fs instanceof FilesystemInterface && !$this->fs instanceof \creocoder\flysystem\Filesystem) {
         return $this->setError('A filesystem instance is required');
     }
     $this->fs->addPlugin(new UrlPlugin());
     isset($this->options['icon']) ?: ($this->options['icon'] = $this->getIcon());
     $this->root = $this->options['path'];
     if ($this->options['glideURL']) {
         $this->urlBuilder = UrlBuilderFactory::create($this->options['glideURL'], $this->options['glideKey']);
     }
     if ($this->options['imageManager']) {
         $this->imageManager = $this->options['imageManager'];
     } else {
         $this->imageManager = new ImageManager();
     }
     return true;
 }