Creating a @thumbnail blade directive

parent 1b7a4852
<?php
namespace Modules\Media\Blade\Facades;
use Illuminate\Support\Facades\Facade;
class MediaThumbnailDirective extends Facade
{
protected static function getFacadeAccessor()
{
return 'media.thumbnail.directive';
}
}
<?php
namespace Modules\Media\Blade;
use Modules\Media\Image\Imagy;
class MediaThumbnailDirective
{
/**
* @var string
*/
private $path;
/**
* @var string
*/
private $thumbnail;
/**
* @var Imagy
*/
private $imagy;
public function __construct()
{
$this->imagy = app(Imagy::class);
}
public function show($arguments)
{
$this->extractArguments($arguments);
return $this->imagy->getThumbnail($this->path, $this->thumbnail);
}
/**
* Extract the possible arguments as class properties
* @param array $arguments
*/
private function extractArguments(array $arguments)
{
$this->path = array_get($arguments, 0);
$this->thumbnail = array_get($arguments, 1);
}
}
......@@ -8,6 +8,7 @@ use Illuminate\Support\ServiceProvider;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Media\Blade\MediaMultipleDirective;
use Modules\Media\Blade\MediaSingleDirective;
use Modules\Media\Blade\MediaThumbnailDirective;
use Modules\Media\Console\RefreshThumbnailCommand;
use Modules\Media\Contracts\DeletingMedia;
use Modules\Media\Contracts\StoringMedia;
......@@ -46,6 +47,9 @@ class MediaServiceProvider extends ServiceProvider
$this->app->bind('media.multiple.directive', function () {
return new MediaMultipleDirective();
});
$this->app->bind('media.thumbnail.directive', function () {
return new MediaThumbnailDirective();
});
}
public function boot(DispatcherContract $events)
......@@ -143,5 +147,8 @@ class MediaServiceProvider extends ServiceProvider
$this->app['blade.compiler']->directive('mediaMultiple', function ($value) {
return "<?php echo MediaMultipleDirective::show([$value]); ?>";
});
$this->app['blade.compiler']->directive('thumbnail', function ($value) {
return "<?php echo MediaThumbnailDirective::show([$value]); ?>";
});
}
}
......@@ -17,7 +17,8 @@
"Imagy": "Modules\\Media\\Image\\Facade\\Imagy",
"FileHelper": "Modules\\Media\\Helpers\\FileHelper",
"MediaSingleDirective": "Modules\\Media\\Blade\\Facades\\MediaSingleDirective",
"MediaMultipleDirective": "Modules\\Media\\Blade\\Facades\\MediaMultipleDirective"
"MediaMultipleDirective": "Modules\\Media\\Blade\\Facades\\MediaMultipleDirective",
"MediaThumbnailDirective": "Modules\\Media\\Blade\\Facades\\MediaThumbnailDirective"
},
"files": [
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment