Skip to content

Commit

Permalink
Resolve #30, PSR-12
Browse files Browse the repository at this point in the history
  • Loading branch information
dusta committed Dec 27, 2019
1 parent 7c3b081 commit 16a1fb1
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/**
* Example Class
*/

class MetadataFile
{
/**
Expand All @@ -16,7 +15,6 @@ class MetadataFile
*/
public function __construct($mime, $stream)
{

//$putStream = tmpfile();
//fwrite($putStream, stream_get_contents($readStream));
//rewind($putStream);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

namespace Libs\Plugins\FileStorage\Stylists;

use Dframe\FileStorage\Stylist;
use Exception;
use Imagecraft\ImageBuilder;

/*
Expand All @@ -13,7 +16,7 @@
*
* @package Libs\Plugins\FileStorage\Stylists
*/
class OriginalStylist extends \Dframe\FileStorage\Stylist
class OriginalStylist extends Stylist
{
/**
* @param resource $originStream
Expand All @@ -32,16 +35,16 @@ public function stylize($originStream, $extension, $stylistObj = false, $stylist
$layer = $builder->addBackgroundLayer();
$contents = stream_get_contents($originStream);
$layer->contents($contents);

fclose($originStream);

$image = $builder->save();

$tmpFile = tmpfile();
if ($image->isValid()) {
fwrite($tmpFile, $image->getContents());
} else {
throw new \Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
throw new Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
}

rewind($tmpFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

namespace Libs\Plugins\FileStorage\Stylists;

use Dframe\FileStorage\Stylist;
use Exception;
use Imagecraft\ImageBuilder;

/*
Expand All @@ -12,7 +15,7 @@
*
* @package Libs\Plugins\FileStorage\Stylists
*/
class RealStylist extends \Dframe\FileStorage\Stylist
class RealStylist extends Stylist
{
/**
* @param resource $originStream
Expand All @@ -31,25 +34,25 @@ public function stylize($originStream, $extension, $stylistObj = false, $stylist
$layer = $builder->addBackgroundLayer();
$contents = stream_get_contents($originStream);
$layer->contents($contents);


if (isset($stylistParam['size'])) {
$size = $stylistParam['size'];
} else {
$size = '100';
}

$layer->resize($size, $size, 'shrink');

fclose($originStream);

$image = $builder->save();

$tmpFile = tmpfile();
if ($image->isValid()) {
fwrite($tmpFile, $image->getContents());
} else {
throw new \Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
throw new Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
}

rewind($tmpFile);
Expand All @@ -69,6 +72,6 @@ public function identify($stylistParam)
$size = '100';
}

return 'realStylist-'.$size;
return 'realStylist-' . $size;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

namespace Libs\Plugins\FileStorage\Stylists;

use Dframe\FileStorage\Stylist;
use Exception;
use Imagecraft\ImageBuilder;

/*
Expand All @@ -15,7 +18,7 @@
*
* @package Libs\Plugins\FileStorage\Stylists
*/
class RectStylist extends \Dframe\FileStorage\Stylist
class RectStylist extends Stylist
{
/**
* @param resource $originStream
Expand All @@ -35,16 +38,16 @@ public function stylize($originStream, $extension, $stylistObj = false, $stylist
$contents = stream_get_contents($originStream);
$layer->contents($contents);
$layer->resize($stylistParam['w'], $stylistParam['h'], 'fill_crop');

fclose($originStream);

$image = $builder->save();

$tmpFile = tmpfile();
if ($image->isValid()) {
fwrite($tmpFile, $image->getContents());
} else {
throw new \Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
throw new Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
}

rewind($tmpFile);
Expand All @@ -58,6 +61,6 @@ public function stylize($originStream, $extension, $stylistObj = false, $stylist
*/
public function identify($stylistParam)
{
return 'rectStylist-'.$stylistParam['w'].'-'.$stylistParam['h'];
return 'rectStylist-' . $stylistParam['w'] . '-' . $stylistParam['h'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Libs\Plugins\FileStorage\Stylists;

use Dframe\FileStorage\Stylist;
use Exception;
use Imagecraft\ImageBuilder;

/*
Expand All @@ -16,7 +18,7 @@
*
* @package Libs\Plugins\FileStorage\Stylists
*/
class SquareStylist extends \Dframe\FileStorage\Stylist
class SquareStylist extends Stylist
{
/**
* @param resource $originStream
Expand Down Expand Up @@ -53,7 +55,7 @@ public function stylize($originStream, $extension, $stylistObj = false, $stylist
if ($image->isValid()) {
fwrite($tmpFile, $image->getContents());
} else {
throw new \Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
throw new Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
}

rewind($tmpFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php

namespace Model\FileStorage\Drivers;

use Dframe\FileStorage\Drivers\DatabaseDriverInterface;
use Exception;
use Model\Model;

/**
* Class DatabaseDriverModel
*
* @package Model\FileStorage\Drivers
*/
class DatabaseDriverModel extends \Model\Model implements DatabaseDriverInterface
class DatabaseDriverModel extends Model implements DatabaseDriverInterface
{
/**
* @param $adapter
Expand Down Expand Up @@ -54,7 +57,10 @@ public function put($adapter, $path, $mime, $stream = false)
return $this->methodResult(false, ['response' => 'Taki obraz już istnieje']);
}

$getLastInsertId = $this->db->pdoQuery('INSERT INTO `files` (`file_adapter`, `file_path`, `file_mime`) VALUES (?,?,?)', [$adapter, $path, $mime])->getLastInsertId();
$getLastInsertId = $this->db->pdoQuery(
'INSERT INTO `files` (`file_adapter`, `file_path`, `file_mime`) VALUES (?,?,?)',
[$adapter, $path, $mime]
)->getLastInsertId();
return $this->methodResult(true, ['lastInsertId' => $getLastInsertId]);
}

Expand Down Expand Up @@ -111,7 +117,7 @@ public function drop($adapter, $path)
$affectedRows = $this->db->delete('files', ['file_id' => $row['file_id']])->affectedRows();

$this->db->end();
} catch (\Exception $e) {
} catch (Exception $e) {
$this->db->back();
return $this->methodResult(false, ['response' => $e->getMessages()]);
}
Expand Down
6 changes: 4 additions & 2 deletions examples/example2/Stylists/OriginalStylist.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

use Dframe\FileStorage\Stylist;
use Imagecraft\ImageBuilder;

/*
Expand All @@ -9,7 +11,7 @@
/**
* Class OriginalStylist
*/
class OriginalStylist extends \Dframe\FileStorage\Stylist
class OriginalStylist extends Stylist
{
/**
* @param resource $originStream
Expand Down Expand Up @@ -37,7 +39,7 @@ public function stylize($originStream, $extension, $stylistObj = false, $stylist
if ($image->isValid()) {
fwrite($tmpFile, $image->getContents());
} else {
throw new \Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
throw new Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
}

rewind($tmpFile);
Expand Down
5 changes: 3 additions & 2 deletions examples/example2/Stylists/RectStylist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Dframe\FileStorage\Stylist;
use Imagecraft\ImageBuilder;

/*
Expand All @@ -12,7 +13,7 @@
/**
* Class RectStylist
*/
class RectStylist extends \Dframe\FileStorage\Stylist
class RectStylist extends Stylist
{
/**
* @param resource $originStream
Expand Down Expand Up @@ -48,7 +49,7 @@ public function stylize($originStream, $extension, $stylistObj = false, $stylist
if ($image->isValid()) {
fwrite($tmpFile, $image->getContents());
} else {
throw new \Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
throw new Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
}

rewind($tmpFile);
Expand Down
5 changes: 3 additions & 2 deletions examples/example2/Stylists/SquareStylist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Dframe\FileStorage\Stylist;
use Imagecraft\ImageBuilder;

/*
Expand All @@ -12,7 +13,7 @@
/**
* Class SquareStylist
*/
class SquareStylist extends \Dframe\FileStorage\Stylist
class SquareStylist extends Stylist
{
/**
* @param resource $originStream
Expand Down Expand Up @@ -49,7 +50,7 @@ public function stylize($originStream, $extension, $stylistObj = false, $stylist
if ($image->isValid()) {
fwrite($tmpFile, $image->getContents());
} else {
throw new \Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
throw new Exception($image->getMessage()); //echo $image->getMessage().PHP_EOL;
}

rewind($tmpFile);
Expand Down
40 changes: 28 additions & 12 deletions examples/example2/stylist.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

use Dframe\FileStorage\Storage;

error_reporting(E_ALL); # Debug settings
Expand All @@ -13,27 +14,42 @@
include "Stylists/SquareStylist.php";

$Storage = new Storage();
$Storage->settings([
'stylists' => [
'Original' => OriginalStylist::class,
'Rect' => RectStylist::class,
'Square' => SquareStylist::class
$Storage->settings(
[
'stylists' => [
'Original' => OriginalStylist::class,
'Rect' => RectStylist::class,
'Square' => SquareStylist::class
]
]
]);
);

$images = [];
$images[] = ['size' => 'Rect 50x50', 'img' => $Storage->image('picture1.jpg')->stylist('Rect')->size('50x50')->get()];
$images[] = ['size' => 'Rect 50x50 Custom Image if file not exist', 'img' => $Storage->image('fileNotExist.jpg', 'noImage.png')->stylist('Rect')->size('50x50')->get()];
$images[] = ['size' => 'Rect 250x100', 'img' => $Storage->image('picture1.jpg')->stylist('Rect')->size('250x100')->get()];
$images[] = ['size' => 'Square 250 width', 'img' => $Storage->image('picture1.jpg')->stylist('Square')->size('250')->get()];
$images[] = ['size' => 'Rect 250x550', 'img' => $Storage->image('picture1.jpg')->stylist('Rect')->size('250x550')->get()];
$images[] = [
'size' => 'Rect 50x50 Custom Image if file not exist',
'img' => $Storage->image('fileNotExist.jpg', 'noImage.png')->stylist('Rect')->size('50x50')->get()
];
$images[] = [
'size' => 'Rect 250x100',
'img' => $Storage->image('picture1.jpg')->stylist('Rect')->size('250x100')->get()
];
$images[] = [
'size' => 'Square 250 width',
'img' => $Storage->image('picture1.jpg')->stylist('Square')->size('250')->get()
];
$images[] = [
'size' => 'Rect 250x550',
'img' => $Storage->image('picture1.jpg')->stylist('Rect')->size('250x550')->get()
];
$images[] = ['size' => 'Original', 'img' => $Storage->image('picture1.jpg')->stylist('Orginal')->get()];

?>

<?php foreach ($images as $key => $image) {
?>
Size: <?php echo $image['size']; ?>;<br>
<img alt="" src="cache/<?php echo $image['img']['cache']; ?>"><hr>
<?php
<img alt="" src="cache/<?php echo $image['img']['cache']; ?>">
<hr>
<?php
} ?>
Loading

0 comments on commit 16a1fb1

Please sign in to comment.