public function getImageUrl($path, array $params = []) { if (exists($path)) { return rtrim(substr($this->urlBuilder->getUrl($path, $params), 1), '?'); } return ''; }
/** * @inheritdoc */ protected function _stat($path) { $stat = array('size' => 0, 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'mime' => 'directory'); if ($this->root == $path) { $stat['name'] = $this->root; return $stat; } $path = $this->_normpath($path); $meta = $this->s3Adapter->getMetadata($path); $meta = $meta === false ? $this->s3Adapter->getMetadata($path . '/') : $meta; if ($meta === false) { return []; } $stat['ts'] = isset($meta['timestamp']) ? $meta['timestamp'] : $this->s3Adapter->getTimestamp($path); $stat['size'] = isset($meta['size']) ? $meta['size'] : $this->s3Adapter->getSize($path); if (!isset($stat['url']) && method_exists($this->s3Adapter, 'getUrl') && ($url = $this->s3Adapter->getUrl($path))) { $stat['url'] = $url; } if ($meta['type'] == 'file') { $stat['mime'] = isset($meta['mimetype']) ? $meta['mimetype'] : $this->s3Adapter->getMimetype($path); $imgMimes = ['image/jpeg', 'image/png', 'image/gif']; if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) { if (!isset($stat['url'])) { $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']); } } return $stat; }
/** * @inheritdoc */ 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)) { // return array(); // } // // $meta = $this->fs->getMetadata($path); try { $meta = $this->fs->getMetadata($path); } catch (FileNotFoundException $e) { $path = $path . '/'; try { $meta = $this->fs->getMetadata($path); } catch (FileNotFoundException $e) { return array(); } } // Get timestamp/size $stat['ts'] = isset($meta['timestamp']) ? $meta['timestamp'] : $this->fs->getTimestamp($path); $stat['size'] = isset($meta['size']) ? $meta['size'] : $this->fs->getSize($path); // Check if file, if so, check mimetype if ($meta['type'] == 'file') { $stat['mime'] = isset($meta['mimetype']) ? $meta['mimetype'] : $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; }
public function testGetInvalidUrl() { $this->setExpectedException('\\InvalidArgumentException', 'Not a valid path.'); $urlBuilder = new UrlBuilder(':80'); $urlBuilder->getUrl('image.jpg'); }