/** * 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; }
/** * Return stat for given path. * Stat contains following fields: * - (int) size file size in b. required * - (int) ts file modification time in unix time. required * - (string) mime mimetype. required for folders, others - optionally * - (bool) read read permissions. required * - (bool) write write permissions. required * - (bool) locked is object locked. optionally * - (bool) hidden is object hidden. optionally * - (string) alias for symlinks - link target path relative to root path. optionally * - (string) target for symlinks - link target path. optionally * * If file does not exists - returns empty array or false. * * @param string $path file path * @return array|false **/ protected function _stat($path) { $stat = array('size' => 0, 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'mime' => 'directory'); // If root, just return from above if ($this->root == $path) { $stat['name'] = $this->root; return $stat; } // If not exists, return empty if (!$this->fs->has($path)) { // Check if the parent doesn't have this path if ($this->_dirExists($path)) { return $stat; } // Neither a file or directory exist, return empty return array(); } try { $meta = $this->fs->getMetadata($path); } catch (\Exception $e) { return array(); } if (false === $meta) { return $stat; } // Set item filename.extension to `name` if exists if (isset($meta['filename']) && isset($meta['extension'])) { $stat['name'] = $meta['filename']; if ($meta['extension'] !== '') { $stat['name'] .= '.' . $meta['extension']; } } // Get timestamp/size if available if (isset($meta['timestamp'])) { $stat['ts'] = $meta['timestamp']; } if (isset($meta['size'])) { $stat['size'] = $meta['size']; } // Check if file, if so, check mimetype when available if ($meta['type'] == 'file') { if (isset($meta['mimetype'])) { $stat['mime'] = $meta['mimetype']; } else { $stat['mime'] = $this->fs->getMimetype($path); } $imgMimes = ['image/jpeg', 'image/png', 'image/gif']; if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) { $stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]); $stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']); } } if (!isset($stat['url']) && $this->fs->getUrl()) { $stat['url'] = 1; } return $stat; }
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); }); }
/** * @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; }
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); }
protected function getBuilder() { return UrlBuilderFactory::create($this->getBaseUrl(), 'faster-stronger'); }
/** * 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; }
/** * 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; }
/** * 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); }
/** * @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; }