From f6d53ea84e69760f06a5bcd543a8735408da4d48 Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Thu, 2 Feb 2017 13:01:01 +0000 Subject: [PATCH] Adding Laravel 5.4 Support --- .gitignore | 1 - .scrutinizer.yml | 2 +- .travis.yml | 2 +- LICENSE.md | 2 +- composer.json | 11 +-- src/Contracts/Media.php | 30 +++++++ src/Http/Controllers/Admin/Controller.php | 4 +- .../Controllers/Admin/MediasController.php | 6 +- src/Http/Routes/Admin/ApiRoutes.php | 39 ++++++++ src/Http/Routes/Admin/MediaRoutes.php | 35 ++------ src/Media.php | 90 +++++++++++++++++++ src/MediaServiceProvider.php | 13 ++- src/Providers/RouteServiceProvider.php | 3 +- tests/MediaServiceProviderTest.php | 2 +- tests/MediaTest.php | 61 +++++++++++++ 15 files changed, 254 insertions(+), 47 deletions(-) create mode 100644 src/Contracts/Media.php create mode 100644 src/Http/Routes/Admin/ApiRoutes.php create mode 100644 src/Media.php create mode 100644 tests/MediaTest.php diff --git a/.gitignore b/.gitignore index d0d6300..cb1299f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /build/ /vendor/ -/_ide_helper.php /composer.lock /composer.phar diff --git a/.scrutinizer.yml b/.scrutinizer.yml index d44a72f..282131b 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -22,7 +22,7 @@ checks: tools: external_code_coverage: timeout: 600 - runs: 2 + runs: 3 php_code_sniffer: enabled: true config: diff --git a/.travis.yml b/.travis.yml index 40e99d0..9baf109 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ matrix: - php: nightly env: - - TESTBENCH_VERSION=3.3.* + - TESTBENCH_VERSION=3.4.* before_script: - travis_retry composer self-update diff --git a/LICENSE.md b/LICENSE.md index dff7a8a..cbc95f0 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 ARCANEDEV - Media For ARCANESOFT +Copyright (c) 2016-2017 ARCANEDEV - Media For ARCANESOFT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 2a5a3b5..e5b89a8 100644 --- a/composer.json +++ b/composer.json @@ -17,13 +17,14 @@ "license": "MIT", "require": { "php": ">=5.6.4", - "arcanesoft/auth": "~1.0", - "arcanesoft/core": "~1.4", - "intervention/image": "~2.0" + "arcanesoft/auth": "~2.0", + "arcanesoft/core": "~1.5", + "intervention/image": "~2.3" }, "require-dev": { "phpunit/phpcov": "~3.0", - "phpunit/phpunit": "~5.0" + "phpunit/phpunit": "~5.0", + "orchestra/testbench": "~3.4.0" }, "autoload": { "psr-4": { @@ -36,7 +37,7 @@ } }, "scripts": { - "testbench": "composer require --dev \"orchestra/testbench=~3.3.0\"" + "testbench": "composer require --dev \"orchestra/testbench=~3.4.0\"" }, "extra": { "branch-alias": { diff --git a/src/Contracts/Media.php b/src/Contracts/Media.php new file mode 100644 index 0000000..83eb3d4 --- /dev/null +++ b/src/Contracts/Media.php @@ -0,0 +1,30 @@ + + */ +interface Media +{ + /* ------------------------------------------------------------------------------------------------ + | Main Functions + | ------------------------------------------------------------------------------------------------ + */ + /** + * Get a filesystem adapter. + * + * @param string|null $driver + * + * @return \Illuminate\Contracts\Filesystem\Filesystem + */ + public function disk($driver = null); + + /** + * Get the default filesystem adapter. + * + * @return \Illuminate\Contracts\Filesystem\Filesystem + */ + public function defaultDisk(); +} diff --git a/src/Http/Controllers/Admin/Controller.php b/src/Http/Controllers/Admin/Controller.php index c4b2cca..19b2aca 100644 --- a/src/Http/Controllers/Admin/Controller.php +++ b/src/Http/Controllers/Admin/Controller.php @@ -1,6 +1,6 @@ */ -abstract class Controller extends BaseController +abstract class Controller extends AdminController { /* ------------------------------------------------------------------------------------------------ | Traits diff --git a/src/Http/Controllers/Admin/MediasController.php b/src/Http/Controllers/Admin/MediasController.php index 53f2422..f2b9e71 100644 --- a/src/Http/Controllers/Admin/MediasController.php +++ b/src/Http/Controllers/Admin/MediasController.php @@ -77,7 +77,7 @@ public function uploadMedia(Request $request) public function createDirectory(Request $request) { $data = $request->all(); - $validator = \Validator::make($data, [ + $validator = validator($data, [ 'name' => 'required', // TODO: check if the folder does not exists 'location' => 'required', ]); @@ -103,7 +103,7 @@ public function renameMedia(Request $request) $data = $request->all(); // TODO: check if the folder does not exists - $validator = \Validator::make($data, [ + $validator = validator($data, [ 'media' => 'required', 'newName' => 'required', 'location' => 'required', @@ -117,7 +117,7 @@ public function renameMedia(Request $request) $location = trim($data['location'], '/'); $media = $data['media']; - $src = $location . '/' . $media['name']; + $src = $location . '/' . $media['name']; if ($media['type'] == 'file') { $ext = pathinfo($media['url'], PATHINFO_EXTENSION); diff --git a/src/Http/Routes/Admin/ApiRoutes.php b/src/Http/Routes/Admin/ApiRoutes.php new file mode 100644 index 0000000..2387fc1 --- /dev/null +++ b/src/Http/Routes/Admin/ApiRoutes.php @@ -0,0 +1,39 @@ + + */ +class ApiRoutes extends RouteRegistrar +{ + /* ------------------------------------------------------------------------------------------------ + | Main Functions + | ------------------------------------------------------------------------------------------------ + */ + /** + * Map routes. + */ + public function map() + { + $this->prefix('api')->name('api.')->group(function () { + $this->get('all', 'MediasController@getAll') + ->name('get'); // admin::media.api.get + + $this->post('upload', 'MediasController@uploadMedia') + ->name('upload'); // admin::media.api.upload + + $this->post('rename', 'MediasController@renameMedia') + ->name('rename'); // admin::media.api.rename + + $this->post('delete', 'MediasController@deleteMedia') + ->name('delete'); // admin::media.api.delete + + $this->post('create', 'MediasController@createDirectory') + ->name('create'); // admin::media.api.create + }); + } +} diff --git a/src/Http/Routes/Admin/MediaRoutes.php b/src/Http/Routes/Admin/MediaRoutes.php index c53203d..890fae5 100644 --- a/src/Http/Routes/Admin/MediaRoutes.php +++ b/src/Http/Routes/Admin/MediaRoutes.php @@ -1,7 +1,6 @@ */ -class MediaRoutes extends RouteRegister +class MediaRoutes extends RouteRegistrar { /* ------------------------------------------------------------------------------------------------ | Main Functions @@ -17,34 +16,10 @@ class MediaRoutes extends RouteRegister */ /** * Map routes. - * - * @param \Illuminate\Contracts\Routing\Registrar $router */ - public function map(Registrar $router) + public function map() { - // media::foundation.index - $this->get('/', 'MediasController@index')->name('index'); - - $this->registerApiRoutes(); - } - - /** - * Register the media api routes. - */ - private function registerApiRoutes() - { - // TODO: Adding ajax middleware - $this->group(['prefix' => 'api', 'as' => 'api.'], function () { - // admin::media.api.get - $this->get('all', 'MediasController@getAll')->name('get'); - // admin::media.api.upload - $this->post('upload', 'MediasController@uploadMedia')->name('upload'); - // admin::media.api.delete - $this->post('rename', 'MediasController@renameMedia')->name('rename'); - // admin::media.api.delete - $this->post('delete', 'MediasController@deleteMedia')->name('delete'); - // admin::media.api.create - $this->post('create', 'MediasController@createDirectory')->name('create'); - }); + $this->get('/', 'MediasController@index') + ->name('index'); // media::foundation.index } } diff --git a/src/Media.php b/src/Media.php new file mode 100644 index 0000000..02af1e4 --- /dev/null +++ b/src/Media.php @@ -0,0 +1,90 @@ + + */ +class Media implements MediaContract +{ + /* ------------------------------------------------------------------------------------------------ + | Properties + | ------------------------------------------------------------------------------------------------ + */ + /** + * The application instance. + * + * @var \Illuminate\Contracts\Foundation\Application + */ + protected $app; + + /* ------------------------------------------------------------------------------------------------ + | Constructor + | ------------------------------------------------------------------------------------------------ + */ + /** + * Media constructor. + * + * @param \Illuminate\Contracts\Foundation\Application $app + */ + public function __construct(Application $app) + { + $this->app = $app; + } + + /* ------------------------------------------------------------------------------------------------ + | Getters & Setters + | ------------------------------------------------------------------------------------------------ + */ + /** + * Get the Filesystem Manager instance. + * + * @return \Illuminate\Contracts\Filesystem\Factory + */ + public function filesystem() + { + return $this->app->make('filesystem'); + } + + /** + * Get the Config Repository. + * + * @return \Illuminate\Contracts\Config\Repository + */ + protected function config() + { + return $this->app->make('config'); + } + + /* ------------------------------------------------------------------------------------------------ + | Main Functions + | ------------------------------------------------------------------------------------------------ + */ + /** + * Get a filesystem adapter. + * + * @param string|null $driver + * + * @return \Illuminate\Contracts\Filesystem\Filesystem + */ + public function disk($driver = null) + { + return $this->filesystem()->disk($driver); + } + + /** + * Get the default filesystem adapter. + * + * @return \Illuminate\Contracts\Filesystem\Filesystem + */ + public function defaultDisk() + { + return $this->disk( + $this->config()->get('arcanesoft.media.filesystem.default') + ); + } +} diff --git a/src/MediaServiceProvider.php b/src/MediaServiceProvider.php index 880263f..acea9d3 100644 --- a/src/MediaServiceProvider.php +++ b/src/MediaServiceProvider.php @@ -45,6 +45,8 @@ public function getBasePath() */ public function register() { + parent::register(); + $this->registerConfig(); $this->registerSidebarItems(); $this->registerProviders([ @@ -55,6 +57,7 @@ public function register() $this->registerConsoleServiceProvider(Providers\ConsoleServiceProvider::class); $this->syncFilesystemConfig(); + $this->registerMediaManager(); } /** @@ -82,7 +85,7 @@ public function boot() public function provides() { return [ - // + Contracts\Media::class, ]; } @@ -100,6 +103,14 @@ private function syncFilesystemConfig() } } + /** + * Register the media manager. + */ + private function registerMediaManager() + { + $this->singleton(Contracts\Media::class, Media::class); + } + /** * Publish the assets. */ diff --git a/src/Providers/RouteServiceProvider.php b/src/Providers/RouteServiceProvider.php index 435641c..766c736 100644 --- a/src/Providers/RouteServiceProvider.php +++ b/src/Providers/RouteServiceProvider.php @@ -43,8 +43,9 @@ private function mapAdminRoutes(Router $router) $this->config()->get('arcanesoft.media.route.prefix', 'media') ); - $router->group($attributes, function (Router $router) { + $router->group($attributes, function ($router) { Routes\Admin\MediaRoutes::register($router); + Routes\Admin\ApiRoutes::register($router); // TODO: Adding `api` or `ajax` middleware ? }); } } diff --git a/tests/MediaServiceProviderTest.php b/tests/MediaServiceProviderTest.php index 5d9a67a..9dc0242 100644 --- a/tests/MediaServiceProviderTest.php +++ b/tests/MediaServiceProviderTest.php @@ -57,7 +57,7 @@ public function it_can_be_instantiated() public function it_can_provides() { $expected = [ - // + \Arcanesoft\Media\Contracts\Media::class, ]; $this->assertSame($expected, $this->provider->provides()); diff --git a/tests/MediaTest.php b/tests/MediaTest.php new file mode 100644 index 0000000..2285458 --- /dev/null +++ b/tests/MediaTest.php @@ -0,0 +1,61 @@ + + */ +class MediaTest extends TestCase +{ + /* ------------------------------------------------------------------------------------------------ + | Properties + | ------------------------------------------------------------------------------------------------ + */ + /** @var \Arcanesoft\Media\Contracts\Media */ + protected $media; + + /* ------------------------------------------------------------------------------------------------ + | Main Functions + | ------------------------------------------------------------------------------------------------ + */ + public function setUp() + { + parent::setUp(); + + $this->media = $this->app->make(\Arcanesoft\Media\Contracts\Media::class); + } + + public function tearDown() + { + unset($this->media); + + parent::tearDown(); + } + + /* ------------------------------------------------------------------------------------------------ + | Test Functions + | ------------------------------------------------------------------------------------------------ + */ + /** @test */ + public function it_can_be_instantiated() + { + $expectations = [ + \Arcanesoft\Media\Contracts\Media::class, + \Arcanesoft\Media\Media::class, + ]; + + foreach ($expectations as $expected) { + $this->assertInstanceOf($expected, $this->media); + } + } + + /** @test */ + public function it_can_get_default_disk() + { + $this->assertInstanceOf( + \Illuminate\Filesystem\FilesystemAdapter::class, + $this->media->defaultDisk() + ); + } +}