Skip to content

Commit

Permalink
Resolved #11, Implement getDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
dusta authored Dec 5, 2018
1 parent 737d5de commit 57fdf73
Showing 1 changed file with 47 additions and 32 deletions.
79 changes: 47 additions & 32 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -98,6 +98,7 @@ public function __construct($config, $image, $default = false, $storage)
public function stylist($stylist = false)
{
$this->stylist = $stylist;

return $this;
}

Expand All @@ -109,6 +110,7 @@ public function stylist($stylist = false)
public function size($size)
{
$this->size = $size;

return $this;
}

Expand All @@ -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']);
}

Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
*
Expand All @@ -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;
}

Expand All @@ -249,18 +245,19 @@ public function renderFile($file, $adapter = 'local')
$fileAdapter = $adapter . '://' . $file;
// Retrieve a read-stream
if (!$this->manager->has($fileAdapter)) {
$body = "<h1>404 Not Found</h1> \n\r" .
"The page that you have requested could not be found.";
$body = "<h1>404 Not Found</h1> \n\r" . "The page that you have requested could not be found.";

return Response::render($body)->status(404);
return Response::render($body)
->status(404);
}

$getMimetype = $this->manager->getMimetype($fileAdapter);
$stream = $this->manager->readStream($fileAdapter);
$contents = stream_get_contents($stream);
fclose($stream);

return Response::render($contents)->headers(['Content-type' => $getMimetype]);
return Response::render($contents)
->headers(['Content-type' => $getMimetype]);
}

/**
Expand All @@ -270,4 +267,22 @@ public function addStylist($stylists)
{
$this->stylists = array_merge($this->stylists, $stylists);
}

/**
* 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();
}
}

0 comments on commit 57fdf73

Please sign in to comment.