diff --git a/src/Image.php b/src/Image.php index 3cc4565..97f568c 100644 --- a/src/Image.php +++ b/src/Image.php @@ -66,9 +66,9 @@ class Image /** * Image constructor. * - * @param $image - * @param bool $default - * @param $storage + * @param $image + * @param bool $default + * @param \Dframe\FileStorage\Storage $storage */ public function __construct($config, $image, $default = false, $storage) { @@ -98,6 +98,7 @@ public function __construct($config, $image, $default = false, $storage) public function stylist($stylist = false) { $this->stylist = $stylist; + return $this; } @@ -109,6 +110,7 @@ public function stylist($stylist = false) public function size($size) { $this->size = $size; + return $this; } @@ -120,6 +122,7 @@ public function size($size) public function display($adapter = 'local') { $get = $this->cache($adapter, $this->orginalImage); + return $this->router->makeUrl('filestorage/images/:params?params=' . $get['cache']); } @@ -174,26 +177,32 @@ public function cache($adapter, $originalImage, $default = false) } if (!empty($this->storage)) { - if (!empty($this->storage->driver)) { - $this->storage->driver->cache($adapter, $originalImage, $cache, $mimetype, $readStream); + if (!empty($this->storage->getDriver())) { + $this->storage->getDriver() + ->cache($adapter, $originalImage, $cache, $mimetype, $readStream); } $this->manager->putStream($cacheAdapter, $readStream); } else { + return false; } } elseif (!empty($this->defaultImage)) { - if (!empty($this->storage->driver)) { - $get = $this->storage->driver->get($adapter, $originalImage, true); + + if (!empty($this->storage->getDriver())) { + $get = $this->storage->getDriver() + ->get($adapter, $originalImage, true); if ($get['return'] == true) { foreach ($get['cache'] as $key => $value) { if ($this->manager->has('cache://' . $value['file_cache_path'])) { $this->manager->delete('cache://' . $value['file_cache_path']); } } - //$this->storage->driver->drop($originalImage); + //$this->storage->getDriver()->drop($originalImage); } } + if ($default == false) { + return $this->cache($adapter, $this->defaultImage, true); //zwracać bład } } @@ -206,24 +215,6 @@ public function cache($adapter, $originalImage, $default = false) ]; } - /** - * Zwraca obiekt stylisty o wskazanej nazwie - * Tylko do uzytku wewnatrz klasy! - * - * @param string $stylist - * - * @return \Dframe\FileStorage\Stylist - */ - protected function getStylist($stylist = 'orginal') - { - $className = $this->stylists[$stylist]; - if (!class_exists($className) or !method_exists($className, 'stylize')) { - throw new \Exception('Requested stylist "' . $stylist . '" was not found or is incorrect'); - } - - return new $className(); - } - /** * @param string $adapter * @@ -232,9 +223,14 @@ protected function getStylist($stylist = 'orginal') public function get($adapter = 'local') { $data = $this->cache($adapter, $this->orginalImage); - if (!empty($this->storage->driver)) { - $data = $this->storage->driver->get($adapter, $this->orginalImage); + if (!empty($this->storage->getDriver())) { + $get = $this->storage->getDriver() + ->get($adapter, $this->orginalImage, $data['cache']); + if ($get['return'] === true) { + $data['data'] = $get['cache']; + } } + return $data; } @@ -249,10 +245,10 @@ public function renderFile($file, $adapter = 'local') $fileAdapter = $adapter . '://' . $file; // Retrieve a read-stream if (!$this->manager->has($fileAdapter)) { - $body = "