From f8cd098ab78604a07a37ae5f13f60b1dec211431 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Tue, 28 Feb 2017 12:29:26 +0800 Subject: [PATCH 01/93] update composer to prepare for Beta2 --- composer.json | 84 ++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index f6a7ac40..1ea36d28 100644 --- a/composer.json +++ b/composer.json @@ -32,33 +32,34 @@ "ext-openssl": "*", "classpreloader/classpreloader": "~3.0", "doctrine/inflector": "~1.0", - "illuminate/auth": "5.3.*", - "illuminate/broadcasting": "5.3.*", - "illuminate/bus": "5.3.*", - "illuminate/cache": "5.3.*", - "illuminate/console": "5.3.*", - "illuminate/container": "5.3.*", - "illuminate/contracts": "5.3.*", - "illuminate/cookie": "5.3.*", - "illuminate/database": "5.3.*", - "illuminate/encryption": "5.3.*", - "illuminate/events": "5.3.*", - "illuminate/filesystem": "5.3.*", - "illuminate/hashing": "5.3.*", - "illuminate/http": "5.3.*", - "illuminate/log": "5.3.*", - "illuminate/mail": "5.3.*", - "illuminate/notifications": "5.3.*", - "illuminate/pagination": "5.3.*", - "illuminate/pipeline": "5.3.*", - "illuminate/queue": "5.3.*", - "illuminate/redis": "5.3.*", - "illuminate/routing": "5.3.*", - "illuminate/session": "5.3.*", - "illuminate/support": "5.3.*", - "illuminate/translation": "5.3.*", - "illuminate/validation": "5.3.*", - "illuminate/view": "5.3.*", + "erusev/parsedown": "~1.6", + "illuminate/auth": "5.4.*", + "illuminate/broadcasting": "5.4.*", + "illuminate/bus": "5.4.*", + "illuminate/cache": "5.4.*", + "illuminate/console": "5.4.*", + "illuminate/container": "5.4.*", + "illuminate/contracts": "5.4.*", + "illuminate/cookie": "5.4.*", + "illuminate/database": "5.4.*", + "illuminate/encryption": "5.4.*", + "illuminate/events": "5.4.*", + "illuminate/filesystem": "5.4.*", + "illuminate/hashing": "5.4.*", + "illuminate/http": "5.4.*", + "illuminate/log": "5.4.*", + "illuminate/mail": "5.4.*", + "illuminate/notifications": "5.4.*", + "illuminate/pagination": "5.4.*", + "illuminate/pipeline": "5.4.*", + "illuminate/queue": "5.4.*", + "illuminate/redis": "5.4.*", + "illuminate/routing": "5.4.*", + "illuminate/session": "5.4.*", + "illuminate/support": "5.4.*", + "illuminate/translation": "5.4.*", + "illuminate/validation": "5.4.*", + "illuminate/view": "5.4.*", "jeremeamia/superclosure": "~2.2", "laravel/passport": "^1.0", "league/flysystem": "~1.0", @@ -66,28 +67,29 @@ "mtdowling/cron-expression": "~1.0", "nesbot/carbon": "~1.20", "paragonie/random_compat": "~1.4|~2.0", - "psy/psysh": "0.7.*", "ramsey/uuid": "~3.0", - "swiftmailer/swiftmailer": "~5.1", - "symfony/console": "3.1.*", - "symfony/debug": "3.1.*", - "symfony/finder": "3.1.*", - "symfony/http-foundation": "3.1.*", - "symfony/http-kernel": "3.1.*", - "symfony/process": "3.1.*", - "symfony/routing": "3.1.*", - "symfony/translation": "3.1.*", - "symfony/var-dumper": "3.1.*", + "swiftmailer/swiftmailer": "~5.4", + "symfony/console": "3.2.*", + "symfony/debug": "3.2.*", + "symfony/finder": "3.2.*", + "symfony/http-foundation": "3.2.*", + "symfony/http-kernel": "3.2.*", + "symfony/process": "3.2.*", + "symfony/routing": "3.2.*", + "symfony/translation": "3.2.*", + "symfony/var-dumper": "3.2.*", + "tijsverkoyen/css-to-inline-styles": "~2.2", "vlucas/phpdotenv": "~2.2" }, "require-dev": { "aws/aws-sdk-php": "~3.0", + "doctrine/dbal": "~2.5", "mockery/mockery": "~0.9.4", "pda/pheanstalk": "~3.0", - "phpunit/phpunit": "~5.4", + "phpunit/phpunit": "~5.7", "predis/predis": "~1.0", - "symfony/css-selector": "3.1.*", - "symfony/dom-crawler": "3.1.*" + "symfony/css-selector": "3.2.*", + "symfony/dom-crawler": "3.2.*" }, "minimum-stability": "dev" } \ No newline at end of file -- Gitee From 7ba9c9452c7a039e372487d5a8df937e7ca639a9 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Tue, 28 Feb 2017 16:39:34 +0800 Subject: [PATCH 02/93] update framework version --- src/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.php b/src/Application.php index b6987fe3..3cc04b33 100644 --- a/src/Application.php +++ b/src/Application.php @@ -34,7 +34,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn /** * @var string */ - const VERSION = '1.0'; + const VERSION = '0.2.1'; /** * @var string -- Gitee From 1f25176b206a2c1339fa73abeecab905750d0d8d Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 12:27:24 +0800 Subject: [PATCH 03/93] update package laravel/passport version to 2.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1ea36d28..b36e08db 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "illuminate/validation": "5.4.*", "illuminate/view": "5.4.*", "jeremeamia/superclosure": "~2.2", - "laravel/passport": "^1.0", + "laravel/passport": "^2.0", "league/flysystem": "~1.0", "monolog/monolog": "~1.11", "mtdowling/cron-expression": "~1.0", -- Gitee From 4edc3d9a63335c15a557b12b94b5069d793767b7 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 12:41:21 +0800 Subject: [PATCH 04/93] remove package classpreloader/classpreloader --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index b36e08db..1ae0cb64 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,6 @@ "php": ">=7.0", "ext-mbstring": "*", "ext-openssl": "*", - "classpreloader/classpreloader": "~3.0", "doctrine/inflector": "~1.0", "erusev/parsedown": "~1.6", "illuminate/auth": "5.4.*", -- Gitee From ab07ae83e81e8ec52f7335d4d9ec1e305087eac9 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 12:42:38 +0800 Subject: [PATCH 05/93] remove code of unlink compiled file in composer scripts --- src/Composer/ComposerScripts.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Composer/ComposerScripts.php b/src/Composer/ComposerScripts.php index 39aec499..941189ef 100644 --- a/src/Composer/ComposerScripts.php +++ b/src/Composer/ComposerScripts.php @@ -47,12 +47,6 @@ class ComposerScripts */ protected static function clearCompiled() { - $laravel = new Application(getcwd()); - if (file_exists($compiledPath = $laravel->getCachedCompilePath())) { - @unlink($compiledPath); - } - if (file_exists($servicesPath = $laravel->getCachedServicesPath())) { - @unlink($servicesPath); - } + file_exists($servicesPath = (new Application(getcwd()))->getCachedCompilePath()) && @unlink($servicesPath); } } -- Gitee From 57bebf56663a56d51205c36fcdffc75d6718b8e1 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 12:54:16 +0800 Subject: [PATCH 06/93] using singleton instead of share --- src/Image/ImageServiceProvider.php | 2 +- src/Routing/RoutingServiceProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Image/ImageServiceProvider.php b/src/Image/ImageServiceProvider.php index 6826905a..ccbee6d1 100644 --- a/src/Image/ImageServiceProvider.php +++ b/src/Image/ImageServiceProvider.php @@ -51,7 +51,7 @@ class ImageServiceProvider extends ServiceProvider */ public function register() { - $this->app['image'] = $this->app->share(function () { + $this->app->singleton('images', function () { return new ImageManager($this->app['config']->get('image')); }); $this->app->alias('image', 'Notadd\Foundation\Image\ImageManager'); diff --git a/src/Routing/RoutingServiceProvider.php b/src/Routing/RoutingServiceProvider.php index da6dc857..722838ca 100644 --- a/src/Routing/RoutingServiceProvider.php +++ b/src/Routing/RoutingServiceProvider.php @@ -20,7 +20,7 @@ class RoutingServiceProvider extends IlluminateRoutingServiceProvider */ protected function registerRedirector() { - $this->app['redirect'] = $this->app->share(function ($app) { + $this->app->singleton('redirect', function ($app) { $redirector = new Redirector($app['url']); if (isset($app['session.store'])) { $redirector->setSession($app['session.store']); -- Gitee From 38327457fbaf0f4ee5c1296f958572cc601bfbd5 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 12:54:40 +0800 Subject: [PATCH 07/93] remove classes files complied logic --- src/Console/Commands/OptimizeCommand.php | 236 +---------------------- 1 file changed, 1 insertion(+), 235 deletions(-) diff --git a/src/Console/Commands/OptimizeCommand.php b/src/Console/Commands/OptimizeCommand.php index 09b00c09..8cd1f03e 100644 --- a/src/Console/Commands/OptimizeCommand.php +++ b/src/Console/Commands/OptimizeCommand.php @@ -8,8 +8,6 @@ */ namespace Notadd\Foundation\Console\Commands; -use ClassPreloader\Exceptions\VisitorExceptionInterface; -use ClassPreloader\Factory; use Illuminate\Console\Command; use Illuminate\Support\Composer; use Symfony\Component\Console\Input\InputOption; @@ -19,195 +17,6 @@ use Symfony\Component\Console\Input\InputOption; */ class OptimizeCommand extends Command { - /** - * @var array - */ - protected $complies = [ - '/vendor/illuminate/contracts/Container/Container.php', - '/vendor/illuminate/contracts/Container/ContextualBindingBuilder.php', - '/vendor/illuminate/contracts/Foundation/Application.php', - '/vendor/illuminate/contracts/Bus/Dispatcher.php', - '/vendor/illuminate/contracts/Bus/QueueingDispatcher.php', - '/vendor/illuminate/contracts/Pipeline/Pipeline.php', - '/vendor/illuminate/contracts/Support/Renderable.php', - '/vendor/illuminate/contracts/Logging/Log.php', - '/vendor/illuminate/contracts/Debug/ExceptionHandler.php', - '/vendor/illuminate/contracts/Config/Repository.php', - '/vendor/illuminate/contracts/Events/Dispatcher.php', - '/vendor/illuminate/contracts/Support/Arrayable.php', - '/vendor/illuminate/contracts/Support/Jsonable.php', - '/vendor/illuminate/contracts/Cookie/Factory.php', - '/vendor/illuminate/contracts/Cookie/QueueingFactory.php', - '/vendor/illuminate/contracts/Encryption/Encrypter.php', - '/vendor/illuminate/contracts/Queue/QueueableEntity.php', - '/vendor/illuminate/contracts/Routing/Registrar.php', - '/vendor/illuminate/contracts/Routing/ResponseFactory.php', - '/vendor/illuminate/contracts/Routing/UrlGenerator.php', - '/vendor/illuminate/contracts/Routing/UrlRoutable.php', - '/vendor/illuminate/contracts/Validation/ValidatesWhenResolved.php', - '/vendor/illuminate/contracts/View/Factory.php', - '/vendor/illuminate/contracts/Support/MessageProvider.php', - '/vendor/illuminate/contracts/Support/MessageBag.php', - '/vendor/illuminate/contracts/View/View.php', - '/vendor/illuminate/contracts/Http/Kernel.php', - '/vendor/illuminate/contracts/Auth/Guard.php', - '/vendor/illuminate/contracts/Auth/StatefulGuard.php', - '/vendor/illuminate/contracts/Auth/Access/Gate.php', - '/vendor/illuminate/contracts/Hashing/Hasher.php', - '/vendor/illuminate/auth/AuthManager.php', - '/vendor/illuminate/auth/SessionGuard.php', - '/vendor/illuminate/auth/Access/Gate.php', - '/vendor/illuminate/contracts/Auth/UserProvider.php', - '/vendor/illuminate/auth/EloquentUserProvider.php', - '/vendor/illuminate/container/Container.php', - '/vendor/symfony/http-kernel/HttpKernelInterface.php', - '/vendor/symfony/http-kernel/TerminableInterface.php', - '/src/Foundation/Application.php', - '/src/Foundation/EnvironmentDetector.php', - '/src/Foundation/Bootstrap/ConfigureLogging.php', - '/src/Foundation/Bootstrap/HandleExceptions.php', - '/src/Foundation/Bootstrap/RegisterFacades.php', - '/src/Foundation/Bootstrap/RegisterProviders.php', - '/src/Foundation/Bootstrap/BootProviders.php', - '/src/Foundation/Bootstrap/LoadConfiguration.php', - '/src/Foundation/Bootstrap/DetectEnvironment.php', - '/src/Foundation/Http/Kernel.php', - '/src/Foundation/Auth/AuthenticatesUsers.php', - '/src/Foundation/Auth/RedirectsUsers.php', - '/src/Foundation/Auth/RegistersUsers.php', - '/src/Foundation/Auth/ResetsPasswords.php', - '/vendor/illuminate/http/Request.php', - '/vendor/illuminate/http/Middleware/FrameGuard.php', - '/src/Foundation/Http/Middlewares/VerifyCsrfToken.php', - '/src/Foundation/Http/Middlewares/CheckForMaintenanceMode.php', - '/vendor/symfony/http-foundation/Request.php', - '/vendor/symfony/http-foundation/ParameterBag.php', - '/vendor/symfony/http-foundation/FileBag.php', - '/vendor/symfony/http-foundation/ServerBag.php', - '/vendor/symfony/http-foundation/HeaderBag.php', - '/vendor/symfony/http-foundation/Session/SessionInterface.php', - '/vendor/symfony/http-foundation/Session/SessionBagInterface.php', - '/vendor/symfony/http-foundation/Session/Attribute/AttributeBagInterface.php', - '/vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php', - '/vendor/symfony/http-foundation/Session/Storage/MetadataBag.php', - '/vendor/symfony/http-foundation/AcceptHeaderItem.php', - '/vendor/symfony/http-foundation/AcceptHeader.php', - '/vendor/symfony/debug/ExceptionHandler.php', - '/vendor/illuminate/support/ServiceProvider.php', - '/vendor/illuminate/support/AggregateServiceProvider.php', - '/vendor/illuminate/routing/RoutingServiceProvider.php', - '/vendor/illuminate/events/EventServiceProvider.php', - '/vendor/illuminate/validation/ValidationServiceProvider.php', - '/src/Foundation/Validation/ValidatesRequests.php', - '/vendor/illuminate/validation/ValidatesWhenResolvedTrait.php', - '/src/Foundation/Auth/Access/AuthorizesRequests.php', - '/src/Foundation/Http/FormRequest.php', - '/src/Foundation/Bus/DispatchesJobs.php', - '/vendor/illuminate/auth/AuthServiceProvider.php', - '/vendor/illuminate/pagination/PaginationServiceProvider.php', - '/vendor/illuminate/hashing/HashServiceProvider.php', - '/vendor/illuminate/hashing/BcryptHasher.php', - '/vendor/illuminate/contracts/Pagination/Paginator.php', - '/vendor/illuminate/pagination/AbstractPaginator.php', - '/vendor/illuminate/pagination/Paginator.php', - '/vendor/illuminate/support/Facades/Facade.php', - '/vendor/illuminate/support/Traits/Macroable.php', - '/vendor/illuminate/support/Arr.php', - '/vendor/illuminate/support/Str.php', - '/vendor/symfony/debug/ErrorHandler.php', - '/vendor/illuminate/config/Repository.php', - '/vendor/illuminate/support/NamespacedItemResolver.php', - '/vendor/illuminate/filesystem/Filesystem.php', - '/src/Foundation/AliasLoader.php', - '/src/Foundation/ProviderRepository.php', - '/vendor/illuminate/cookie/CookieServiceProvider.php', - '/vendor/illuminate/database/DatabaseServiceProvider.php', - '/vendor/illuminate/encryption/EncryptionServiceProvider.php', - '/vendor/illuminate/filesystem/FilesystemServiceProvider.php', - '/vendor/illuminate/session/SessionServiceProvider.php', - '/vendor/illuminate/view/ViewServiceProvider.php', - '/vendor/illuminate/routing/RouteDependencyResolverTrait.php', - '/vendor/illuminate/routing/Router.php', - '/vendor/illuminate/routing/Route.php', - '/vendor/illuminate/routing/RouteCollection.php', - '/vendor/symfony/routing/CompiledRoute.php', - '/vendor/symfony/routing/RouteCompilerInterface.php', - '/vendor/symfony/routing/RouteCompiler.php', - '/vendor/symfony/routing/Route.php', - '/vendor/illuminate/routing/Controller.php', - '/vendor/illuminate/routing/ControllerDispatcher.php', - '/vendor/illuminate/routing/UrlGenerator.php', - '/vendor/illuminate/bus/Dispatcher.php', - '/vendor/illuminate/pipeline/Pipeline.php', - '/vendor/illuminate/routing/Matching/ValidatorInterface.php', - '/vendor/illuminate/routing/Matching/HostValidator.php', - '/vendor/illuminate/routing/Matching/MethodValidator.php', - '/vendor/illuminate/routing/Matching/SchemeValidator.php', - '/vendor/illuminate/routing/Matching/UriValidator.php', - '/vendor/illuminate/routing/Middleware/SubstituteBindings.php', - '/vendor/illuminate/events/Dispatcher.php', - '/vendor/illuminate/database/Eloquent/Model.php', - '/vendor/illuminate/database/DatabaseManager.php', - '/vendor/illuminate/database/ConnectionResolverInterface.php', - '/vendor/illuminate/database/Connectors/ConnectionFactory.php', - '/vendor/illuminate/session/SessionInterface.php', - '/vendor/illuminate/session/Middleware/StartSession.php', - '/vendor/illuminate/session/Store.php', - '/vendor/illuminate/session/SessionManager.php', - '/vendor/illuminate/support/Manager.php', - '/vendor/illuminate/support/Collection.php', - '/vendor/illuminate/cookie/CookieJar.php', - '/vendor/illuminate/cookie/Middleware/EncryptCookies.php', - '/vendor/illuminate/cookie/Middleware/AddQueuedCookiesToResponse.php', - '/vendor/illuminate/encryption/Encrypter.php', - '/vendor/illuminate/support/Facades/Log.php', - '/vendor/illuminate/log/Writer.php', - '/vendor/illuminate/view/Middleware/ShareErrorsFromSession.php', - '/vendor/monolog/monolog/src/Monolog/Logger.php', - '/vendor/psr/log/Psr/Log/LoggerInterface.php', - '/vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php', - '/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php', - '/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php', - '/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php', - '/vendor/monolog/monolog/src/Monolog/Handler/HandlerInterface.php', - '/vendor/monolog/monolog/src/Monolog/Formatter/FormatterInterface.php', - '/vendor/monolog/monolog/src/Monolog/Formatter/NormalizerFormatter.php', - '/vendor/monolog/monolog/src/Monolog/Formatter/LineFormatter.php', - '/vendor/illuminate/support/Facades/App.php', - '/vendor/illuminate/support/Facades/Route.php', - '/vendor/illuminate/view/Engines/EngineResolver.php', - '/vendor/illuminate/view/ViewFinderInterface.php', - '/vendor/illuminate/view/FileViewFinder.php', - '/vendor/illuminate/view/Factory.php', - '/vendor/illuminate/support/ViewErrorBag.php', - '/vendor/illuminate/support/MessageBag.php', - '/vendor/illuminate/support/Facades/View.php', - '/vendor/illuminate/view/View.php', - '/vendor/illuminate/view/Engines/EngineInterface.php', - '/vendor/illuminate/view/Engines/PhpEngine.php', - '/vendor/illuminate/view/Engines/CompilerEngine.php', - '/vendor/illuminate/view/Compilers/CompilerInterface.php', - '/vendor/illuminate/view/Compilers/Compiler.php', - '/vendor/illuminate/view/Compilers/BladeCompiler.php', - '/vendor/symfony/http-foundation/Response.php', - '/vendor/illuminate/http/ResponseTrait.php', - '/vendor/illuminate/http/Response.php', - '/vendor/symfony/http-foundation/ResponseHeaderBag.php', - '/vendor/symfony/http-foundation/Cookie.php', - '/vendor/symfony/finder/SplFileInfo.php', - '/vendor/symfony/finder/Iterator/FilterIterator.php', - '/vendor/symfony/finder/Iterator/MultiplePcreFilterIterator.php', - '/vendor/symfony/finder/Iterator/PathFilterIterator.php', - '/vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php', - '/vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php', - '/vendor/symfony/finder/Iterator/FileTypeFilterIterator.php', - '/vendor/symfony/finder/Iterator/FilenameFilterIterator.php', - '/vendor/symfony/finder/Finder.php', - '/vendor/symfony/finder/Glob.php', - '/vendor/vlucas/phpdotenv/src/Dotenv.php', - '/vendor/nesbot/carbon/src/Carbon/Carbon.php', - ]; - /** * @var string */ @@ -245,50 +54,7 @@ class OptimizeCommand extends Command } else { $this->composer->dumpOptimized(); } - if ($this->option('force') || !$this->laravel['config']['app.debug']) { - $this->info('Compiling common classes'); - $this->compileClasses(); - $this->info('Compiled common classes'); - } else { - $this->call('clear-compiled'); - } - } - - /** - * Generate the compiled class file. - */ - protected function compileClasses() - { - $preloader = (new Factory())->create(['skip' => true]); - $handle = $preloader->prepareOutput($this->laravel->getCachedCompilePath()); - foreach ($this->getClassFiles() as $file) { - try { - fwrite($handle, $preloader->getCode($file, false) . "\n"); - } catch (VisitorExceptionInterface $e) { - } - } - fclose($handle); - } - - /** - * Get the classes that should be combined and compiled. - * - * @return array - */ - protected function getClassFiles() - { - $core = collect($this->complies)->transform(function ($value) { - return $this->laravel->basePath() . $value; - })->toArray(); - $files = array_merge($core, $this->laravel['config']->get('compile.files', [])); - foreach ($this->laravel['config']->get('compile.providers', []) as $provider) { - $files = array_merge($files, forward_static_call([ - $provider, - 'compiles', - ])); - } - - return array_map('realpath', $files); + $this->call('clear-compiled'); } /** -- Gitee From e15417ea122ae24028c166f7b504c15624649edd Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 14:11:10 +0800 Subject: [PATCH 08/93] remove providers which do not exists --- configurations/app.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/configurations/app.php b/configurations/app.php index b9954eaa..61db15c5 100644 --- a/configurations/app.php +++ b/configurations/app.php @@ -27,7 +27,6 @@ return [ Notadd\Foundation\Bus\BusServiceProvider::class, Notadd\Foundation\Cache\CacheServiceProvider::class, Notadd\Foundation\Composer\ComposerServiceProvider::class, - Illuminate\Queue\ConsoleServiceProvider::class, Illuminate\Cookie\CookieServiceProvider::class, Notadd\Foundation\Database\DatabaseServiceProvider::class, Notadd\Foundation\Debug\DebugServiceProvider::class, @@ -51,8 +50,6 @@ return [ Notadd\Foundation\Queue\QueueServiceProvider::class, Illuminate\Redis\RedisServiceProvider::class, Notadd\Foundation\Sitemap\SitemapServiceProvider::class, - Illuminate\Console\ScheduleServiceProvider::class, - Illuminate\Database\SeedServiceProvider::class, Notadd\Foundation\SearchEngine\SearchEngineServiceProvider::class, Notadd\Foundation\Session\SessionServiceProvider::class, Notadd\Foundation\Setting\SettingServiceProvider::class, -- Gitee From 0979d92802d662e4a68d2ea2bafdb50176323336 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 14:17:45 +0800 Subject: [PATCH 09/93] fix error on Container::afterResolving and Container::resolving usage --- src/Http/HttpServiceProvider.php | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/Http/HttpServiceProvider.php b/src/Http/HttpServiceProvider.php index e60a1ffc..d4b5dd62 100644 --- a/src/Http/HttpServiceProvider.php +++ b/src/Http/HttpServiceProvider.php @@ -25,26 +25,16 @@ class HttpServiceProvider extends ServiceProvider */ public function boot() { - if ($this->app->make('request')->getMethod() == 'OPTIONS') { - $this->app->make(KernelContract::class)->prependMiddleware(CrossPreflight::class); - } - $this->configureFormRequests(); - $this->loadViewsFrom(realpath(__DIR__ . '/../../resources/errors'), 'error'); - $this->loadMigrationsFrom(realpath(__DIR__ . '/../../databases/migrations')); - } - - /** - * Configure the form request related services. - */ - protected function configureFormRequests() - { - $this->app->afterResolving(function (ValidatesWhenResolved $resolved) { + $this->app->afterResolving(ValidatesWhenResolved::class, function (ValidatesWhenResolved $resolved) { $resolved->validate(); }); - $this->app->resolving(function (FormRequest $request, $app) { + $this->app->make('request')->getMethod() == 'OPTIONS' && $this->app->make(KernelContract::class)->prependMiddleware(CrossPreflight::class); + $this->app->resolving(FormRequest::class, function (FormRequest $request, $app) { $this->initializeRequest($request, $app['request']); - $request->setContainer($app)->setRedirector($app->make(Redirector::class)); + $request->setContainer($app)->setRedirector($this->app->make(Redirector::class)); }); + $this->loadViewsFrom(realpath(__DIR__ . '/../../resources/errors'), 'error'); + $this->loadMigrationsFrom(realpath(__DIR__ . '/../../databases/migrations')); } /** -- Gitee From 3c5fe6d13802827d9d23e9460bad661a014e3469 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 14:23:03 +0800 Subject: [PATCH 10/93] fix error on instance Schedule --- src/Console/Kernel.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Console/Kernel.php b/src/Console/Kernel.php index 6ea311b9..511a950c 100644 --- a/src/Console/Kernel.php +++ b/src/Console/Kernel.php @@ -12,6 +12,7 @@ use Closure; use Exception; use Illuminate\Console\Events\ArtisanStarting; use Illuminate\Console\Scheduling\Schedule; +use Illuminate\Contracts\Cache\Repository as Cache; use Illuminate\Contracts\Console\Kernel as KernelContract; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Foundation\Application; @@ -99,7 +100,7 @@ class Kernel implements KernelContract */ protected function defineConsoleSchedule() { - $this->app->instance('Illuminate\Console\Scheduling\Schedule', $schedule = new Schedule()); + $this->app->instance(Schedule::class, $schedule = new Schedule($this->app[Cache::class])); $this->schedule($schedule); } -- Gitee From 517638a110d972733390adec4ccb1c35e93d3d5a Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 15:07:16 +0800 Subject: [PATCH 11/93] bootstrap class rename to LoadEnvironmentVariables --- configurations/app.php | 1 - src/Application.php | 6 ++++-- .../{DetectEnvironment.php => LoadEnvironmentVariables.php} | 2 +- src/Console/Kernel.php | 4 ++-- src/Http/Kernel.php | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) rename src/Bootstrap/{DetectEnvironment.php => LoadEnvironmentVariables.php} (98%) diff --git a/configurations/app.php b/configurations/app.php index 61db15c5..70bf2689 100644 --- a/configurations/app.php +++ b/configurations/app.php @@ -33,7 +33,6 @@ return [ Notadd\Foundation\Editor\EditorServiceProvider::class, Illuminate\Encryption\EncryptionServiceProvider::class, Notadd\Foundation\Extension\ExtensionServiceProvider::class, - Illuminate\Filesystem\FilesystemServiceProvider::class, Illuminate\Hashing\HashServiceProvider::class, Notadd\Installer\InstallerServiceProvider::class, Notadd\Foundation\Image\ImageServiceProvider::class, diff --git a/src/Application.php b/src/Application.php index 3cc04b33..782cf56e 100644 --- a/src/Application.php +++ b/src/Application.php @@ -12,12 +12,13 @@ use Closure; use Illuminate\Container\Container; use Illuminate\Contracts\Foundation\Application as ApplicationContract; use Illuminate\Filesystem\Filesystem; +use Illuminate\Filesystem\FilesystemServiceProvider; use Illuminate\Http\Request; use Illuminate\Support\Arr; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; use Illuminate\View\ViewServiceProvider; -use Notadd\Foundation\Bootstrap\DetectEnvironment; +use Notadd\Foundation\Bootstrap\LoadEnvironmentVariables; use Notadd\Foundation\Event\EventServiceProvider; use Notadd\Foundation\Routing\RoutingServiceProvider; use RuntimeException; @@ -160,6 +161,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn protected function registerBaseServiceProviders() { $this->register(new EventServiceProvider($this)); + $this->register(new FilesystemServiceProvider($this)); $this->register(new RoutingServiceProvider($this)); $this->register(new ViewServiceProvider($this)); } @@ -188,7 +190,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn */ public function afterLoadingEnvironment(Closure $callback) { - return $this->afterBootstrapping(DetectEnvironment::class, $callback); + return $this->afterBootstrapping(LoadEnvironmentVariables::class, $callback); } /** diff --git a/src/Bootstrap/DetectEnvironment.php b/src/Bootstrap/LoadEnvironmentVariables.php similarity index 98% rename from src/Bootstrap/DetectEnvironment.php rename to src/Bootstrap/LoadEnvironmentVariables.php index 1fee8cf9..cd6091ee 100644 --- a/src/Bootstrap/DetectEnvironment.php +++ b/src/Bootstrap/LoadEnvironmentVariables.php @@ -16,7 +16,7 @@ use Symfony\Component\Console\Input\ArgvInput; /** * Class DetectEnvironment. */ -class DetectEnvironment +class LoadEnvironmentVariables { /** * Bootstrap the given application. diff --git a/src/Console/Kernel.php b/src/Console/Kernel.php index 511a950c..30a42abd 100644 --- a/src/Console/Kernel.php +++ b/src/Console/Kernel.php @@ -18,7 +18,7 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Foundation\Application; use Notadd\Foundation\Bootstrap\LoadProviders; use Notadd\Foundation\Bootstrap\ConfigureLogging; -use Notadd\Foundation\Bootstrap\DetectEnvironment; +use Notadd\Foundation\Bootstrap\LoadEnvironmentVariables; use Notadd\Foundation\Bootstrap\HandleExceptions; use Notadd\Foundation\Bootstrap\LoadConfiguration; use Notadd\Foundation\Bootstrap\LoadSetting; @@ -66,7 +66,7 @@ class Kernel implements KernelContract * @var array */ protected $bootstrappers = [ - DetectEnvironment::class, + LoadEnvironmentVariables::class, LoadConfiguration::class, ConfigureLogging::class, HandleExceptions::class, diff --git a/src/Http/Kernel.php b/src/Http/Kernel.php index 425b50ba..52282208 100644 --- a/src/Http/Kernel.php +++ b/src/Http/Kernel.php @@ -28,7 +28,7 @@ use Laravel\Passport\Http\Middleware\CheckForAnyScope; use Laravel\Passport\Http\Middleware\CheckScopes; use Notadd\Foundation\Bootstrap\LoadProviders; use Notadd\Foundation\Bootstrap\ConfigureLogging; -use Notadd\Foundation\Bootstrap\DetectEnvironment; +use Notadd\Foundation\Bootstrap\LoadEnvironmentVariables; use Notadd\Foundation\Bootstrap\HandleExceptions; use Notadd\Foundation\Bootstrap\LoadConfiguration; use Notadd\Foundation\Bootstrap\LoadSetting; @@ -61,7 +61,7 @@ class Kernel implements KernelContract * @var array */ protected $bootstrappers = [ - DetectEnvironment::class, + LoadEnvironmentVariables::class, LoadConfiguration::class, ConfigureLogging::class, HandleExceptions::class, -- Gitee From 0d22cc8b6e4307ef43b5ef6385e9b654ead5ffb7 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 15:12:53 +0800 Subject: [PATCH 12/93] use method alias instead of bind --- src/Member/MemberServiceProvider.php | 2 +- src/Testing/Concerns/MocksApplicationServices.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Member/MemberServiceProvider.php b/src/Member/MemberServiceProvider.php index 144600fe..2f57a9d4 100644 --- a/src/Member/MemberServiceProvider.php +++ b/src/Member/MemberServiceProvider.php @@ -54,7 +54,7 @@ class MemberServiceProvider extends ServiceProvider public function registerPermission() { - $this->app->bind('permission', function ($app) { + $this->app->alias('permission', function ($app) { return new PermissionManager; }); } diff --git a/src/Testing/Concerns/MocksApplicationServices.php b/src/Testing/Concerns/MocksApplicationServices.php index 6868af4d..d7027080 100644 --- a/src/Testing/Concerns/MocksApplicationServices.php +++ b/src/Testing/Concerns/MocksApplicationServices.php @@ -206,7 +206,7 @@ trait MocksApplicationServices { $observers = is_array($observers) ? $observers : [$observers]; array_map(function ($observer) { - $this->app->bind($observer, function () use ($observer) { + $this->app->alias($observer, function () use ($observer) { return $this->getMockBuilder($observer)->disableOriginalConstructor()->getMock(); }); }, $observers); -- Gitee From 412448f1aac237476f6263611e960bbbaad2d0e9 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 15:21:23 +0800 Subject: [PATCH 13/93] use method dispatch instead of fire --- src/Application.php | 8 ++++---- src/helpers.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Application.php b/src/Application.php index 782cf56e..b6f2a19a 100644 --- a/src/Application.php +++ b/src/Application.php @@ -177,9 +177,9 @@ class Application extends Container implements ApplicationContract, HttpKernelIn { $this->hasBeenBootstrapped = true; foreach ($bootstrappers as $bootstrapper) { - $this['events']->fire('bootstrapping: ' . $bootstrapper, [$this]); + $this['events']->dispatch('bootstrapping: ' . $bootstrapper, [$this]); $this->make($bootstrapper)->bootstrap($this); - $this['events']->fire('bootstrapped: ' . $bootstrapper, [$this]); + $this['events']->dispatch('bootstrapped: ' . $bootstrapper, [$this]); } } @@ -606,7 +606,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn */ protected function markAsRegistered($provider) { - $this['events']->fire($class = get_class($provider), [$provider]); + $this['events']->dispatch($class = get_class($provider), [$provider]); $this->serviceProviders[] = $provider; $this->loadedProviders[$class] = true; } @@ -1016,7 +1016,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn { $this['config']->set('app.locale', $locale); $this['translator']->setLocale($locale); - $this['events']->fire('locale.changed', [$locale]); + $this['events']->dispatch('locale.changed', [$locale]); } /** diff --git a/src/helpers.php b/src/helpers.php index c7686c24..a3bb83b2 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -499,7 +499,7 @@ if (!function_exists('event')) { */ function event(...$args) { - return app('events')->fire(...$args); + return app('events')->dispatch(...$args); } } -- Gitee From 0ae52e7cd24c680bb2a5ad694ba498236545851d Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 15:25:39 +0800 Subject: [PATCH 14/93] rename event kernel.handled to RequestHandled --- src/Http/Events/RequestHandled.php | 41 ++++++++++++++++++++++++++ src/Http/Kernel.php | 3 +- src/Sitemap/SitemapServiceProvider.php | 3 +- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/Http/Events/RequestHandled.php diff --git a/src/Http/Events/RequestHandled.php b/src/Http/Events/RequestHandled.php new file mode 100644 index 00000000..47a2e378 --- /dev/null +++ b/src/Http/Events/RequestHandled.php @@ -0,0 +1,41 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-01 15:23 + */ +namespace Notadd\Foundation\Http\Events; + +/** + * Class RequestHandled. + */ +class RequestHandled +{ + /** + * The request instance. + * + * @var \Illuminate\Http\Request + */ + public $request; + + /** + * The response instance. + * + * @var \Illuminate\Http\Response + */ + public $response; + + /** + * Create a new event instance. + * + * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Response $response + */ + public function __construct($request, $response) + { + $this->request = $request; + $this->response = $response; + } +} diff --git a/src/Http/Kernel.php b/src/Http/Kernel.php index 52282208..8fa5a176 100644 --- a/src/Http/Kernel.php +++ b/src/Http/Kernel.php @@ -34,6 +34,7 @@ use Notadd\Foundation\Bootstrap\LoadConfiguration; use Notadd\Foundation\Bootstrap\LoadSetting; use Notadd\Foundation\Bootstrap\RegisterFacades; use Notadd\Foundation\Bootstrap\RegisterRouter; +use Notadd\Foundation\Http\Events\RequestHandled; use Notadd\Foundation\Http\Middlewares\CheckForMaintenanceMode; use Notadd\Foundation\Http\Middlewares\EnableCrossRequest; use Notadd\Foundation\Http\Middlewares\RedirectIfAuthenticated; @@ -161,7 +162,7 @@ class Kernel implements KernelContract $this->reportException($e = new FatalThrowableError($e)); $response = $this->renderException($request, $e); } - $this->application['events']->fire('kernel.handled', [ + $this->application['events']->dispatch(RequestHandled::class, [ $request, $response, ]); diff --git a/src/Sitemap/SitemapServiceProvider.php b/src/Sitemap/SitemapServiceProvider.php index 34dd5697..57676fbb 100644 --- a/src/Sitemap/SitemapServiceProvider.php +++ b/src/Sitemap/SitemapServiceProvider.php @@ -11,6 +11,7 @@ namespace Notadd\Foundation\Sitemap; use Illuminate\Events\Dispatcher; use Illuminate\Support\ServiceProvider; use Notadd\Content\Models\Article; +use Notadd\Foundation\Http\Events\RequestHandled; use Notadd\Foundation\Setting\Contracts\SettingsRepository; use Notadd\Foundation\Sitemap\Listeners\CsrfTokenRegister; use Notadd\Foundation\Sitemap\Listeners\RouteRegistrar; @@ -23,7 +24,7 @@ class SitemapServiceProvider extends ServiceProvider public function boot() { $this->loadViewsFrom(realpath(__DIR__ . '/../../resources/views/sitemap'), 'sitemap'); - $this->app->make(Dispatcher::class)->listen('kernel.handled', function () { + $this->app->make(Dispatcher::class)->listen(RequestHandled::class, function () { if ($this->app->isInstalled()) { $setting = $this->app->make(SettingsRepository::class); if ($setting->get('sitemap.recently', true)) { -- Gitee From dc4c21764340cd66b3b4da81889dd2ad61831595 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 15:30:01 +0800 Subject: [PATCH 15/93] rename event locale.changed to LocaleUpdated --- configurations/app.php | 2 +- src/Application.php | 3 +- src/Translation/Events/LocaleUpdated.php | 32 +++++++++++++++++++ .../TranslationServiceProvider.php | 18 +++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/Translation/Events/LocaleUpdated.php create mode 100644 src/Translation/TranslationServiceProvider.php diff --git a/configurations/app.php b/configurations/app.php index 70bf2689..9191691b 100644 --- a/configurations/app.php +++ b/configurations/app.php @@ -53,7 +53,7 @@ return [ Notadd\Foundation\Session\SessionServiceProvider::class, Notadd\Foundation\Setting\SettingServiceProvider::class, Notadd\Foundation\Theme\ThemeServiceProvider::class, - Illuminate\Translation\TranslationServiceProvider::class, + Notadd\Foundation\Translation\TranslationServiceProvider::class, Notadd\Foundation\Validation\ValidationServiceProvider::class, Notadd\Foundation\Http\HttpServiceProvider::class, Notadd\Foundation\Administration\AdministrationServiceProvider::class, diff --git a/src/Application.php b/src/Application.php index b6f2a19a..c922fb32 100644 --- a/src/Application.php +++ b/src/Application.php @@ -21,6 +21,7 @@ use Illuminate\View\ViewServiceProvider; use Notadd\Foundation\Bootstrap\LoadEnvironmentVariables; use Notadd\Foundation\Event\EventServiceProvider; use Notadd\Foundation\Routing\RoutingServiceProvider; +use Notadd\Foundation\Translation\Events\LocaleUpdated; use RuntimeException; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -1016,7 +1017,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn { $this['config']->set('app.locale', $locale); $this['translator']->setLocale($locale); - $this['events']->dispatch('locale.changed', [$locale]); + $this['events']->dispatch(LocaleUpdated::class, [$locale]); } /** diff --git a/src/Translation/Events/LocaleUpdated.php b/src/Translation/Events/LocaleUpdated.php new file mode 100644 index 00000000..10ffa4c8 --- /dev/null +++ b/src/Translation/Events/LocaleUpdated.php @@ -0,0 +1,32 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-01 15:29 + */ +namespace Notadd\Foundation\Translation\Events; + +/** + * Class LocaleUpdated. + */ +class LocaleUpdated +{ + /** + * The new locale. + * + * @var string + */ + public $locale; + + /** + * Create a new event instance. + * + * @param string $locale + */ + public function __construct($locale) + { + $this->locale = $locale; + } +} diff --git a/src/Translation/TranslationServiceProvider.php b/src/Translation/TranslationServiceProvider.php new file mode 100644 index 00000000..2f45094a --- /dev/null +++ b/src/Translation/TranslationServiceProvider.php @@ -0,0 +1,18 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-01 15:27 + */ +namespace Notadd\Foundation\Translation; + +use Illuminate\Translation\TranslationServiceProvider as IlluminateTranslationServiceProvider; + +/** + * Class TranslationServiceProvider. + */ +class TranslationServiceProvider extends IlluminateTranslationServiceProvider +{ +} -- Gitee From 15002edfb03ceb0cbfe962ed4bb5bef078b063da Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 15:34:07 +0800 Subject: [PATCH 16/93] rename class VerifyPostSize to ValidatePostSize --- .../{VerifyPostSize.php => ValidatePostSize.php} | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) rename src/Http/Middlewares/{VerifyPostSize.php => ValidatePostSize.php} (79%) diff --git a/src/Http/Middlewares/VerifyPostSize.php b/src/Http/Middlewares/ValidatePostSize.php similarity index 79% rename from src/Http/Middlewares/VerifyPostSize.php rename to src/Http/Middlewares/ValidatePostSize.php index 093b3a43..9080ba48 100644 --- a/src/Http/Middlewares/VerifyPostSize.php +++ b/src/Http/Middlewares/ValidatePostSize.php @@ -9,12 +9,12 @@ namespace Notadd\Foundation\Http\Middlewares; use Closure; -use Illuminate\Http\Exception\PostTooLargeException; +use Illuminate\Http\Exceptions\PostTooLargeException; /** * Class VerifyPostSize. */ -class VerifyPostSize +class ValidatePostSize { /** * Middleware handler. @@ -22,13 +22,15 @@ class VerifyPostSize * @param \Illuminate\Http\Request $request * @param \Closure $next * - * @throws \Illuminate\Http\Exception\PostTooLargeException + * @throws \Illuminate\Http\Exceptions\PostTooLargeException * @return mixed */ public function handle($request, Closure $next) { - if ($request->server('CONTENT_LENGTH') > $this->getPostMaxSize()) { - throw new PostTooLargeException(); + $max = $this->getPostMaxSize(); + + if ($max > 0 && $request->server('CONTENT_LENGTH') > $max) { + throw new PostTooLargeException; } return $next($request); -- Gitee From fcc9a3231d3534cca7d321667b8853ba6900ff58 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 15:36:36 +0800 Subject: [PATCH 17/93] use aliasMiddleware instead of middleware on router instance --- src/Http/Kernel.php | 2 +- src/Member/MemberServiceProvider.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Http/Kernel.php b/src/Http/Kernel.php index 8fa5a176..7dbda74d 100644 --- a/src/Http/Kernel.php +++ b/src/Http/Kernel.php @@ -139,7 +139,7 @@ class Kernel implements KernelContract $router->middlewareGroup($key, $middleware); } foreach ($this->routeMiddleware as $key => $middleware) { - $router->middleware($key, $middleware); + $router->aliasMiddleware($key, $middleware); } } diff --git a/src/Member/MemberServiceProvider.php b/src/Member/MemberServiceProvider.php index 2f57a9d4..8cb3f36a 100644 --- a/src/Member/MemberServiceProvider.php +++ b/src/Member/MemberServiceProvider.php @@ -41,8 +41,8 @@ class MemberServiceProvider extends ServiceProvider public function registerMiddleware() { - $this->app['router']->middleware('permission', Permission::class); - $this->app['router']->middleware('admin-permission', AdminPermission::class); + $this->app['router']->aliasMiddleware('permission', Permission::class); + $this->app['router']->aliasMiddleware('admin-permission', AdminPermission::class); } public function registerCommands() -- Gitee From 5795835528f59e1f702db95fe558e6575ca988d4 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 15:42:06 +0800 Subject: [PATCH 18/93] use method token instead of getToken --- src/helpers.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helpers.php b/src/helpers.php index a3bb83b2..43f3f19b 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -335,6 +335,7 @@ if (!function_exists('csrf_field')) { * Generate a CSRF token form field. * * @return \Illuminate\Support\HtmlString + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ function csrf_field() { @@ -353,7 +354,7 @@ if (!function_exists('csrf_token')) { { $session = app('session'); if (isset($session)) { - return $session->getToken(); + return $session->token(); } throw new RuntimeException('Application session store not set.'); } -- Gitee From 21a0e251bfe8123c9f23d0f618a2203f6690fea1 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 15:52:57 +0800 Subject: [PATCH 19/93] fix error on instance permission --- src/Member/MemberServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Member/MemberServiceProvider.php b/src/Member/MemberServiceProvider.php index 8cb3f36a..1ee02fa0 100644 --- a/src/Member/MemberServiceProvider.php +++ b/src/Member/MemberServiceProvider.php @@ -54,7 +54,7 @@ class MemberServiceProvider extends ServiceProvider public function registerPermission() { - $this->app->alias('permission', function ($app) { + $this->app->instance('permission', function ($app) { return new PermissionManager; }); } -- Gitee From 79dd78e4e2e575b7a8a855286edff08940c396ab Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 16:13:27 +0800 Subject: [PATCH 20/93] register migration commands on ArtisanServiceProvider --- src/Console/ArtisanServiceProvider.php | 141 +++++++++++++++++----- src/Console/Commands/TinkerCommand.php | 104 ---------------- src/Database/MigrationServiceProvider.php | 11 -- 3 files changed, 114 insertions(+), 142 deletions(-) delete mode 100644 src/Console/Commands/TinkerCommand.php diff --git a/src/Console/ArtisanServiceProvider.php b/src/Console/ArtisanServiceProvider.php index 8b8e7721..1c77ab99 100644 --- a/src/Console/ArtisanServiceProvider.php +++ b/src/Console/ArtisanServiceProvider.php @@ -10,6 +10,13 @@ namespace Notadd\Foundation\Console; use Illuminate\Auth\Console\ClearResetsCommand; use Illuminate\Auth\Console\MakeAuthCommand; +use Illuminate\Database\Console\Migrations\MigrateCommand; +use Illuminate\Database\Console\Migrations\MigrateMakeCommand; +use Illuminate\Database\Console\Migrations\ResetCommand as MigrateResetCommand; +use Illuminate\Database\Console\Migrations\StatusCommand as MigrateStatusCommand; +use Illuminate\Database\Console\Migrations\InstallCommand as MigrateInstallCommand; +use Illuminate\Database\Console\Migrations\RefreshCommand as MigrateRefreshCommand; +use Illuminate\Database\Console\Migrations\RollbackCommand as MigrateRollbackCommand; use Illuminate\Queue\Console\FailedTableCommand; use Illuminate\Queue\Console\TableCommand; use Illuminate\Support\ServiceProvider; @@ -24,7 +31,6 @@ use Notadd\Foundation\Console\Commands\EnvironmentCommand; use Notadd\Foundation\Console\Commands\EventGenerateCommand; use Notadd\Foundation\Console\Commands\StorageLinkCommand; use Notadd\Foundation\Console\Commands\TestMakeCommand; -use Notadd\Foundation\Console\Commands\TinkerCommand; use Notadd\Foundation\Console\Commands\VendorPublishCommand; use Notadd\Foundation\Database\Commands\ModelMakeCommand; use Notadd\Foundation\Database\Commands\SeederMakeCommand; @@ -56,28 +62,32 @@ class ArtisanServiceProvider extends ServiceProvider * @var array */ protected $commands = [ - 'ClearCompiled' => 'command.clear-compiled', - 'ClearResets' => 'command.auth.resets.clear', - 'ConfigCache' => 'command.config.cache', - 'ConfigClear' => 'command.config.clear', - 'Down' => 'command.down', - 'Environment' => 'command.environment', - 'KeyGenerate' => 'command.key.generate', - 'Optimize' => 'command.optimize', - 'RouteCache' => 'command.route.cache', - 'RouteClear' => 'command.route.clear', - 'RouteList' => 'command.route.list', - 'StorageLink' => 'command.storage.link', - 'Tinker' => 'command.tinker', - 'Up' => 'command.up', - 'ViewClear' => 'command.view.clear', + 'ClearCompiled' => 'command.clear-compiled', + 'ClearResets' => 'command.auth.resets.clear', + 'ConfigCache' => 'command.config.cache', + 'ConfigClear' => 'command.config.clear', + 'Down' => 'command.down', + 'Environment' => 'command.environment', + 'KeyGenerate' => 'command.key.generate', + 'Migrate' => 'command.migrate', + 'MigrateInstall' => 'command.migrate.install', + 'MigrateRefresh' => 'command.migrate.refresh', + 'MigrateReset' => 'command.migrate.reset', + 'MigrateRollback' => 'command.migrate.rollback', + 'MigrateStatus' => 'command.migrate.status', + 'Optimize' => 'command.optimize', + 'RouteCache' => 'command.route.cache', + 'RouteClear' => 'command.route.clear', + 'RouteList' => 'command.route.list', + 'StorageLink' => 'command.storage.link', + 'Up' => 'command.up', + 'ViewClear' => 'command.view.clear', ]; /** * @var array */ protected $devCommands = [ - //'AppName' => 'command.app.name', 'AuthMake' => 'command.auth.make', 'CacheTable' => 'command.cache.table', 'ConsoleMake' => 'command.console.make', @@ -308,6 +318,93 @@ class ArtisanServiceProvider extends ServiceProvider }); } + /** + * Register the command. + * + * @return void + */ + protected function registerMigrateCommand() + { + $this->app->singleton('command.migrate', function ($app) { + return new MigrateCommand($app['migrator']); + }); + } + + /** + * Register the command. + * + * @return void + */ + protected function registerMigrateInstallCommand() + { + $this->app->singleton('command.migrate.install', function ($app) { + return new MigrateInstallCommand($app['migration.repository']); + }); + } + + /** + * Register the command. + * + * @return void + */ + protected function registerMigrateMakeCommand() + { + $this->app->singleton('command.migrate.make', function ($app) { + $creator = $app['migration.creator']; + $composer = $app['composer']; + + return new MigrateMakeCommand($creator, $composer); + }); + } + + /** + * Register the command. + * + * @return void + */ + protected function registerMigrateRefreshCommand() + { + $this->app->singleton('command.migrate.refresh', function () { + return new MigrateRefreshCommand; + }); + } + + /** + * Register the command. + * + * @return void + */ + protected function registerMigrateResetCommand() + { + $this->app->singleton('command.migrate.reset', function ($app) { + return new MigrateResetCommand($app['migrator']); + }); + } + + /** + * Register the command. + * + * @return void + */ + protected function registerMigrateRollbackCommand() + { + $this->app->singleton('command.migrate.rollback', function ($app) { + return new MigrateRollbackCommand($app['migrator']); + }); + } + + /** + * Register the command. + * + * @return void + */ + protected function registerMigrateStatusCommand() + { + $this->app->singleton('command.migrate.status', function ($app) { + return new MigrateStatusCommand($app['migrator']); + }); + } + /** * Register the command. */ @@ -448,16 +545,6 @@ class ArtisanServiceProvider extends ServiceProvider }); } - /** - * Register the command. - */ - protected function registerTinkerCommand() - { - $this->app->singleton('command.tinker', function () { - return new TinkerCommand(); - }); - } - /** * Register the command. */ diff --git a/src/Console/Commands/TinkerCommand.php b/src/Console/Commands/TinkerCommand.php deleted file mode 100644 index 5c419e92..00000000 --- a/src/Console/Commands/TinkerCommand.php +++ /dev/null @@ -1,104 +0,0 @@ - - * @copyright (c) 2016, iBenchu.org - * @datetime 2016-10-21 12:23 - */ -namespace Notadd\Foundation\Console\Commands; - -use Illuminate\Console\Command; -use Psy\Configuration; -use Psy\Shell; -use Symfony\Component\Console\Input\InputArgument; - -/** - * Class TinkerCommand. - */ -class TinkerCommand extends Command -{ - /** - * @var array - */ - protected $commandWhitelist = [ - 'clear-compiled', - 'down', - 'env', - 'inspire', - 'migrate', - 'optimize', - 'up', - ]; - - /** - * @var string - */ - protected $name = 'tinker'; - - /** - * @var string - */ - protected $description = 'Interact with your application'; - - /** - * Command handler. - */ - public function fire() - { - $this->getApplication()->setCatchExceptions(false); - $config = new Configuration(); - $config->getPresenter()->addCasters($this->getCasters()); - $shell = new Shell($config); - $shell->addCommands($this->getCommands()); - $shell->setIncludes($this->argument('include')); - $shell->run(); - } - - /** - * Get artisan commands to pass through to PsySH. - * - * @return array - */ - protected function getCommands() - { - $commands = []; - foreach ($this->getApplication()->all() as $name => $command) { - if (in_array($name, $this->commandWhitelist)) { - $commands[] = $command; - } - } - - return $commands; - } - - /** - * Get an array of Laravel tailored casters. - * - * @return array - */ - protected function getCasters() - { - return [ - 'Notadd\Foundation\Application' => 'Notadd\Foundation\Console\IlluminateCaster::castApplication', - 'Illuminate\Support\Collection' => 'Notadd\Foundation\Console\IlluminateCaster::castCollection', - 'Illuminate\Database\Eloquent\Model' => 'Notadd\Foundation\Console\IlluminateCaster::castModel', - ]; - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - [ - 'include', - InputArgument::IS_ARRAY, - 'Include file(s) before starting tinker', - ], - ]; - } -} diff --git a/src/Database/MigrationServiceProvider.php b/src/Database/MigrationServiceProvider.php index ebd2d6e1..8982461a 100644 --- a/src/Database/MigrationServiceProvider.php +++ b/src/Database/MigrationServiceProvider.php @@ -8,7 +8,6 @@ */ namespace Notadd\Foundation\Database; -use Illuminate\Database\Console\Migrations\MigrateCommand; use Illuminate\Database\MigrationServiceProvider as IlluminateMigrationServiceProvider; use Notadd\Foundation\Database\Migrations\MigrationCreator; use Notadd\Foundation\Database\Migrations\Migrator; @@ -28,16 +27,6 @@ class MigrationServiceProvider extends IlluminateMigrationServiceProvider }); } - /** - * Register the "migrate" migration command. - */ - protected function registerMigrateCommand() - { - $this->app->singleton('command.migrate', function ($app) { - return new MigrateCommand($app['migrator']); - }); - } - /** * Register the migrator service. */ -- Gitee From 390eefda9146d994f48ed6820e3ee560c0a737ce Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 16:16:40 +0800 Subject: [PATCH 21/93] using correct method to register permission instance --- src/Member/MemberServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Member/MemberServiceProvider.php b/src/Member/MemberServiceProvider.php index 1ee02fa0..ef4cf938 100644 --- a/src/Member/MemberServiceProvider.php +++ b/src/Member/MemberServiceProvider.php @@ -54,7 +54,7 @@ class MemberServiceProvider extends ServiceProvider public function registerPermission() { - $this->app->instance('permission', function ($app) { + $this->app->singleton('permission', function ($app) { return new PermissionManager; }); } -- Gitee From 9fe483a888b7cfd080a79e652fc3342e75dd8aa9 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 17:24:43 +0800 Subject: [PATCH 22/93] rename service provider --- configurations/app.php | 2 +- .../{ArtisanServiceProvider.php => ConsoleServiceProvider.php} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/Console/{ArtisanServiceProvider.php => ConsoleServiceProvider.php} (99%) diff --git a/configurations/app.php b/configurations/app.php index 9191691b..32b1ccf2 100644 --- a/configurations/app.php +++ b/configurations/app.php @@ -20,13 +20,13 @@ return [ 'log' => env('APP_LOG', 'daily'), 'log_level' => env('APP_LOG_LEVEL', 'debug'), 'providers' => [ - Notadd\Foundation\Console\ArtisanServiceProvider::class, Notadd\Foundation\Attachment\AttachmentServiceProvider::class, Notadd\Foundation\Auth\AuthServiceProvider::class, Illuminate\Broadcasting\BroadcastServiceProvider::class, Notadd\Foundation\Bus\BusServiceProvider::class, Notadd\Foundation\Cache\CacheServiceProvider::class, Notadd\Foundation\Composer\ComposerServiceProvider::class, + Notadd\Foundation\Console\ConsoleServiceProvider::class, Illuminate\Cookie\CookieServiceProvider::class, Notadd\Foundation\Database\DatabaseServiceProvider::class, Notadd\Foundation\Debug\DebugServiceProvider::class, diff --git a/src/Console/ArtisanServiceProvider.php b/src/Console/ConsoleServiceProvider.php similarity index 99% rename from src/Console/ArtisanServiceProvider.php rename to src/Console/ConsoleServiceProvider.php index 1c77ab99..311755ee 100644 --- a/src/Console/ArtisanServiceProvider.php +++ b/src/Console/ConsoleServiceProvider.php @@ -51,7 +51,7 @@ use Notadd\Foundation\Session\Commands\SessionTableCommand; /** * Class ArtisanServiceProvider. */ -class ArtisanServiceProvider extends ServiceProvider +class ConsoleServiceProvider extends ServiceProvider { /** * @var bool -- Gitee From ba7f890f31a16ae4876104474338d27ded07d9cc Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 1 Mar 2017 17:30:48 +0800 Subject: [PATCH 23/93] fix parameters error --- src/Console/Application.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Console/Application.php b/src/Console/Application.php index 3e5ce1d1..e269f57e 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -48,14 +48,16 @@ class Application extends IlluminateApplication implements ApplicationContract * * @param string $command * @param array $parameters + * @param null $outputBuffer * * @return int * @throws \Exception + * @throws \Throwable */ - public function call($command, array $parameters = []) + public function call($command, array $parameters = [], $outputBuffer = null) { $parameters = collect($parameters)->prepend($command); - $this->lastOutput = new BufferedOutput(); + $this->lastOutput = $outputBuffer ?: new BufferedOutput(); $this->setCatchExceptions(false); $result = $this->run(new ArrayInput($parameters->toArray()), $this->lastOutput); $this->setCatchExceptions(true); -- Gitee From 12a5bc77c3a4f51d6f64a22c29e62780c63cb8b1 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 14:24:11 +0800 Subject: [PATCH 24/93] refactor method registerCoreContainerAliases --- src/Application.php | 140 ++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 75 deletions(-) diff --git a/src/Application.php b/src/Application.php index c922fb32..2bc02e57 100644 --- a/src/Application.php +++ b/src/Application.php @@ -1038,124 +1038,114 @@ class Application extends Container implements ApplicationContract, HttpKernelIn public function registerCoreContainerAliases() { $aliases = [ - 'administration' => ['Notadd\Foundation\Administration\Administration'], + 'administration' => [\Notadd\Foundation\Administration\Administration::class], 'app' => [ - 'Illuminate\Contracts\Container\Container', - 'Illuminate\Contracts\Foundation\Application', - 'Notadd\Foundation\Application', + \Illuminate\Contracts\Container\Container::class, + \Illuminate\Contracts\Foundation\Application::class, + \Notadd\Foundation\Application::class, ], 'auth' => [ - 'Illuminate\Auth\AuthManager', - 'Illuminate\Contracts\Auth\Factory', + \Illuminate\Auth\AuthManager::class, + \Illuminate\Contracts\Auth\Factory::class, ], - 'auth.driver' => ['Illuminate\Contracts\Auth\Guard'], - 'auth.password' => [ - 'Illuminate\Auth\Passwords\PasswordBrokerManager', - 'Illuminate\Contracts\Auth\PasswordBrokerFactory', - ], - 'auth.password.broker' => [ - 'Illuminate\Auth\Passwords\PasswordBroker', - 'Illuminate\Contracts\Auth\PasswordBroker', - ], - 'blade.compiler' => ['Illuminate\View\Compilers\BladeCompiler'], + 'blade.compiler' => [\Illuminate\View\Compilers\BladeCompiler::class], 'cache' => [ - 'Illuminate\Cache\CacheManager', - 'Illuminate\Contracts\Cache\Factory', + \Illuminate\Cache\CacheManager::class, + \Illuminate\Contracts\Cache\Factory::class, ], 'cache.store' => [ - 'Illuminate\Cache\Repository', - 'Illuminate\Contracts\Cache\Repository', + \Illuminate\Cache\Repository::class, + \Illuminate\Contracts\Cache\Repository::class, ], - 'composer' => ['Illuminate\Support\Composer'], 'config' => [ - 'Illuminate\Contracts\Config\Repository', - 'Notadd\Foundation\Configuration\Repository', + \Illuminate\Contracts\Config\Repository::class, + \Notadd\Foundation\Configuration\Repository::class, ], 'cookie' => [ - 'Illuminate\Cookie\CookieJar', - 'Illuminate\Contracts\Cookie\Factory', - 'Illuminate\Contracts\Cookie\QueueingFactory', + \Illuminate\Cookie\CookieJar::class, + \Illuminate\Contracts\Cookie\Factory::class, + \Illuminate\Contracts\Cookie\QueueingFactory::class, ], 'encrypter' => [ - 'Illuminate\Encryption\Encrypter', - 'Illuminate\Contracts\Encryption\Encrypter', + \Illuminate\Encryption\Encrypter::class, + \Illuminate\Contracts\Encryption\Encrypter::class, ], - 'db' => ['Illuminate\Database\DatabaseManager'], + 'db' => [\Illuminate\Database\DatabaseManager::class], 'db.connection' => [ - 'Illuminate\Database\Connection', - 'Illuminate\Database\ConnectionInterface', + \Illuminate\Database\Connection::class, + \Illuminate\Database\ConnectionInterface::class, ], - 'extension' => ['Notadd\Foundation\Extension\ExtensionManager'], + 'extension' => [\Notadd\Foundation\Extension\ExtensionManager::class], 'events' => [ - 'Illuminate\Events\Dispatcher', - 'Illuminate\Contracts\Events\Dispatcher', + \Illuminate\Events\Dispatcher::class, + \Illuminate\Contracts\Events\Dispatcher::class, ], - 'files' => ['Illuminate\Filesystem\Filesystem'], + 'files' => [\Illuminate\Filesystem\Filesystem::class], 'filesystem' => [ - 'Illuminate\Filesystem\FilesystemManager', - 'Illuminate\Contracts\Filesystem\Factory', + \Illuminate\Filesystem\FilesystemManager::class, + \Illuminate\Contracts\Filesystem\Factory::class, ], - 'filesystem.disk' => ['Illuminate\Contracts\Filesystem\Filesystem'], - 'filesystem.cloud' => ['Illuminate\Contracts\Filesystem\Cloud'], - 'hash' => ['Illuminate\Contracts\Hashing\Hasher'], + 'filesystem.disk' => [\Illuminate\Contracts\Filesystem\Filesystem::class], + 'filesystem.cloud' => [\Illuminate\Contracts\Filesystem\Cloud::class], + 'hash' => [\Illuminate\Contracts\Hashing\Hasher::class], 'translator' => [ - 'Illuminate\Translation\Translator', - 'Symfony\Component\Translation\TranslatorInterface', + \Illuminate\Translation\Translator::class, + \Illuminate\Contracts\Translation\Translator::class, ], 'log' => [ - 'Illuminate\Log\Writer', - 'Illuminate\Contracts\Logging\Log', - 'Psr\Log\LoggerInterface', + \Illuminate\Log\Writer::class, + \Illuminate\Contracts\Logging\Log::class, + \Psr\Log\LoggerInterface::class, ], 'mailer' => [ - 'Illuminate\Mail\Mailer', - 'Illuminate\Contracts\Mail\Mailer', - 'Illuminate\Contracts\Mail\MailQueue', + \Illuminate\Mail\Mailer::class, + \Illuminate\Contracts\Mail\Mailer::class, + \Illuminate\Contracts\Mail\MailQueue::class, ], - 'member' => ['Notadd\Foundation\Member\MemberManagement'], - 'module' => ['Notadd\Foundation\Module\ModuleManager'], + 'member' => [\Notadd\Foundation\Member\MemberManagement::class], + 'module' => [\Notadd\Foundation\Module\ModuleManager::class], 'queue' => [ - 'Illuminate\Queue\QueueManager', - 'Illuminate\Contracts\Queue\Factory', - 'Illuminate\Contracts\Queue\Monitor', + \Illuminate\Queue\QueueManager::class, + \Illuminate\Contracts\Queue\Factory::class, + \Illuminate\Contracts\Queue\Monitor::class, ], - 'queue.connection' => ['Illuminate\Contracts\Queue\Queue'], - 'queue.failer' => ['Illuminate\Queue\Failed\FailedJobProviderInterface'], + 'queue.connection' => [\Illuminate\Contracts\Queue\Queue::class], + 'queue.failer' => [\Illuminate\Queue\Failed\FailedJobProviderInterface::class], 'redirect' => [ - 'Illuminate\Routing\Redirector', - 'Notadd\Foundation\Routing\Redirector', + \Illuminate\Routing\Redirector::class, + \Notadd\Foundation\Routing\Redirector::class, ], 'redis' => [ - 'Illuminate\Redis\Database', - 'Illuminate\Contracts\Redis\Database', + \Illuminate\Redis\RedisManager::class, + \Illuminate\Contracts\Redis\Factory::class, ], 'request' => [ - 'Illuminate\Http\Request', - 'Symfony\Component\HttpFoundation\Request', + \Illuminate\Http\Request::class, + \Symfony\Component\HttpFoundation\Request::class, ], 'router' => [ - 'Illuminate\Routing\Router', - 'Illuminate\Contracts\Routing\Registrar', + \Illuminate\Routing\Router::class, + \Illuminate\Contracts\Routing\Registrar::class, ], - 'searchengine.optimization' => ['Notadd\Foundation\SearchEngine\Optimization'], - 'session' => ['Illuminate\Session\SessionManager'], + 'searchengine.optimization' => [\Notadd\Foundation\SearchEngine\Optimization::class], + 'session' => [\Illuminate\Session\SessionManager::class], 'session.store' => [ - 'Illuminate\Session\Store', - 'Symfony\Component\HttpFoundation\Session\SessionInterface', + \Illuminate\Session\Store::class, + \Symfony\Component\HttpFoundation\Session\SessionInterface::class, ], - 'setting' => ['Notadd\Foundation\Setting\Contracts\SettingsRepository'], - 'theme' => ['Notadd\Foundation\Theme\ThemeManager'], + 'setting' => [\Notadd\Foundation\Setting\Contracts\SettingsRepository::class], + 'theme' => [\Notadd\Foundation\Theme\ThemeManager::class], 'url' => [ - 'Illuminate\Routing\UrlGenerator', - 'Illuminate\Contracts\Routing\UrlGenerator', + \Illuminate\Routing\UrlGenerator::class, + \Illuminate\Contracts\Routing\UrlGenerator::class, ], 'validator' => [ - 'Illuminate\Validation\Factory', - 'Illuminate\Contracts\Validation\Factory', + \Illuminate\Validation\Factory::class, + \Illuminate\Contracts\Validation\Factory::class, ], 'view' => [ - 'Illuminate\View\Factory', - 'Illuminate\Contracts\View\Factory', + \Illuminate\View\Factory::class, + \Illuminate\Contracts\View\Factory::class, ], ]; foreach ($aliases as $key => $aliases) { -- Gitee From a68a5d3eab4fd90fc297fc0efee9112213ca5a09 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 14:43:15 +0800 Subject: [PATCH 25/93] refactor module loading on boot --- src/Module/ModuleServiceProvider.php | 44 ++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/Module/ModuleServiceProvider.php b/src/Module/ModuleServiceProvider.php index e4004009..2eeed576 100644 --- a/src/Module/ModuleServiceProvider.php +++ b/src/Module/ModuleServiceProvider.php @@ -8,7 +8,9 @@ */ namespace Notadd\Foundation\Module; +use Illuminate\Contracts\Foundation\Application; use Illuminate\Events\Dispatcher; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\ServiceProvider; use Notadd\Foundation\Module\Commands\GenerateCommand; use Notadd\Foundation\Module\Commands\ListCommand; @@ -20,14 +22,50 @@ use Notadd\Foundation\Module\Listeners\RouteRegister; */ class ModuleServiceProvider extends ServiceProvider { + /** + * @var \Illuminate\Filesystem\Filesystem + */ + protected $files; + + /** + * ModuleServiceProvider constructor. + * + * @param \Illuminate\Contracts\Foundation\Application $app + * @param \Illuminate\Filesystem\Filesystem $files + */ + public function __construct(Application $app, Filesystem $files) + { + parent::__construct($app); + $this->files = $files; + } + /** * Boot service provider. */ public function boot() { - collect($this->app->make('module')->getModules())->each(function (Module $module, $path) { - if ($this->app->make('files')->isDirectory($path) && is_string($module->getEntry())) { - $this->app->register($module->getEntry()); + $this->app->make('module')->getModules()->each(function (Module $module, $path) { + if ($this->files->isDirectory($path)) { + if(is_string($module->getEntry()) && class_exists($module->getEntry())) { + $this->app->register($module->getEntry()); + } else { + } + } + if ($this->files->isDirectory($path) && is_string($module->getEntry())) { + if (class_exists($module->getEntry())) { + $this->app->register($module->getEntry()); + } else { + if ($this->files->exists($autoload = $path . DIRECTORY_SEPARATOR . 'vendor' .DIRECTORY_SEPARATOR . 'autoload.php')) { + $this->files->requireOnce($autoload); + if (class_exists($module->getEntry())) { + $this->app->register($module->getEntry()); + } else { + throw new \Exception('Module load fail!'); + } + } else { + throw new \Exception('Module load fail!'); + } + } } }); $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); -- Gitee From eef1275d61cf3df289eeb0825a66b4c954312485 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 14:53:40 +0800 Subject: [PATCH 26/93] refactor extension loading on boot --- src/Extension/ExtensionServiceProvider.php | 33 ++++++++++++++++++++-- src/Module/ModuleServiceProvider.php | 15 ++++------ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/Extension/ExtensionServiceProvider.php b/src/Extension/ExtensionServiceProvider.php index dc8dc01c..9d0ce77d 100644 --- a/src/Extension/ExtensionServiceProvider.php +++ b/src/Extension/ExtensionServiceProvider.php @@ -8,7 +8,9 @@ */ namespace Notadd\Foundation\Extension; +use Illuminate\Contracts\Foundation\Application; use Illuminate\Events\Dispatcher; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\ServiceProvider; use Notadd\Foundation\Extension\Commands\ListCommand; use Notadd\Foundation\Extension\Listeners\CsrfTokenRegister; @@ -19,6 +21,23 @@ use Notadd\Foundation\Extension\Listeners\RouteRegister; */ class ExtensionServiceProvider extends ServiceProvider { + /** + * @var \Illuminate\Filesystem\Filesystem + */ + protected $files; + + /** + * ExtensionServiceProvider constructor. + * + * @param \Illuminate\Contracts\Foundation\Application $app + * @param \Illuminate\Filesystem\Filesystem $files + */ + public function __construct(Application $app, Filesystem $files) + { + parent::__construct($app); + $this->files = $files; + } + /** * Boot service provider. * @@ -28,8 +47,18 @@ class ExtensionServiceProvider extends ServiceProvider { $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); - $this->app->make('extension')->getExtensions()->each(function (Extension $extension, $path) { - if ($this->app->make('files')->isDirectory($path) && is_string($extension->getEntry())) { + $this->app->make(ExtensionManager::class)->getExtensions()->each(function (Extension $extension, $path) { + if ($this->files->isDirectory($path) && is_string($extension->getEntry())) { + if (!class_exists($extension->getEntry())) { + if ($this->files->exists($autoload = $path . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php')) { + $this->files->requireOnce($autoload); + if (!class_exists($extension->getEntry())) { + throw new \Exception('Extension load fail!'); + } + } else { + throw new \Exception('Extension load fail!'); + } + } $this->app->register($extension->getEntry()); } }); diff --git a/src/Module/ModuleServiceProvider.php b/src/Module/ModuleServiceProvider.php index 2eeed576..f308dfb8 100644 --- a/src/Module/ModuleServiceProvider.php +++ b/src/Module/ModuleServiceProvider.php @@ -44,7 +44,9 @@ class ModuleServiceProvider extends ServiceProvider */ public function boot() { - $this->app->make('module')->getModules()->each(function (Module $module, $path) { + $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); + $this->app->make(ModuleManager::class)->getModules()->each(function (Module $module, $path) { if ($this->files->isDirectory($path)) { if(is_string($module->getEntry()) && class_exists($module->getEntry())) { $this->app->register($module->getEntry()); @@ -52,24 +54,19 @@ class ModuleServiceProvider extends ServiceProvider } } if ($this->files->isDirectory($path) && is_string($module->getEntry())) { - if (class_exists($module->getEntry())) { - $this->app->register($module->getEntry()); - } else { + if (!class_exists($module->getEntry())) { if ($this->files->exists($autoload = $path . DIRECTORY_SEPARATOR . 'vendor' .DIRECTORY_SEPARATOR . 'autoload.php')) { $this->files->requireOnce($autoload); - if (class_exists($module->getEntry())) { - $this->app->register($module->getEntry()); - } else { + if (!class_exists($module->getEntry())) { throw new \Exception('Module load fail!'); } } else { throw new \Exception('Module load fail!'); } } + $this->app->register($module->getEntry()); } }); - $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); - $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); $this->commands([ GenerateCommand::class, ListCommand::class -- Gitee From 4fa83096705f7bc6346be19cd2792e727f15a08a Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 15:33:50 +0800 Subject: [PATCH 27/93] add directory info for module --- src/Module/Module.php | 25 +++++++++++++++++++++++++ src/Module/ModuleManager.php | 9 +++++---- src/Module/ModuleServiceProvider.php | 3 ++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Module/Module.php b/src/Module/Module.php index 11d9ed34..7ba4db3f 100644 --- a/src/Module/Module.php +++ b/src/Module/Module.php @@ -28,6 +28,11 @@ class Module */ protected $description; + /** + * @var string + */ + protected $directory; + /** * @var string */ @@ -83,6 +88,16 @@ class Module return $this->description; } + /** + * Directory of module. + * + * @return string + */ + public function getDirectory() + { + return $this->directory; + } + /** * Entry of module. * @@ -179,6 +194,16 @@ class Module $this->description = $description; } + /** + * Set module's directory. + * + * @param string $directory + */ + public function setDirectory($directory) + { + $this->directory = $directory; + } + /** * Set module's entry. * diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index 2750fd84..74e3ccdd 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -68,7 +68,7 @@ class ModuleManager return $list; } $this->modules->each(function (Module $module) use ($list) { - $module->isEnabled() && $list->push($module); + $module->isEnabled() && $list->put($module->getName(), $module); }); return $list; @@ -92,6 +92,9 @@ class ModuleManager $module = new Module($name); $module->setAuthor(Arr::get($package, 'authors')); $module->setDescription(Arr::get($package, 'description')); + $module->setDirectory($directory); + $status = $this->container->isInstalled() ? $this->container->make('setting')->get('module.' . $name . '.enabled', false) : false; + $module->setEnabled($status); $provider = ''; if ($entries = data_get($package, 'autoload.psr-4')) { foreach ($entries as $namespace => $entry) { @@ -101,9 +104,7 @@ class ModuleManager } method_exists($provider, 'script') && $module->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $module->setStylesheet(call_user_func([$provider, 'stylesheet'])); - $status = $this->container->isInstalled() ? $this->container->make('setting')->get('module.' . $name . '.enabled', false) : false; - $module->setEnabled($status); - $this->modules->put($directory, $module); + $this->modules->put($name, $module); } } }); diff --git a/src/Module/ModuleServiceProvider.php b/src/Module/ModuleServiceProvider.php index f308dfb8..a236fbbf 100644 --- a/src/Module/ModuleServiceProvider.php +++ b/src/Module/ModuleServiceProvider.php @@ -46,7 +46,8 @@ class ModuleServiceProvider extends ServiceProvider { $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); - $this->app->make(ModuleManager::class)->getModules()->each(function (Module $module, $path) { + $this->app->make(ModuleManager::class)->getModules()->each(function (Module $module) { + $path = $module->getDirectory(); if ($this->files->isDirectory($path)) { if(is_string($module->getEntry()) && class_exists($module->getEntry())) { $this->app->register($module->getEntry()); -- Gitee From 35e7f08ab16dc285e83604d96d96c187a0115ced Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 15:36:20 +0800 Subject: [PATCH 28/93] add install entry and handler for module --- src/Module/Controllers/ModuleController.php | 14 ++++++++++++++ src/Module/Handlers/InstallHandler.php | 18 ++++++++++++++++++ src/Module/Listeners/RouteRegister.php | 1 + 3 files changed, 33 insertions(+) create mode 100644 src/Module/Handlers/InstallHandler.php diff --git a/src/Module/Controllers/ModuleController.php b/src/Module/Controllers/ModuleController.php index b7163a47..eedacc82 100644 --- a/src/Module/Controllers/ModuleController.php +++ b/src/Module/Controllers/ModuleController.php @@ -9,6 +9,7 @@ namespace Notadd\Foundation\Module\Controllers; use Notadd\Foundation\Module\Handlers\EnableHandler; +use Notadd\Foundation\Module\Handlers\InstallHandler; use Notadd\Foundation\Module\Handlers\ModuleHandler; /** @@ -41,4 +42,17 @@ class ModuleController { return $handler->toResponse()->generateHttpResponse(); } + + /** + * Install handler. + * + * @param \Notadd\Foundation\Module\Handlers\InstallHandler $handler + * + * @return \Notadd\Foundation\Passport\Responses\ApiResponse|\Psr\Http\Message\ResponseInterface|\Zend\Diactoros\Response + * @throws \Exception + */ + public function install(InstallHandler $handler) + { + return $handler->toResponse()->generateHttpResponse(); + } } diff --git a/src/Module/Handlers/InstallHandler.php b/src/Module/Handlers/InstallHandler.php new file mode 100644 index 00000000..5649d046 --- /dev/null +++ b/src/Module/Handlers/InstallHandler.php @@ -0,0 +1,18 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-02 15:34 + */ +namespace Notadd\Foundation\Module\Handlers; + +use Notadd\Foundation\Passport\Abstracts\SetHandler; + +/** + * Class InstallHandler. + */ +class InstallHandler extends SetHandler +{ +} diff --git a/src/Module/Listeners/RouteRegister.php b/src/Module/Listeners/RouteRegister.php index d8f40491..b297bea6 100644 --- a/src/Module/Listeners/RouteRegister.php +++ b/src/Module/Listeners/RouteRegister.php @@ -23,6 +23,7 @@ class RouteRegister extends AbstractRouteRegistrar { $this->router->group(['middleware' => ['auth:api', 'cross', 'web'], 'prefix' => 'api'], function () { $this->router->post('module/enable', ModuleController::class . '@enable'); + $this->router->post('module/install', ModuleController::class . '@install'); $this->router->post('module', ModuleController::class . '@handle'); }); } -- Gitee From 8451278a5b8fec7a4163bea77d40591085bff54b Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 15:47:28 +0800 Subject: [PATCH 29/93] add logic to handler install --- src/Module/Handlers/InstallHandler.php | 61 ++++++++++++++++++++++++++ src/Module/ModuleManager.php | 12 +++++ 2 files changed, 73 insertions(+) diff --git a/src/Module/Handlers/InstallHandler.php b/src/Module/Handlers/InstallHandler.php index 5649d046..ab4e620c 100644 --- a/src/Module/Handlers/InstallHandler.php +++ b/src/Module/Handlers/InstallHandler.php @@ -8,6 +8,8 @@ */ namespace Notadd\Foundation\Module\Handlers; +use Illuminate\Container\Container; +use Notadd\Foundation\Module\ModuleManager; use Notadd\Foundation\Passport\Abstracts\SetHandler; /** @@ -15,4 +17,63 @@ use Notadd\Foundation\Passport\Abstracts\SetHandler; */ class InstallHandler extends SetHandler { + /** + * @var \Notadd\Foundation\Module\ModuleManager + */ + protected $manager; + + /** + * InstallHandler constructor. + * + * @param \Illuminate\Container\Container $container + * @param \Notadd\Foundation\Module\ModuleManager $manager + */ + public function __construct(Container $container, ModuleManager $manager) + { + parent::__construct($container); + $this->manager = $manager; + } + + /** + * Errors for handler. + * + * @return array + */ + public function errors() + { + return [ + $this->translator->trans(''), + ]; + } + + /** + * Execute handler. + * + * @return bool + */ + public function execute() + { + $module = $this->manager->get($this->request->input('name')); + $provider = $module->getEntry(); + if (method_exists($provider, 'install')) { + return call_user_func([ + $provider, + 'install', + ]); + } + + return false; + } + + /** + * Messages for handler. + * + * @throws array + */ + public function messages() + { + return [ + $this->translator->trans(''), + ]; + } } diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index 74e3ccdd..8fa50c28 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -74,6 +74,18 @@ class ModuleManager return $list; } + /** + * Get a module by name. + * + * @param $name + * + * @return \Notadd\Foundation\Module\Module + */ + public function get($name) + { + return $this->modules->get($name); + } + /** * Modules of list. * -- Gitee From 6d950613df4045b2e2e87e19ceb6f7f74463e125 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 15:50:22 +0800 Subject: [PATCH 30/93] add directory of extension --- src/Extension/Extension.php | 25 ++++++++++++++++++++++ src/Extension/ExtensionManager.php | 5 +++-- src/Extension/ExtensionServiceProvider.php | 3 ++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Extension/Extension.php b/src/Extension/Extension.php index 96674ea4..1e6ff8e5 100644 --- a/src/Extension/Extension.php +++ b/src/Extension/Extension.php @@ -23,6 +23,11 @@ class Extension */ protected $description; + /** + * @var string + */ + protected $directory; + /** * @var bool */ @@ -89,6 +94,16 @@ class Extension return $this->description; } + /** + * Get directory of extension. + * + * @return string + */ + public function getDirectory(): string + { + return $this->directory; + } + /** * @return string */ @@ -179,6 +194,16 @@ class Extension $this->description = $description; } + /** + * Set directory of extension. + * + * @param string $directory + */ + public function setDirectory(string $directory) + { + $this->directory = $directory; + } + /** * @param string $entry */ diff --git a/src/Extension/ExtensionManager.php b/src/Extension/ExtensionManager.php index e3b8c216..52e2ddcd 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -101,6 +101,8 @@ class ExtensionManager $extension = new Extension($name); $extension->setAuthor(Arr::get($package, 'authors')); $extension->setDescription(Arr::get($package, 'description')); + $extension->setDirectory($directory); + $extension->setEnabled($this->container->make('setting')->get('extension.' . $name . '.enabled', false)); $provider = ''; if ($entries = data_get($package, 'autoload.psr-4')) { foreach ($entries as $namespace => $entry) { @@ -110,8 +112,7 @@ class ExtensionManager } method_exists($provider, 'script') && $extension->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $extension->setStylesheet(call_user_func([$provider, 'stylesheet'])); - $extension->setEnabled($this->container->make('setting')->get('extension.' . $name . '.enabled', false)); - $this->extensions->put($directory, $extension); + $this->extensions->put($name, $extension); } } }); diff --git a/src/Extension/ExtensionServiceProvider.php b/src/Extension/ExtensionServiceProvider.php index 9d0ce77d..2ebb4f1f 100644 --- a/src/Extension/ExtensionServiceProvider.php +++ b/src/Extension/ExtensionServiceProvider.php @@ -47,7 +47,8 @@ class ExtensionServiceProvider extends ServiceProvider { $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); - $this->app->make(ExtensionManager::class)->getExtensions()->each(function (Extension $extension, $path) { + $this->app->make(ExtensionManager::class)->getExtensions()->each(function (Extension $extension) { + $path = $extension->getDirectory(); if ($this->files->isDirectory($path) && is_string($extension->getEntry())) { if (!class_exists($extension->getEntry())) { if ($this->files->exists($autoload = $path . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php')) { -- Gitee From 4951dfac2bbdfd6bcce59db2895218f36f36b931 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 15:54:00 +0800 Subject: [PATCH 31/93] add entry and handler for extension install --- .../Controllers/ExtensionController.php | 5 ++ src/Extension/Handlers/InstallHandler.php | 70 +++++++++++++++++++ src/Extension/Listeners/RouteRegister.php | 1 + 3 files changed, 76 insertions(+) create mode 100644 src/Extension/Handlers/InstallHandler.php diff --git a/src/Extension/Controllers/ExtensionController.php b/src/Extension/Controllers/ExtensionController.php index aa2ea47b..5673ce35 100644 --- a/src/Extension/Controllers/ExtensionController.php +++ b/src/Extension/Controllers/ExtensionController.php @@ -42,4 +42,9 @@ class ExtensionController extends Controller { return $handler->toResponse()->generateHttpResponse(); } + + public function install() + { + + } } diff --git a/src/Extension/Handlers/InstallHandler.php b/src/Extension/Handlers/InstallHandler.php new file mode 100644 index 00000000..2331de4a --- /dev/null +++ b/src/Extension/Handlers/InstallHandler.php @@ -0,0 +1,70 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-02 15:51 + */ +namespace Notadd\Foundation\Extension\Handlers; + +use Illuminate\Container\Container; +use Notadd\Foundation\Extension\ExtensionManager; +use Notadd\Foundation\Passport\Abstracts\SetHandler; + +/** + * Class InstallHandler. + */ +class InstallHandler extends SetHandler +{ + /** + * @var \Notadd\Foundation\Extension\ExtensionManager + */ + protected $manager; + + /** + * InstallHandler constructor. + * + * @param \Illuminate\Container\Container $container + * @param \Notadd\Foundation\Extension\ExtensionManager $manager + */ + public function __construct(Container $container, ExtensionManager $manager) + { + parent::__construct($container); + $this->manager = $manager; + } + + /** + * Errors for handler. + * + * @return array + */ + public function errors() + { + return [ + $this->translator->trans(''), + ]; + } + + /** + * Execute Handler. + * + * @return bool + */ + public function execute() + { + return false; + } + + /** + * Messages for handler. + * + * @return array + */ + public function messages() + { + return [ + $this->translator->trans(''), + ]; + } +} diff --git a/src/Extension/Listeners/RouteRegister.php b/src/Extension/Listeners/RouteRegister.php index f08071b4..6faa4c40 100644 --- a/src/Extension/Listeners/RouteRegister.php +++ b/src/Extension/Listeners/RouteRegister.php @@ -23,6 +23,7 @@ class RouteRegister extends AbstractRouteRegistrar { $this->router->group(['middleware' => ['auth:api', 'cross', 'web'], 'prefix' => 'api'], function () { $this->router->post('extension/enable', ExtensionController::class . '@enable'); + $this->router->post('extension/install', ExtensionController::class . '@install'); $this->router->post('extension', ExtensionController::class . '@handle'); }); } -- Gitee From 997cff46e81bcb9cdd4e40ba993d37716e89f768 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 15:57:39 +0800 Subject: [PATCH 32/93] add logic of extension install --- src/Extension/ExtensionManager.php | 12 ++++++++++++ src/Extension/Handlers/InstallHandler.php | 10 +++++++++- src/Module/Handlers/InstallHandler.php | 3 +-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Extension/ExtensionManager.php b/src/Extension/ExtensionManager.php index 52e2ddcd..540080d4 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -54,6 +54,18 @@ class ExtensionManager $this->files = $files; } + /** + * Get a extension by name. + * + * @param $name + * + * @return \Notadd\Foundation\Extension\Extension + */ + public function get($name) + { + return $this->extensions->get($name); + } + /** * Path for extension. * diff --git a/src/Extension/Handlers/InstallHandler.php b/src/Extension/Handlers/InstallHandler.php index 2331de4a..3cecc1cf 100644 --- a/src/Extension/Handlers/InstallHandler.php +++ b/src/Extension/Handlers/InstallHandler.php @@ -25,7 +25,7 @@ class InstallHandler extends SetHandler /** * InstallHandler constructor. * - * @param \Illuminate\Container\Container $container + * @param \Illuminate\Container\Container $container * @param \Notadd\Foundation\Extension\ExtensionManager $manager */ public function __construct(Container $container, ExtensionManager $manager) @@ -53,6 +53,14 @@ class InstallHandler extends SetHandler */ public function execute() { + $extension = $this->manager->get($this->request->input('name')); + if ($extension && method_exists($provider = $extension->getEntry(), 'install')) { + return call_user_func([ + $provider, + 'install', + ]); + } + return false; } diff --git a/src/Module/Handlers/InstallHandler.php b/src/Module/Handlers/InstallHandler.php index ab4e620c..82a63866 100644 --- a/src/Module/Handlers/InstallHandler.php +++ b/src/Module/Handlers/InstallHandler.php @@ -54,8 +54,7 @@ class InstallHandler extends SetHandler public function execute() { $module = $this->manager->get($this->request->input('name')); - $provider = $module->getEntry(); - if (method_exists($provider, 'install')) { + if ($module && method_exists($provider = $module->getEntry(), 'install')) { return call_user_func([ $provider, 'install', -- Gitee From c571ca6b9f0b2cd9012f3bd7620747ab397f1bfd Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 16:05:43 +0800 Subject: [PATCH 33/93] add entry and handler for module uninstall --- .../Controllers/ExtensionController.php | 13 +++- src/Module/Controllers/ModuleController.php | 14 ++++ src/Module/Handlers/UninstallHandler.php | 70 +++++++++++++++++++ src/Module/Listeners/RouteRegister.php | 1 + 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 src/Module/Handlers/UninstallHandler.php diff --git a/src/Extension/Controllers/ExtensionController.php b/src/Extension/Controllers/ExtensionController.php index 5673ce35..b2abb65f 100644 --- a/src/Extension/Controllers/ExtensionController.php +++ b/src/Extension/Controllers/ExtensionController.php @@ -10,6 +10,7 @@ namespace Notadd\Foundation\Extension\Controllers; use Notadd\Foundation\Extension\Handlers\EnableHandler; use Notadd\Foundation\Extension\Handlers\ExtensionHandler; +use Notadd\Foundation\Extension\Handlers\InstallHandler; use Notadd\Foundation\Routing\Abstracts\Controller; /** @@ -43,8 +44,16 @@ class ExtensionController extends Controller return $handler->toResponse()->generateHttpResponse(); } - public function install() + /** + * Install handler. + * + * @param \Notadd\Foundation\Extension\Handlers\InstallHandler $handler + * + * @return \Notadd\Foundation\Passport\Responses\ApiResponse|\Psr\Http\Message\ResponseInterface|\Zend\Diactoros\Response + * @throws \Exception + */ + public function install(InstallHandler $handler) { - + return $handler->toResponse()->generateHttpResponse(); } } diff --git a/src/Module/Controllers/ModuleController.php b/src/Module/Controllers/ModuleController.php index eedacc82..4e613ba4 100644 --- a/src/Module/Controllers/ModuleController.php +++ b/src/Module/Controllers/ModuleController.php @@ -11,6 +11,7 @@ namespace Notadd\Foundation\Module\Controllers; use Notadd\Foundation\Module\Handlers\EnableHandler; use Notadd\Foundation\Module\Handlers\InstallHandler; use Notadd\Foundation\Module\Handlers\ModuleHandler; +use Notadd\Foundation\Module\Handlers\UninstallHandler; /** * Class ModuleController. @@ -55,4 +56,17 @@ class ModuleController { return $handler->toResponse()->generateHttpResponse(); } + + /** + * Uninstall handler. + * + * @param \Notadd\Foundation\Module\Handlers\UninstallHandler $handler + * + * @return \Notadd\Foundation\Passport\Responses\ApiResponse|\Psr\Http\Message\ResponseInterface|\Zend\Diactoros\Response + * @throws \Exception + */ + public function uninstall(UninstallHandler $handler) + { + return $handler->toResponse()->generateHttpResponse(); + } } diff --git a/src/Module/Handlers/UninstallHandler.php b/src/Module/Handlers/UninstallHandler.php new file mode 100644 index 00000000..3314ad46 --- /dev/null +++ b/src/Module/Handlers/UninstallHandler.php @@ -0,0 +1,70 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-02 16:00 + */ +namespace Notadd\Foundation\Module\Handlers; + +use Illuminate\Container\Container; +use Notadd\Foundation\Module\ModuleManager; +use Notadd\Foundation\Passport\Abstracts\SetHandler; + +/** + * Class UninstallHandler. + */ +class UninstallHandler extends SetHandler +{ + /** + * @var \Notadd\Foundation\Module\ModuleManager + */ + protected $manager; + + /** + * UninstallHandler constructor. + * + * @param \Illuminate\Container\Container $container + * @param \Notadd\Foundation\Module\ModuleManager $manager + */ + public function __construct(Container $container, ModuleManager $manager) + { + parent::__construct($container); + $this->manager = $manager; + } + + /** + * Errors for handler. + * + * @return array + */ + public function errors() + { + return [ + $this->translator->trans(''), + ]; + } + + /** + * Execute Handler. + * + * @return bool + */ + public function execute() + { + return false; + } + + /** + * Messages for handler. + * + * @return array + */ + public function messages() + { + return [ + $this->translator->trans(''), + ]; + } +} diff --git a/src/Module/Listeners/RouteRegister.php b/src/Module/Listeners/RouteRegister.php index b297bea6..482b7b5e 100644 --- a/src/Module/Listeners/RouteRegister.php +++ b/src/Module/Listeners/RouteRegister.php @@ -24,6 +24,7 @@ class RouteRegister extends AbstractRouteRegistrar $this->router->group(['middleware' => ['auth:api', 'cross', 'web'], 'prefix' => 'api'], function () { $this->router->post('module/enable', ModuleController::class . '@enable'); $this->router->post('module/install', ModuleController::class . '@install'); + $this->router->post('module/uninstall', ModuleController::class . '@uninstall'); $this->router->post('module', ModuleController::class . '@handle'); }); } -- Gitee From 969818c7b7f779b1c9379b96c3605a35a8d06c87 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 16:08:03 +0800 Subject: [PATCH 34/93] add logic of module uninstall --- src/Module/Handlers/UninstallHandler.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Module/Handlers/UninstallHandler.php b/src/Module/Handlers/UninstallHandler.php index 3314ad46..886c441b 100644 --- a/src/Module/Handlers/UninstallHandler.php +++ b/src/Module/Handlers/UninstallHandler.php @@ -25,7 +25,7 @@ class UninstallHandler extends SetHandler /** * UninstallHandler constructor. * - * @param \Illuminate\Container\Container $container + * @param \Illuminate\Container\Container $container * @param \Notadd\Foundation\Module\ModuleManager $manager */ public function __construct(Container $container, ModuleManager $manager) @@ -53,6 +53,14 @@ class UninstallHandler extends SetHandler */ public function execute() { + $module = $this->manager->get($this->request->input('name')); + if ($module && method_exists($provider = $module->getEntry(), 'uninstall')) { + return call_user_func([ + $provider, + 'uninstall', + ]); + } + return false; } -- Gitee From b128a53cc38134ecd2839190f6ee9fb566ce0955 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 16:11:22 +0800 Subject: [PATCH 35/93] add entry and handler for extension uninstall --- .../Controllers/ExtensionController.php | 14 ++++++++++++++ src/Extension/Handlers/UninstallHandler.php | 19 +++++++++++++++++++ src/Extension/Listeners/RouteRegister.php | 1 + 3 files changed, 34 insertions(+) create mode 100644 src/Extension/Handlers/UninstallHandler.php diff --git a/src/Extension/Controllers/ExtensionController.php b/src/Extension/Controllers/ExtensionController.php index b2abb65f..b8f6d02d 100644 --- a/src/Extension/Controllers/ExtensionController.php +++ b/src/Extension/Controllers/ExtensionController.php @@ -11,6 +11,7 @@ namespace Notadd\Foundation\Extension\Controllers; use Notadd\Foundation\Extension\Handlers\EnableHandler; use Notadd\Foundation\Extension\Handlers\ExtensionHandler; use Notadd\Foundation\Extension\Handlers\InstallHandler; +use Notadd\Foundation\Extension\Handlers\UninstallHandler; use Notadd\Foundation\Routing\Abstracts\Controller; /** @@ -56,4 +57,17 @@ class ExtensionController extends Controller { return $handler->toResponse()->generateHttpResponse(); } + + /** + * Uninstall handler. + * + * @param \Notadd\Foundation\Extension\Handlers\UninstallHandler $handler + * + * @return \Notadd\Foundation\Passport\Responses\ApiResponse|\Psr\Http\Message\ResponseInterface|\Zend\Diactoros\Response + * @throws \Exception + */ + public function uninstall(UninstallHandler $handler) + { + return $handler->toResponse()->generateHttpResponse(); + } } diff --git a/src/Extension/Handlers/UninstallHandler.php b/src/Extension/Handlers/UninstallHandler.php new file mode 100644 index 00000000..37280630 --- /dev/null +++ b/src/Extension/Handlers/UninstallHandler.php @@ -0,0 +1,19 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-02 16:10 + */ +namespace Notadd\Foundation\Extension\Handlers; + +use Notadd\Foundation\Passport\Abstracts\SetHandler; + +/** + * Class UninstallHandler. + */ +class UninstallHandler extends SetHandler +{ + +} diff --git a/src/Extension/Listeners/RouteRegister.php b/src/Extension/Listeners/RouteRegister.php index 6faa4c40..1abdaddb 100644 --- a/src/Extension/Listeners/RouteRegister.php +++ b/src/Extension/Listeners/RouteRegister.php @@ -24,6 +24,7 @@ class RouteRegister extends AbstractRouteRegistrar $this->router->group(['middleware' => ['auth:api', 'cross', 'web'], 'prefix' => 'api'], function () { $this->router->post('extension/enable', ExtensionController::class . '@enable'); $this->router->post('extension/install', ExtensionController::class . '@install'); + $this->router->post('extension/uninstall', ExtensionController::class . '@uninstall'); $this->router->post('extension', ExtensionController::class . '@handle'); }); } -- Gitee From e1e0f1c6a91b2ae040fd1ee94537a3a5551e9020 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 2 Mar 2017 16:17:18 +0800 Subject: [PATCH 36/93] add logic of extension uninstall --- src/Extension/Handlers/UninstallHandler.php | 59 +++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/Extension/Handlers/UninstallHandler.php b/src/Extension/Handlers/UninstallHandler.php index 37280630..27eda677 100644 --- a/src/Extension/Handlers/UninstallHandler.php +++ b/src/Extension/Handlers/UninstallHandler.php @@ -8,6 +8,8 @@ */ namespace Notadd\Foundation\Extension\Handlers; +use Illuminate\Container\Container; +use Notadd\Foundation\Extension\ExtensionManager; use Notadd\Foundation\Passport\Abstracts\SetHandler; /** @@ -15,5 +17,62 @@ use Notadd\Foundation\Passport\Abstracts\SetHandler; */ class UninstallHandler extends SetHandler { + /** + * @var \Notadd\Foundation\Extension\ExtensionManager + */ + protected $manager; + /** + * UninstallHandler constructor. + * + * @param \Illuminate\Container\Container $container + * @param \Notadd\Foundation\Extension\ExtensionManager $manager + */ + public function __construct(Container $container, ExtensionManager $manager) + { + parent::__construct($container); + $this->manager = $manager; + } + + /** + * Errors for handler. + * + * @return array + */ + public function errors() + { + return [ + $this->translator->trans(''), + ]; + } + + /** + * Execute Handler. + * + * @return bool + */ + public function execute() + { + $extension = $this->manager->get($this->request->input('name')); + if ($extension && method_exists($provider = $extension->getEntry(), 'uninstall')) { + return call_user_func([ + $provider, + 'uninstall', + ]); + } + + return false; + } + + /** + * Messages for handler. + * + * @return array + */ + public function messages() + { + return [ + $this->translator->trans(''), + ]; + } } -- Gitee From 429c0eaf7cab865d06d425c89e34f5e28604b0c4 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 3 Mar 2017 10:09:17 +0800 Subject: [PATCH 37/93] can not inject instance in service provider's construct --- src/Extension/ExtensionServiceProvider.php | 5 ++--- src/Module/ModuleServiceProvider.php | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Extension/ExtensionServiceProvider.php b/src/Extension/ExtensionServiceProvider.php index 2ebb4f1f..5d60d9c4 100644 --- a/src/Extension/ExtensionServiceProvider.php +++ b/src/Extension/ExtensionServiceProvider.php @@ -30,12 +30,11 @@ class ExtensionServiceProvider extends ServiceProvider * ExtensionServiceProvider constructor. * * @param \Illuminate\Contracts\Foundation\Application $app - * @param \Illuminate\Filesystem\Filesystem $files */ - public function __construct(Application $app, Filesystem $files) + public function __construct(Application $app) { parent::__construct($app); - $this->files = $files; + $this->files = $app->make(Filesystem::class); } /** diff --git a/src/Module/ModuleServiceProvider.php b/src/Module/ModuleServiceProvider.php index a236fbbf..a2a44560 100644 --- a/src/Module/ModuleServiceProvider.php +++ b/src/Module/ModuleServiceProvider.php @@ -31,12 +31,11 @@ class ModuleServiceProvider extends ServiceProvider * ModuleServiceProvider constructor. * * @param \Illuminate\Contracts\Foundation\Application $app - * @param \Illuminate\Filesystem\Filesystem $files */ - public function __construct(Application $app, Filesystem $files) + public function __construct(Application $app) { parent::__construct($app); - $this->files = $files; + $this->files = $app->make(Filesystem::class); } /** -- Gitee From ed8595ee0478b733340bc3b100d456877bee5099 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 3 Mar 2017 15:12:24 +0800 Subject: [PATCH 38/93] make class Extension to abstract class ,and add abstract functions --- src/Extension/Abstracts/Extension.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Extension/Abstracts/Extension.php b/src/Extension/Abstracts/Extension.php index 7e7a87b6..0aeddf16 100644 --- a/src/Extension/Abstracts/Extension.php +++ b/src/Extension/Abstracts/Extension.php @@ -14,7 +14,7 @@ use Illuminate\Support\ServiceProvider; /** * Class Extension. */ -class Extension extends ServiceProvider +abstract class Extension extends ServiceProvider { /** * @var \Illuminate\Events\Dispatcher @@ -41,8 +41,14 @@ class Extension extends ServiceProvider /** * Boot extension. */ - public function boot() { - } + abstract public function boot(); + + /** + * Install extension. + * + * @return bool + */ + abstract public function install(); /** * Register extension extra providers. @@ -50,4 +56,11 @@ class Extension extends ServiceProvider public function register() { } + + /** + * Uninstall extension. + * + * @return mixed + */ + abstract public function uninstall(); } -- Gitee From ebce01b949caf9a229410a60d0d407612992c57f Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 3 Mar 2017 15:17:32 +0800 Subject: [PATCH 39/93] add class Module as base class for module's service provider --- src/Module/Abstracts/Module.php | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/Module/Abstracts/Module.php diff --git a/src/Module/Abstracts/Module.php b/src/Module/Abstracts/Module.php new file mode 100644 index 00000000..38e7917b --- /dev/null +++ b/src/Module/Abstracts/Module.php @@ -0,0 +1,66 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-03 15:12 + */ +namespace Notadd\Foundation\Module\Abstracts; + +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Support\ServiceProvider; + +/** + * Class Module. + */ +abstract class Module extends ServiceProvider +{ + /** + * @var \Illuminate\Events\Dispatcher + */ + protected $events; + + /** + * @var \Illuminate\Routing\Router + */ + protected $router; + + /** + * Module constructor. + * + * @param \Illuminate\Contracts\Foundation\Application $app + */ + public function __construct(Application $app) + { + parent::__construct($app); + $this->events = $app['events']; + $this->router = $app['router']; + } + + /** + * Boot module. + */ + abstract public function boot(); + + /** + * Install module. + * + * @return bool + */ + abstract public function install(); + + /** + * Register module extra providers. + */ + public function register() + { + } + + /** + * Uninstall module. + * + * @return mixed + */ + abstract public function uninstall(); +} -- Gitee From 6a7ec500fdb3dcc0637f6b794fd628bde88ac44d Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 3 Mar 2017 15:30:51 +0800 Subject: [PATCH 40/93] add entry and handler for module update --- src/Module/Controllers/ModuleController.php | 14 ++++++++++++++ src/Module/Handlers/UpdateHandler.php | 18 ++++++++++++++++++ src/Module/Listeners/RouteRegister.php | 1 + 3 files changed, 33 insertions(+) create mode 100644 src/Module/Handlers/UpdateHandler.php diff --git a/src/Module/Controllers/ModuleController.php b/src/Module/Controllers/ModuleController.php index 4e613ba4..fdf7c1b9 100644 --- a/src/Module/Controllers/ModuleController.php +++ b/src/Module/Controllers/ModuleController.php @@ -12,6 +12,7 @@ use Notadd\Foundation\Module\Handlers\EnableHandler; use Notadd\Foundation\Module\Handlers\InstallHandler; use Notadd\Foundation\Module\Handlers\ModuleHandler; use Notadd\Foundation\Module\Handlers\UninstallHandler; +use Notadd\Foundation\Module\Handlers\UpdateHandler; /** * Class ModuleController. @@ -69,4 +70,17 @@ class ModuleController { return $handler->toResponse()->generateHttpResponse(); } + + /** + * Update Handler. + * + * @param \Notadd\Foundation\Module\Handlers\UpdateHandler $handler + * + * @return \Notadd\Foundation\Passport\Responses\ApiResponse|\Psr\Http\Message\ResponseInterface|\Zend\Diactoros\Response + * @throws \Exception + */ + public function update(UpdateHandler $handler) + { + return $handler->toResponse()->generateHttpResponse(); + } } diff --git a/src/Module/Handlers/UpdateHandler.php b/src/Module/Handlers/UpdateHandler.php new file mode 100644 index 00000000..074155d7 --- /dev/null +++ b/src/Module/Handlers/UpdateHandler.php @@ -0,0 +1,18 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-03 15:27 + */ +namespace Notadd\Foundation\Module\Handlers; + +use Notadd\Foundation\Passport\Abstracts\SetHandler; + +/** + * Class UpdateHandler. + */ +class UpdateHandler extends SetHandler +{ +} diff --git a/src/Module/Listeners/RouteRegister.php b/src/Module/Listeners/RouteRegister.php index 482b7b5e..6cd31425 100644 --- a/src/Module/Listeners/RouteRegister.php +++ b/src/Module/Listeners/RouteRegister.php @@ -25,6 +25,7 @@ class RouteRegister extends AbstractRouteRegistrar $this->router->post('module/enable', ModuleController::class . '@enable'); $this->router->post('module/install', ModuleController::class . '@install'); $this->router->post('module/uninstall', ModuleController::class . '@uninstall'); + $this->router->post('module/update', ModuleController::class . '@update'); $this->router->post('module', ModuleController::class . '@handle'); }); } -- Gitee From 2b300fbcef6fa14bdcac6651263d19963ada58a9 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 3 Mar 2017 15:31:47 +0800 Subject: [PATCH 41/93] add update logic for update handler --- src/Module/Handlers/UpdateHandler.php | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/Module/Handlers/UpdateHandler.php b/src/Module/Handlers/UpdateHandler.php index 074155d7..e371e288 100644 --- a/src/Module/Handlers/UpdateHandler.php +++ b/src/Module/Handlers/UpdateHandler.php @@ -8,6 +8,8 @@ */ namespace Notadd\Foundation\Module\Handlers; +use Illuminate\Container\Container; +use Notadd\Foundation\Module\ModuleManager; use Notadd\Foundation\Passport\Abstracts\SetHandler; /** @@ -15,4 +17,62 @@ use Notadd\Foundation\Passport\Abstracts\SetHandler; */ class UpdateHandler extends SetHandler { + /** + * @var \Notadd\Foundation\Module\ModuleManager + */ + protected $manager; + + /** + * UpdateHandler constructor. + * + * @param \Illuminate\Container\Container $container + * @param \Notadd\Foundation\Module\ModuleManager $manager + */ + public function __construct(Container $container, ModuleManager $manager) + { + parent::__construct($container); + $this->manager = $manager; + } + + /** + * Errors for handler. + * + * @return array + */ + public function errors() + { + return [ + $this->translator->trans(''), + ]; + } + + /** + * Execute Handler. + * + * @return bool + */ + public function execute() + { + $module = $this->manager->get($this->request->input('name')); + if ($module && method_exists($provider = $module->getEntry(), 'update')) { + return call_user_func([ + $provider, + 'update', + ]); + } + + return false; + } + + /** + * Messages for handler. + * + * @return array + */ + public function messages() + { + return [ + $this->translator->trans(''), + ]; + } } -- Gitee From 83488bdb70a573c6bc700c90d8cd247163980146 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 3 Mar 2017 15:34:36 +0800 Subject: [PATCH 42/93] add entry and handler for extension update --- .../Controllers/ExtensionController.php | 14 ++++++++++++++ src/Extension/Handlers/UpdateHandler.php | 18 ++++++++++++++++++ src/Extension/Listeners/RouteRegister.php | 1 + 3 files changed, 33 insertions(+) create mode 100644 src/Extension/Handlers/UpdateHandler.php diff --git a/src/Extension/Controllers/ExtensionController.php b/src/Extension/Controllers/ExtensionController.php index b8f6d02d..623e1168 100644 --- a/src/Extension/Controllers/ExtensionController.php +++ b/src/Extension/Controllers/ExtensionController.php @@ -12,6 +12,7 @@ use Notadd\Foundation\Extension\Handlers\EnableHandler; use Notadd\Foundation\Extension\Handlers\ExtensionHandler; use Notadd\Foundation\Extension\Handlers\InstallHandler; use Notadd\Foundation\Extension\Handlers\UninstallHandler; +use Notadd\Foundation\Extension\Handlers\UpdateHandler; use Notadd\Foundation\Routing\Abstracts\Controller; /** @@ -70,4 +71,17 @@ class ExtensionController extends Controller { return $handler->toResponse()->generateHttpResponse(); } + + /** + * Update handler. + * + * @param \Notadd\Foundation\Extension\Handlers\UpdateHandler $handler + * + * @return \Notadd\Foundation\Passport\Responses\ApiResponse|\Psr\Http\Message\ResponseInterface|\Zend\Diactoros\Response + * @throws \Exception + */ + public function update(UpdateHandler $handler) + { + return $handler->toResponse()->generateHttpResponse(); + } } diff --git a/src/Extension/Handlers/UpdateHandler.php b/src/Extension/Handlers/UpdateHandler.php new file mode 100644 index 00000000..6933f4fb --- /dev/null +++ b/src/Extension/Handlers/UpdateHandler.php @@ -0,0 +1,18 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-03 15:33 + */ +namespace Notadd\Foundation\Extension\Handlers; + +use Notadd\Foundation\Passport\Abstracts\SetHandler; + +/** + * Class UpdateHandler. + */ +class UpdateHandler extends SetHandler +{ +} diff --git a/src/Extension/Listeners/RouteRegister.php b/src/Extension/Listeners/RouteRegister.php index 1abdaddb..bcd05d08 100644 --- a/src/Extension/Listeners/RouteRegister.php +++ b/src/Extension/Listeners/RouteRegister.php @@ -25,6 +25,7 @@ class RouteRegister extends AbstractRouteRegistrar $this->router->post('extension/enable', ExtensionController::class . '@enable'); $this->router->post('extension/install', ExtensionController::class . '@install'); $this->router->post('extension/uninstall', ExtensionController::class . '@uninstall'); + $this->router->post('extension/update', ExtensionController::class . '@update'); $this->router->post('extension', ExtensionController::class . '@handle'); }); } -- Gitee From c09367400346cdf76cfd70322537322776a04f16 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 3 Mar 2017 15:37:24 +0800 Subject: [PATCH 43/93] add logic for update handler --- src/Extension/Handlers/UpdateHandler.php | 60 ++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/Extension/Handlers/UpdateHandler.php b/src/Extension/Handlers/UpdateHandler.php index 6933f4fb..7822ec9d 100644 --- a/src/Extension/Handlers/UpdateHandler.php +++ b/src/Extension/Handlers/UpdateHandler.php @@ -8,6 +8,8 @@ */ namespace Notadd\Foundation\Extension\Handlers; +use Illuminate\Container\Container; +use Notadd\Foundation\Extension\ExtensionManager; use Notadd\Foundation\Passport\Abstracts\SetHandler; /** @@ -15,4 +17,62 @@ use Notadd\Foundation\Passport\Abstracts\SetHandler; */ class UpdateHandler extends SetHandler { + /** + * @var \Notadd\Foundation\Extension\ExtensionManager + */ + protected $manager; + + /** + * UpdateHandler constructor. + * + * @param \Illuminate\Container\Container $container + * @param \Notadd\Foundation\Extension\ExtensionManager $manager + */ + public function __construct(Container $container, ExtensionManager $manager) + { + parent::__construct($container); + $this->manager = $manager; + } + + /** + * Errors for handler. + * + * @return array + */ + public function errors() + { + return [ + $this->translator->trans(''), + ]; + } + + /** + * Execute Handler. + * + * @return bool + */ + public function execute() + { + $extension = $this->manager->get($this->request->input('name')); + if ($extension && method_exists($provider = $extension->getEntry(), 'update')) { + return call_user_func([ + $provider, + 'update', + ]); + } + + return false; + } + + /** + * Messages for handler. + * + * @return array + */ + public function messages() + { + return [ + $this->translator->trans(''), + ]; + } } -- Gitee From b790efb72322467153926f6a0c66475c0c4d943f Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 3 Mar 2017 16:21:50 +0800 Subject: [PATCH 44/93] rename to RouteRegister --- src/Attachment/AttachmentServiceProvider.php | 4 ++-- src/Attachment/Listeners/RouteRegistrar.php | 4 ++-- src/Auth/AuthServiceProvider.php | 4 ++-- src/Auth/Listeners/RouteRegistrar.php | 4 ++-- src/Debug/DebugServiceProvider.php | 4 ++-- src/Debug/Listeners/RouteRegistrar.php | 4 ++-- src/Editor/EditorServiceProvider.php | 4 ++-- src/Editor/Listeners/RouteRegistrar.php | 4 ++-- src/Extension/Listeners/RouteRegister.php | 4 ++-- src/Mail/Listeners/RouterRegistrar.php | 4 ++-- src/Mail/MailServiceProvider.php | 4 ++-- src/Module/Listeners/RouteRegister.php | 4 ++-- src/Navigation/Listeners/RouteRegister.php | 4 ++-- src/Passport/Listeners/RouterRegistrar.php | 4 ++-- src/Passport/PassportServiceProvider.php | 4 ++-- .../Abstracts/{RouteRegistrar.php => RouteRegister.php} | 2 +- src/SearchEngine/Listeners/RouterRegistrar.php | 4 ++-- src/SearchEngine/SearchEngineServiceProvider.php | 4 ++-- src/Setting/Listeners/RouteRegistrar.php | 4 ++-- src/Setting/SettingServiceProvider.php | 4 ++-- src/Sitemap/Listeners/RouteRegistrar.php | 5 ++--- src/Sitemap/SitemapServiceProvider.php | 4 ++-- 22 files changed, 43 insertions(+), 44 deletions(-) rename src/Routing/Abstracts/{RouteRegistrar.php => RouteRegister.php} (95%) diff --git a/src/Attachment/AttachmentServiceProvider.php b/src/Attachment/AttachmentServiceProvider.php index 6e876d5c..1419167d 100644 --- a/src/Attachment/AttachmentServiceProvider.php +++ b/src/Attachment/AttachmentServiceProvider.php @@ -11,7 +11,7 @@ namespace Notadd\Foundation\Attachment; use Illuminate\Events\Dispatcher; use Illuminate\Support\ServiceProvider; use Notadd\Foundation\Attachment\Listeners\CsrfTokenRegister; -use Notadd\Foundation\Attachment\Listeners\RouteRegistrar; +use Notadd\Foundation\Attachment\Listeners\RouteRegister; /** * Class AttachmentServiceProvider. @@ -24,6 +24,6 @@ class AttachmentServiceProvider extends ServiceProvider public function boot() { $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); - $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); } } diff --git a/src/Attachment/Listeners/RouteRegistrar.php b/src/Attachment/Listeners/RouteRegistrar.php index 31465a28..1ab84886 100644 --- a/src/Attachment/Listeners/RouteRegistrar.php +++ b/src/Attachment/Listeners/RouteRegistrar.php @@ -11,12 +11,12 @@ namespace Notadd\Foundation\Attachment\Listeners; use Notadd\Foundation\Attachment\Controllers\AttachmentController; use Notadd\Foundation\Attachment\Controllers\CdnController; use Notadd\Foundation\Attachment\Controllers\StorageController; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; +use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; /** * Class RouteRegistrar. */ -class RouteRegistrar extends AbstractRouteRegistrar +class RouteRegister extends AbstractRouteRegister { /** * Handle Route Registrar. diff --git a/src/Auth/AuthServiceProvider.php b/src/Auth/AuthServiceProvider.php index 5be41306..32742c3f 100644 --- a/src/Auth/AuthServiceProvider.php +++ b/src/Auth/AuthServiceProvider.php @@ -10,7 +10,7 @@ namespace Notadd\Foundation\Auth; use Illuminate\Auth\AuthServiceProvider as IlluminateAuthServiceProvider; use Illuminate\Events\Dispatcher; -use Notadd\Foundation\Auth\Listeners\RouteRegistrar; +use Notadd\Foundation\Auth\Listeners\RouteRegister; /** * Class AuthServiceProvider. @@ -22,6 +22,6 @@ class AuthServiceProvider extends IlluminateAuthServiceProvider */ public function boot() { - $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); } } diff --git a/src/Auth/Listeners/RouteRegistrar.php b/src/Auth/Listeners/RouteRegistrar.php index a40c98cf..173b9f34 100644 --- a/src/Auth/Listeners/RouteRegistrar.php +++ b/src/Auth/Listeners/RouteRegistrar.php @@ -9,12 +9,12 @@ namespace Notadd\Foundation\Auth\Listeners; use Notadd\Foundation\Auth\Controllers\AuthController; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; +use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; /** * Class RouterRegistrar. */ -class RouteRegistrar extends AbstractRouteRegistrar +class RouteRegister extends AbstractRouteRegister { /** * Handle Route Registrar. diff --git a/src/Debug/DebugServiceProvider.php b/src/Debug/DebugServiceProvider.php index 532f4c16..25b4049d 100644 --- a/src/Debug/DebugServiceProvider.php +++ b/src/Debug/DebugServiceProvider.php @@ -10,7 +10,7 @@ namespace Notadd\Foundation\Debug; use Illuminate\Events\Dispatcher; use Illuminate\Support\ServiceProvider; use Notadd\Foundation\Debug\Listeners\CsrfTokenRegister; -use Notadd\Foundation\Debug\Listeners\RouteRegistrar; +use Notadd\Foundation\Debug\Listeners\RouteRegister; /** * Class DebugServiceProvider. @@ -23,6 +23,6 @@ class DebugServiceProvider extends ServiceProvider public function boot() { $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); - $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); } } diff --git a/src/Debug/Listeners/RouteRegistrar.php b/src/Debug/Listeners/RouteRegistrar.php index 4b7b974b..ab30f6cc 100644 --- a/src/Debug/Listeners/RouteRegistrar.php +++ b/src/Debug/Listeners/RouteRegistrar.php @@ -8,12 +8,12 @@ namespace Notadd\Foundation\Debug\Listeners; use Notadd\Foundation\Debug\Controllers\DebugController; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; +use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; /** * Class RouteRegistrar. */ -class RouteRegistrar extends AbstractRouteRegistrar +class RouteRegister extends AbstractRouteRegister { /** * Handle Route Registrar. diff --git a/src/Editor/EditorServiceProvider.php b/src/Editor/EditorServiceProvider.php index c5018532..9e6aeea6 100644 --- a/src/Editor/EditorServiceProvider.php +++ b/src/Editor/EditorServiceProvider.php @@ -11,7 +11,7 @@ namespace Notadd\Foundation\Editor; use Illuminate\Events\Dispatcher; use Illuminate\Support\ServiceProvider; use Notadd\Foundation\Editor\Listeners\CsrfTokenRegister; -use Notadd\Foundation\Editor\Listeners\RouteRegistrar; +use Notadd\Foundation\Editor\Listeners\RouteRegister; /** * Class EditorServiceProvider. @@ -24,6 +24,6 @@ class EditorServiceProvider extends ServiceProvider public function boot() { $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); - $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); } } diff --git a/src/Editor/Listeners/RouteRegistrar.php b/src/Editor/Listeners/RouteRegistrar.php index 8389b4e1..6773554b 100644 --- a/src/Editor/Listeners/RouteRegistrar.php +++ b/src/Editor/Listeners/RouteRegistrar.php @@ -9,12 +9,12 @@ namespace Notadd\Foundation\Editor\Listeners; use Notadd\Foundation\Editor\Controllers\UEditorController; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; +use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; /** * Class RouteRegistrar. */ -class RouteRegistrar extends AbstractRouteRegistrar +class RouteRegister extends AbstractRouteRegister { /** * Handle Route Registrar. diff --git a/src/Extension/Listeners/RouteRegister.php b/src/Extension/Listeners/RouteRegister.php index bcd05d08..13c027cf 100644 --- a/src/Extension/Listeners/RouteRegister.php +++ b/src/Extension/Listeners/RouteRegister.php @@ -9,12 +9,12 @@ namespace Notadd\Foundation\Extension\Listeners; use Notadd\Foundation\Extension\Controllers\ExtensionController; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; +use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; /** * Class RouteRegistrar. */ -class RouteRegister extends AbstractRouteRegistrar +class RouteRegister extends AbstractRouteRegister { /** * Handle Route Registrar. diff --git a/src/Mail/Listeners/RouterRegistrar.php b/src/Mail/Listeners/RouterRegistrar.php index 4d2dca03..8f854b0a 100644 --- a/src/Mail/Listeners/RouterRegistrar.php +++ b/src/Mail/Listeners/RouterRegistrar.php @@ -9,12 +9,12 @@ namespace Notadd\Foundation\Mail\Listeners; use Notadd\Foundation\Mail\Controllers\MailController; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; +use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; /** * Class RouterRegistrar. */ -class RouterRegistrar extends AbstractRouteRegistrar +class RouterRegister extends AbstractRouteRegister { /** * Handle Route Registrar. diff --git a/src/Mail/MailServiceProvider.php b/src/Mail/MailServiceProvider.php index 67f69e06..48d14f00 100644 --- a/src/Mail/MailServiceProvider.php +++ b/src/Mail/MailServiceProvider.php @@ -11,7 +11,7 @@ namespace Notadd\Foundation\Mail; use Illuminate\Events\Dispatcher; use Illuminate\Mail\MailServiceProvider as IlluminateMailServiceProvider; use Notadd\Foundation\Mail\Listeners\CsrfTokenRegister; -use Notadd\Foundation\Mail\Listeners\RouterRegistrar; +use Notadd\Foundation\Mail\Listeners\RouterRegister; /** * Class MailServiceProvider. @@ -29,6 +29,6 @@ class MailServiceProvider extends IlluminateMailServiceProvider public function boot() { $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); - $this->app->make(Dispatcher::class)->subscribe(RouterRegistrar::class); + $this->app->make(Dispatcher::class)->subscribe(RouterRegister::class); } } diff --git a/src/Module/Listeners/RouteRegister.php b/src/Module/Listeners/RouteRegister.php index 6cd31425..622c210e 100644 --- a/src/Module/Listeners/RouteRegister.php +++ b/src/Module/Listeners/RouteRegister.php @@ -9,12 +9,12 @@ namespace Notadd\Foundation\Module\Listeners; use Notadd\Foundation\Module\Controllers\ModuleController; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; +use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; /** * Class RouteRegistrar. */ -class RouteRegister extends AbstractRouteRegistrar +class RouteRegister extends AbstractRouteRegister { /** * Handle Route Registrar. diff --git a/src/Navigation/Listeners/RouteRegister.php b/src/Navigation/Listeners/RouteRegister.php index 4baac58c..4695fa61 100644 --- a/src/Navigation/Listeners/RouteRegister.php +++ b/src/Navigation/Listeners/RouteRegister.php @@ -10,12 +10,12 @@ namespace Notadd\Foundation\Navigation\Listeners; use Notadd\Foundation\Navigation\Controllers\GroupController; use Notadd\Foundation\Navigation\Controllers\ItemController; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; +use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; /** * Class RouteRegister. */ -class RouteRegister extends AbstractRouteRegistrar +class RouteRegister extends AbstractRouteRegister { /** * Handle Route Registrar. diff --git a/src/Passport/Listeners/RouterRegistrar.php b/src/Passport/Listeners/RouterRegistrar.php index 53ce362a..e6dbefaf 100644 --- a/src/Passport/Listeners/RouterRegistrar.php +++ b/src/Passport/Listeners/RouterRegistrar.php @@ -14,12 +14,12 @@ use Laravel\Passport\ApiTokenCookieFactory; use Notadd\Foundation\Passport\Controllers\AccessTokenController; use Notadd\Foundation\Passport\Controllers\AuthorizationController; use Notadd\Foundation\Passport\Controllers\ClientsController; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar; +use Notadd\Foundation\Routing\Abstracts\RouteRegister; /** * Class RouterRegistrar. */ -class RouterRegistrar extends RouteRegistrar +class RouterRegister extends RouteRegister { /** * Handle Route Registrar. diff --git a/src/Passport/PassportServiceProvider.php b/src/Passport/PassportServiceProvider.php index 3c008cf3..55dbe492 100644 --- a/src/Passport/PassportServiceProvider.php +++ b/src/Passport/PassportServiceProvider.php @@ -15,7 +15,7 @@ use Laravel\Passport\Console\InstallCommand; use Laravel\Passport\Console\KeysCommand; use Laravel\Passport\Passport; use Laravel\Passport\PassportServiceProvider as LaravelPassportServiceProvider; -use Notadd\Foundation\Passport\Listeners\RouterRegistrar; +use Notadd\Foundation\Passport\Listeners\RouterRegister; /** * Class PassportServiceProvider. @@ -27,7 +27,7 @@ class PassportServiceProvider extends LaravelPassportServiceProvider */ public function boot() { - $this->app->make(Dispatcher::class)->subscribe(RouterRegistrar::class); + $this->app->make(Dispatcher::class)->subscribe(RouterRegister::class); $this->commands([ ClientCommand::class, InstallCommand::class, diff --git a/src/Routing/Abstracts/RouteRegistrar.php b/src/Routing/Abstracts/RouteRegister.php similarity index 95% rename from src/Routing/Abstracts/RouteRegistrar.php rename to src/Routing/Abstracts/RouteRegister.php index 6747e9a5..463aac96 100644 --- a/src/Routing/Abstracts/RouteRegistrar.php +++ b/src/Routing/Abstracts/RouteRegister.php @@ -17,7 +17,7 @@ use Notadd\Foundation\Routing\Events\RouteRegister as RouteRegisterEvent; /** * Class AbstractRouteRegister. */ -abstract class RouteRegistrar extends EventSubscriber +abstract class RouteRegister extends EventSubscriber { /** * @var \Illuminate\Routing\Router diff --git a/src/SearchEngine/Listeners/RouterRegistrar.php b/src/SearchEngine/Listeners/RouterRegistrar.php index 56c14fad..c9feb338 100644 --- a/src/SearchEngine/Listeners/RouterRegistrar.php +++ b/src/SearchEngine/Listeners/RouterRegistrar.php @@ -8,13 +8,13 @@ */ namespace Notadd\Foundation\SearchEngine\Listeners; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; +use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; use Notadd\Foundation\SearchEngine\Controllers\SeoController; /** * Class RouterRegistrar. */ -class RouterRegistrar extends AbstractRouteRegistrar +class RouterRegister extends AbstractRouteRegister { /** * Handle Route Registrar. diff --git a/src/SearchEngine/SearchEngineServiceProvider.php b/src/SearchEngine/SearchEngineServiceProvider.php index 0cb80896..a763766a 100644 --- a/src/SearchEngine/SearchEngineServiceProvider.php +++ b/src/SearchEngine/SearchEngineServiceProvider.php @@ -11,7 +11,7 @@ namespace Notadd\Foundation\SearchEngine; use Illuminate\Events\Dispatcher; use Illuminate\Support\ServiceProvider; use Notadd\Foundation\SearchEngine\Listeners\CsrfTokenRegister; -use Notadd\Foundation\SearchEngine\Listeners\RouterRegistrar; +use Notadd\Foundation\SearchEngine\Listeners\RouterRegister; /** * Class SearchEngineServiceProvider. @@ -24,7 +24,7 @@ class SearchEngineServiceProvider extends ServiceProvider public function boot() { $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); - $this->app->make(Dispatcher::class)->subscribe(RouterRegistrar::class); + $this->app->make(Dispatcher::class)->subscribe(RouterRegister::class); } /** diff --git a/src/Setting/Listeners/RouteRegistrar.php b/src/Setting/Listeners/RouteRegistrar.php index 3af55b1f..f687200f 100644 --- a/src/Setting/Listeners/RouteRegistrar.php +++ b/src/Setting/Listeners/RouteRegistrar.php @@ -8,13 +8,13 @@ */ namespace Notadd\Foundation\Setting\Listeners; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; +use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; use Notadd\Foundation\Setting\Controllers\SettingController; /** * Class RouteRegistrar. */ -class RouteRegistrar extends AbstractRouteRegistrar +class RouteRegister extends AbstractRouteRegister { /** * Handle Route Registrar. diff --git a/src/Setting/SettingServiceProvider.php b/src/Setting/SettingServiceProvider.php index 6d09554c..ccc43781 100644 --- a/src/Setting/SettingServiceProvider.php +++ b/src/Setting/SettingServiceProvider.php @@ -11,7 +11,7 @@ namespace Notadd\Foundation\Setting; use Illuminate\Events\Dispatcher; use Illuminate\Support\ServiceProvider; use Notadd\Foundation\Setting\Listeners\CsrfTokenRegister; -use Notadd\Foundation\Setting\Listeners\RouteRegistrar; +use Notadd\Foundation\Setting\Listeners\RouteRegister; /** * Class SettingServiceProvider. @@ -24,7 +24,7 @@ class SettingServiceProvider extends ServiceProvider public function boot() { $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); - $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); } /** diff --git a/src/Sitemap/Listeners/RouteRegistrar.php b/src/Sitemap/Listeners/RouteRegistrar.php index 97d56ef9..cc4d3122 100644 --- a/src/Sitemap/Listeners/RouteRegistrar.php +++ b/src/Sitemap/Listeners/RouteRegistrar.php @@ -8,14 +8,13 @@ */ namespace Notadd\Foundation\Sitemap\Listeners; -use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; -use Notadd\Foundation\Setting\Controllers\SettingController; +use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; use Notadd\Foundation\Sitemap\Controllers\SitemapController; /** * Class RouteRegistrar. */ -class RouteRegistrar extends AbstractRouteRegistrar +class RouteRegister extends AbstractRouteRegister { /** * Handle Route Registrar. diff --git a/src/Sitemap/SitemapServiceProvider.php b/src/Sitemap/SitemapServiceProvider.php index 57676fbb..44f59330 100644 --- a/src/Sitemap/SitemapServiceProvider.php +++ b/src/Sitemap/SitemapServiceProvider.php @@ -14,7 +14,7 @@ use Notadd\Content\Models\Article; use Notadd\Foundation\Http\Events\RequestHandled; use Notadd\Foundation\Setting\Contracts\SettingsRepository; use Notadd\Foundation\Sitemap\Listeners\CsrfTokenRegister; -use Notadd\Foundation\Sitemap\Listeners\RouteRegistrar; +use Notadd\Foundation\Sitemap\Listeners\RouteRegister; /** * Class SitemapServiceProvider. @@ -42,7 +42,7 @@ class SitemapServiceProvider extends ServiceProvider } }); $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); - $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); } public function register() -- Gitee From 634592d1112d62ac832ff656b70440d66e95e003 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 3 Mar 2017 16:35:18 +0800 Subject: [PATCH 45/93] fix file name error --- .../Listeners/{RouteRegistrar.php => RouteRegister.php} | 0 src/Auth/Listeners/{RouteRegistrar.php => RouteRegister.php} | 0 src/Debug/Listeners/{RouteRegistrar.php => RouteRegister.php} | 0 src/Editor/Listeners/{RouteRegistrar.php => RouteRegister.php} | 0 src/Setting/Listeners/{RouteRegistrar.php => RouteRegister.php} | 0 src/Sitemap/Listeners/{RouteRegistrar.php => RouteRegister.php} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename src/Attachment/Listeners/{RouteRegistrar.php => RouteRegister.php} (100%) rename src/Auth/Listeners/{RouteRegistrar.php => RouteRegister.php} (100%) rename src/Debug/Listeners/{RouteRegistrar.php => RouteRegister.php} (100%) rename src/Editor/Listeners/{RouteRegistrar.php => RouteRegister.php} (100%) rename src/Setting/Listeners/{RouteRegistrar.php => RouteRegister.php} (100%) rename src/Sitemap/Listeners/{RouteRegistrar.php => RouteRegister.php} (100%) diff --git a/src/Attachment/Listeners/RouteRegistrar.php b/src/Attachment/Listeners/RouteRegister.php similarity index 100% rename from src/Attachment/Listeners/RouteRegistrar.php rename to src/Attachment/Listeners/RouteRegister.php diff --git a/src/Auth/Listeners/RouteRegistrar.php b/src/Auth/Listeners/RouteRegister.php similarity index 100% rename from src/Auth/Listeners/RouteRegistrar.php rename to src/Auth/Listeners/RouteRegister.php diff --git a/src/Debug/Listeners/RouteRegistrar.php b/src/Debug/Listeners/RouteRegister.php similarity index 100% rename from src/Debug/Listeners/RouteRegistrar.php rename to src/Debug/Listeners/RouteRegister.php diff --git a/src/Editor/Listeners/RouteRegistrar.php b/src/Editor/Listeners/RouteRegister.php similarity index 100% rename from src/Editor/Listeners/RouteRegistrar.php rename to src/Editor/Listeners/RouteRegister.php diff --git a/src/Setting/Listeners/RouteRegistrar.php b/src/Setting/Listeners/RouteRegister.php similarity index 100% rename from src/Setting/Listeners/RouteRegistrar.php rename to src/Setting/Listeners/RouteRegister.php diff --git a/src/Sitemap/Listeners/RouteRegistrar.php b/src/Sitemap/Listeners/RouteRegister.php similarity index 100% rename from src/Sitemap/Listeners/RouteRegistrar.php rename to src/Sitemap/Listeners/RouteRegister.php -- Gitee From 683445774a98649e0077ffadb0dbbcf440f55cdd Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 3 Mar 2017 16:39:35 +0800 Subject: [PATCH 46/93] fix file name errors --- src/Mail/Listeners/{RouterRegistrar.php => RouterRegister.php} | 0 .../Listeners/{RouterRegistrar.php => RouterRegister.php} | 0 .../Listeners/{RouterRegistrar.php => RouterRegister.php} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/Mail/Listeners/{RouterRegistrar.php => RouterRegister.php} (100%) rename src/Passport/Listeners/{RouterRegistrar.php => RouterRegister.php} (100%) rename src/SearchEngine/Listeners/{RouterRegistrar.php => RouterRegister.php} (100%) diff --git a/src/Mail/Listeners/RouterRegistrar.php b/src/Mail/Listeners/RouterRegister.php similarity index 100% rename from src/Mail/Listeners/RouterRegistrar.php rename to src/Mail/Listeners/RouterRegister.php diff --git a/src/Passport/Listeners/RouterRegistrar.php b/src/Passport/Listeners/RouterRegister.php similarity index 100% rename from src/Passport/Listeners/RouterRegistrar.php rename to src/Passport/Listeners/RouterRegister.php diff --git a/src/SearchEngine/Listeners/RouterRegistrar.php b/src/SearchEngine/Listeners/RouterRegister.php similarity index 100% rename from src/SearchEngine/Listeners/RouterRegistrar.php rename to src/SearchEngine/Listeners/RouterRegister.php -- Gitee From e88247b11272b3c15e8c227ff560e76c5cfc0d4d Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Mon, 6 Mar 2017 18:10:36 +0800 Subject: [PATCH 47/93] move code to attribute --- src/Passport/Abstracts/DataHandler.php | 5 +++++ src/Passport/Abstracts/SetHandler.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Passport/Abstracts/DataHandler.php b/src/Passport/Abstracts/DataHandler.php index 65827d56..5c84e129 100644 --- a/src/Passport/Abstracts/DataHandler.php +++ b/src/Passport/Abstracts/DataHandler.php @@ -16,6 +16,11 @@ use Notadd\Foundation\Passport\Responses\ApiResponse; */ abstract class DataHandler extends Handler { + /** + * @var int + */ + protected $code = 200; + /** * @var bool */ diff --git a/src/Passport/Abstracts/SetHandler.php b/src/Passport/Abstracts/SetHandler.php index 80dacd2d..069818c3 100644 --- a/src/Passport/Abstracts/SetHandler.php +++ b/src/Passport/Abstracts/SetHandler.php @@ -24,7 +24,7 @@ abstract class SetHandler extends DataHandler */ public function code() { - return 200; + return $this->code; } /** -- Gitee From fb280b34869237ced023103b27f9cc5746b3e7e6 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Tue, 7 Mar 2017 14:04:51 +0800 Subject: [PATCH 48/93] refactor to response with try and catch --- src/Passport/Abstracts/DataHandler.php | 19 +++++++++++++------ src/Passport/Abstracts/SetHandler.php | 22 +++++++++++++++------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Passport/Abstracts/DataHandler.php b/src/Passport/Abstracts/DataHandler.php index 5c84e129..3f4e2d4c 100644 --- a/src/Passport/Abstracts/DataHandler.php +++ b/src/Passport/Abstracts/DataHandler.php @@ -71,16 +71,23 @@ abstract class DataHandler extends Handler */ public function toResponse() { - $data = $this->data(); - if (empty($data)) { - $messages = $this->errors(); - } else { - $messages = $this->messages(); + try { + $code = $this->code(); + $data = $this->data(); + if (empty($data)) { + $messages = $this->errors(); + } else { + $messages = $this->messages(); + } + } catch (Exception $exception) { + $code = $exception->getCode(); + $data = $exception->getTrace(); + $messages = $exception->getMessage(); } $response = new ApiResponse(); return $response->withParams([ - 'code' => $this->code(), + 'code' => $code, 'data' => $data, 'message' => $messages, ]); diff --git a/src/Passport/Abstracts/SetHandler.php b/src/Passport/Abstracts/SetHandler.php index 069818c3..d05b722e 100644 --- a/src/Passport/Abstracts/SetHandler.php +++ b/src/Passport/Abstracts/SetHandler.php @@ -56,17 +56,25 @@ abstract class SetHandler extends DataHandler */ public function toResponse() { - $result = $this->execute(); - if ($result) { - $messages = $this->messages(); - } else { - $messages = $this->errors(); + try { + $result = $this->execute(); + if ($result) { + $messages = $this->messages(); + } else { + $messages = $this->errors(); + } + $code = $this->code(); + $data = $this->data(); + } catch (Exception $exception) { + $code = $exception->getCode(); + $data = $exception->getTrace(); + $messages = $exception->getMessage(); } $response = new ApiResponse(); return $response->withParams([ - 'code' => $this->code(), - 'data' => $this->data(), + 'code' => $code, + 'data' => $data, 'message' => $messages, ]); } -- Gitee From 84ee368e4c4027e1181a708af21fa6d96f70567b Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Tue, 7 Mar 2017 14:58:20 +0800 Subject: [PATCH 49/93] get response status from custom params --- src/Passport/Responses/ApiResponse.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Passport/Responses/ApiResponse.php b/src/Passport/Responses/ApiResponse.php index 9b6668d6..f90715a6 100644 --- a/src/Passport/Responses/ApiResponse.php +++ b/src/Passport/Responses/ApiResponse.php @@ -33,7 +33,8 @@ class ApiResponse { is_null($response) && $response = new Response(); $params && $this->params = array_merge($this->params, $params); - $response = $response->withStatus(200) + $status = collect($this->params)->get('code', 200); + $response = $response->withStatus($status) ->withHeader('pragma', 'no-cache') ->withHeader('cache-control', 'no-store') ->withHeader('content-type', 'application/json; charset=UTF-8'); -- Gitee From 9a29c5831e2d839d92cfb518e0e707017d9243af Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Tue, 7 Mar 2017 15:02:44 +0800 Subject: [PATCH 50/93] using trace instead of data --- src/Passport/Abstracts/DataHandler.php | 23 ++++++++++++----------- src/Passport/Abstracts/SetHandler.php | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/Passport/Abstracts/DataHandler.php b/src/Passport/Abstracts/DataHandler.php index 3f4e2d4c..a099d92b 100644 --- a/src/Passport/Abstracts/DataHandler.php +++ b/src/Passport/Abstracts/DataHandler.php @@ -71,25 +71,26 @@ abstract class DataHandler extends Handler */ public function toResponse() { + $response = new ApiResponse(); try { - $code = $this->code(); $data = $this->data(); if (empty($data)) { $messages = $this->errors(); } else { $messages = $this->messages(); } + + return $response->withParams([ + 'code' => $this->code(), + 'data' => $data, + 'message' => $messages, + ]); } catch (Exception $exception) { - $code = $exception->getCode(); - $data = $exception->getTrace(); - $messages = $exception->getMessage(); + return $response->withParams([ + 'code' => $exception->getCode(), + 'message' => $exception->getMessage(), + 'trace' => $exception->getTrace(), + ]); } - $response = new ApiResponse(); - - return $response->withParams([ - 'code' => $code, - 'data' => $data, - 'message' => $messages, - ]); } } diff --git a/src/Passport/Abstracts/SetHandler.php b/src/Passport/Abstracts/SetHandler.php index d05b722e..3c4c4cea 100644 --- a/src/Passport/Abstracts/SetHandler.php +++ b/src/Passport/Abstracts/SetHandler.php @@ -56,6 +56,7 @@ abstract class SetHandler extends DataHandler */ public function toResponse() { + $response = new ApiResponse(); try { $result = $this->execute(); if ($result) { @@ -63,19 +64,18 @@ abstract class SetHandler extends DataHandler } else { $messages = $this->errors(); } - $code = $this->code(); - $data = $this->data(); + + return $response->withParams([ + 'code' => $this->code(), + 'data' => $this->data(), + 'message' => $messages, + ]); } catch (Exception $exception) { - $code = $exception->getCode(); - $data = $exception->getTrace(); - $messages = $exception->getMessage(); + return $response->withParams([ + 'code' => $exception->getCode(), + 'message' => $exception->getMessage(), + 'trace' => $exception->getTrace(), + ]); } - $response = new ApiResponse(); - - return $response->withParams([ - 'code' => $code, - 'data' => $data, - 'message' => $messages, - ]); } } -- Gitee From 2961a7acee283766c07effdbf66c07b6e0804551 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Tue, 7 Mar 2017 15:28:29 +0800 Subject: [PATCH 51/93] fix errors on issue token --- src/Editor/Controllers/UEditorController.php | 2 +- .../Controllers/AccessTokenController.php | 23 +------------------ 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/Editor/Controllers/UEditorController.php b/src/Editor/Controllers/UEditorController.php index 9d4fb6da..190dd171 100644 --- a/src/Editor/Controllers/UEditorController.php +++ b/src/Editor/Controllers/UEditorController.php @@ -41,7 +41,7 @@ class UEditorController extends Controller public function __construct() { parent::__construct(); - $this->image = $this->container->make('image'); + $this->image = $this->container->make('images'); $this->setting = $this->getSetting(); $this->config(); } diff --git a/src/Passport/Controllers/AccessTokenController.php b/src/Passport/Controllers/AccessTokenController.php index 325c6b97..ca4568fd 100644 --- a/src/Passport/Controllers/AccessTokenController.php +++ b/src/Passport/Controllers/AccessTokenController.php @@ -93,29 +93,8 @@ class AccessTokenController extends Controller */ public function issueToken(ServerRequestInterface $request) { - $response = $this->withErrorHandling(function () use ($request) { + return $this->withErrorHandling(function () use ($request) { return $this->server->respondToAccessTokenRequest($request, new Psr7Response()); }); - if ($response->getStatusCode() < 200 || $response->getStatusCode() > 299) { - return $response; - } - $payload = json_decode($response->getBody()->__toString(), true); - if (isset($payload['access_token'])) { - $this->revokeOtherAccessTokens($payload); - } - - return $response; - } - - /** - * Revoke other access tokens handler. - * - * @param array $payload - */ - protected function revokeOtherAccessTokens(array $payload) - { - $token = $this->tokens->find($tokenId = $this->jwt->parse($payload['access_token'])->getClaim('jti')); - $this->tokens->revokeOtherAccessTokens($token->client_id, $token->user_id, $tokenId, - Passport::$pruneRevokedTokens); } } -- Gitee From dc4ec8cd6bcabfdd0c7db0333953159a04d9442b Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Tue, 7 Mar 2017 15:32:02 +0800 Subject: [PATCH 52/93] move alias definition to Application --- src/Application.php | 9 +++++---- src/Image/ImageServiceProvider.php | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Application.php b/src/Application.php index 2bc02e57..5c93271b 100644 --- a/src/Application.php +++ b/src/Application.php @@ -1088,10 +1088,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn 'filesystem.disk' => [\Illuminate\Contracts\Filesystem\Filesystem::class], 'filesystem.cloud' => [\Illuminate\Contracts\Filesystem\Cloud::class], 'hash' => [\Illuminate\Contracts\Hashing\Hasher::class], - 'translator' => [ - \Illuminate\Translation\Translator::class, - \Illuminate\Contracts\Translation\Translator::class, - ], + 'images' => [\Notadd\Foundation\Image\ImageManager::class], 'log' => [ \Illuminate\Log\Writer::class, \Illuminate\Contracts\Logging\Log::class, @@ -1135,6 +1132,10 @@ class Application extends Container implements ApplicationContract, HttpKernelIn ], 'setting' => [\Notadd\Foundation\Setting\Contracts\SettingsRepository::class], 'theme' => [\Notadd\Foundation\Theme\ThemeManager::class], + 'translator' => [ + \Illuminate\Translation\Translator::class, + \Illuminate\Contracts\Translation\Translator::class, + ], 'url' => [ \Illuminate\Routing\UrlGenerator::class, \Illuminate\Contracts\Routing\UrlGenerator::class, diff --git a/src/Image/ImageServiceProvider.php b/src/Image/ImageServiceProvider.php index ccbee6d1..703de569 100644 --- a/src/Image/ImageServiceProvider.php +++ b/src/Image/ImageServiceProvider.php @@ -54,7 +54,6 @@ class ImageServiceProvider extends ServiceProvider $this->app->singleton('images', function () { return new ImageManager($this->app['config']->get('image')); }); - $this->app->alias('image', 'Notadd\Foundation\Image\ImageManager'); } /** -- Gitee From 73593e184ae1fbe901c144ae976613d6b197b3da Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Tue, 7 Mar 2017 16:39:03 +0800 Subject: [PATCH 53/93] fix some errors --- .../Controllers/AuthorizationController.php | 4 ++-- src/Passport/Controllers/ClientsController.php | 14 ++++++++++---- src/Passport/Traits/PassportHelpers.php | 17 ----------------- 3 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 src/Passport/Traits/PassportHelpers.php diff --git a/src/Passport/Controllers/AuthorizationController.php b/src/Passport/Controllers/AuthorizationController.php index 47e3f322..3843e5f9 100644 --- a/src/Passport/Controllers/AuthorizationController.php +++ b/src/Passport/Controllers/AuthorizationController.php @@ -108,8 +108,8 @@ class AuthorizationController extends Controller */ public function store() { - return $this->withErrorHandling(function () use ($request) { - $authRequest = $this->getAuthRequestFromSession($request); + return $this->withErrorHandling(function () { + $authRequest = $this->getAuthRequestFromSession($this->request); return $this->server->completeAuthorizationRequest($authRequest, new Psr7Response()); }); diff --git a/src/Passport/Controllers/ClientsController.php b/src/Passport/Controllers/ClientsController.php index 7745d0b1..a34fc77d 100644 --- a/src/Passport/Controllers/ClientsController.php +++ b/src/Passport/Controllers/ClientsController.php @@ -83,8 +83,11 @@ class ClientsController extends Controller 'redirect' => 'required|url', ])->validate(); - return $this->clients->create($this->request->user()->getKey(), $this->request->name, - $this->request->redirect)->makeVisible('secret'); + return $this->clients->create( + $this->request->user()->getKey(), + $this->request->name, + $this->request->redirect + )->makeVisible('secret'); } /** @@ -98,13 +101,16 @@ class ClientsController extends Controller public function update($clientId) { if (!$this->request->user()->clients->find($clientId)) { - return new Response('', 404); + return new Response('User not found!', 404); } $this->validation->make($this->request->all(), [ 'name' => 'required|max:255', 'redirect' => 'required|url', ])->validate(); - return $this->clients->update($this->request->user()->clients->find($clientId), $this->request->name, $this->request->redirect); + return $this->clients->update( + $this->request->user()->clients->find($clientId), + $this->request->name, $this->request->redirect + ); } } diff --git a/src/Passport/Traits/PassportHelpers.php b/src/Passport/Traits/PassportHelpers.php deleted file mode 100644 index fc53ea23..00000000 --- a/src/Passport/Traits/PassportHelpers.php +++ /dev/null @@ -1,17 +0,0 @@ - - * @copyright (c) 2017, iBenchu.org - * @datetime 2017-01-08 20:07 - */ -namespace Notadd\Foundation\Passport\Traits; - -/** - * Class PassportHelpers. - */ -trait PassportHelpers -{ - -} -- Gitee From 7569e519df5aed627d47afc33e8e21d711166f6f Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Tue, 7 Mar 2017 17:25:00 +0800 Subject: [PATCH 54/93] fix asset path --- src/Editor/Controllers/UEditorController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Editor/Controllers/UEditorController.php b/src/Editor/Controllers/UEditorController.php index 190dd171..70124c00 100644 --- a/src/Editor/Controllers/UEditorController.php +++ b/src/Editor/Controllers/UEditorController.php @@ -102,7 +102,7 @@ class UEditorController extends Controller 'fileManagerUrlPrefix' => '', 'fileManagerListSize' => 20, 'fileManagerAllowFiles' => $this->setting->get('attachment.manager.image'), - 'watermark' => public_path($this->setting->get('attachment.watermark.file', '.png,.jpg,.jpeg,.gif,.bmp,.flv,.swf,.mkv,.avi,.rm,.rmvb,.mpeg,.mpg,.ogg,.ogv,.mov,.wmv,.mp4,.webm,.mp3,.wav,.mid,.rar,.zip,.tar,.gz,.7z,.bz2,.cab,.iso,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.txt,.md,.xml')), + 'watermark' => asset($this->setting->get('attachment.watermark.file', 'watermark.png')), ]; } -- Gitee From 59098c4f94a52fc410bae92aab038891a6306874 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 8 Mar 2017 12:04:20 +0800 Subject: [PATCH 55/93] rename name to identification --- src/Module/Commands/ListCommand.php | 2 +- src/Module/Handlers/ModuleHandler.php | 2 +- src/Module/Module.php | 14 +++++++------- src/Module/ModuleManager.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Module/Commands/ListCommand.php b/src/Module/Commands/ListCommand.php index 603fde7c..472b9f1d 100644 --- a/src/Module/Commands/ListCommand.php +++ b/src/Module/Commands/ListCommand.php @@ -53,7 +53,7 @@ class ListCommand extends Command $this->info('Extensions list:'); $modules->each(function (Module $module, $path) use ($list) { $list->push([ - $module->getName(), + $module->getIdentification(), collect($module->getAuthor())->first(), $module->getDescription(), $path, diff --git a/src/Module/Handlers/ModuleHandler.php b/src/Module/Handlers/ModuleHandler.php index d96beac7..a64f104a 100644 --- a/src/Module/Handlers/ModuleHandler.php +++ b/src/Module/Handlers/ModuleHandler.php @@ -60,7 +60,7 @@ class ModuleHandler extends DataHandler 'author' => $module->getAuthor(), 'enabled' => $module->isEnabled(), 'description' => $module->getDescription(), - 'name' => $module->getName(), + 'name' => $module->getIdentification(), ]; }); diff --git a/src/Module/Module.php b/src/Module/Module.php index 7ba4db3f..f7701ebb 100644 --- a/src/Module/Module.php +++ b/src/Module/Module.php @@ -46,7 +46,7 @@ class Module /** * @var string */ - protected $name; + protected $identification; /** * @var string @@ -65,7 +65,7 @@ class Module */ public function __construct($name = null) { - $this->name = $name; + $this->identification = $name; } /** @@ -113,9 +113,9 @@ class Module * * @return string */ - public function getName() + public function getIdentification() { - return $this->name; + return $this->identification; } /** @@ -227,11 +227,11 @@ class Module /** * Set module's name. * - * @param string $name + * @param string $identification */ - public function setName($name) + public function setIdentification($identification) { - $this->name = $name; + $this->identification = $identification; } /** diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index 8fa50c28..c2165ca7 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -68,7 +68,7 @@ class ModuleManager return $list; } $this->modules->each(function (Module $module) use ($list) { - $module->isEnabled() && $list->put($module->getName(), $module); + $module->isEnabled() && $list->put($module->getIdentification(), $module); }); return $list; -- Gitee From 4bcb7a5a4bb5cfa1678ab4de4ba15a458615d430 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 8 Mar 2017 12:16:47 +0800 Subject: [PATCH 56/93] add name info for module --- src/Module/Module.php | 31 +++++++++++++++++++++++++--- src/Module/ModuleServiceProvider.php | 6 ------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/Module/Module.php b/src/Module/Module.php index f7701ebb..cc2543eb 100644 --- a/src/Module/Module.php +++ b/src/Module/Module.php @@ -38,6 +38,11 @@ class Module */ protected $entry; + /** + * @var string + */ + protected $identification; + /** * @var bool */ @@ -46,7 +51,7 @@ class Module /** * @var string */ - protected $identification; + protected $name; /** * @var string @@ -109,7 +114,7 @@ class Module } /** - * Name of module. + * Identification of module. * * @return string */ @@ -118,6 +123,16 @@ class Module return $this->identification; } + /** + * Name of module. + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + /** * Script of module. * @@ -225,7 +240,7 @@ class Module } /** - * Set module's name. + * Set module's identification. * * @param string $identification */ @@ -234,6 +249,16 @@ class Module $this->identification = $identification; } + /** + * Set module's name. + * + * @param string $name + */ + public function setName(string $name) + { + $this->name = $name; + } + /** * Set module's script. * diff --git a/src/Module/ModuleServiceProvider.php b/src/Module/ModuleServiceProvider.php index a2a44560..462f7436 100644 --- a/src/Module/ModuleServiceProvider.php +++ b/src/Module/ModuleServiceProvider.php @@ -47,12 +47,6 @@ class ModuleServiceProvider extends ServiceProvider $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); $this->app->make(ModuleManager::class)->getModules()->each(function (Module $module) { $path = $module->getDirectory(); - if ($this->files->isDirectory($path)) { - if(is_string($module->getEntry()) && class_exists($module->getEntry())) { - $this->app->register($module->getEntry()); - } else { - } - } if ($this->files->isDirectory($path) && is_string($module->getEntry())) { if (!class_exists($module->getEntry())) { if ($this->files->exists($autoload = $path . DIRECTORY_SEPARATOR . 'vendor' .DIRECTORY_SEPARATOR . 'autoload.php')) { -- Gitee From 17c870eb6ba23a3774d097e1a9a3eadd3a003528 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 8 Mar 2017 12:22:32 +0800 Subject: [PATCH 57/93] checking class exists on listing modules --- src/Module/ModuleManager.php | 12 +++++++++++- src/Module/ModuleServiceProvider.php | 10 ---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index c2165ca7..797eaa39 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -111,9 +111,19 @@ class ModuleManager if ($entries = data_get($package, 'autoload.psr-4')) { foreach ($entries as $namespace => $entry) { $provider = $namespace . 'ModuleServiceProvider'; - $module->setEntry($provider); } } + if (!class_exists($module->getEntry())) { + if ($this->files->exists($autoload = $directory . DIRECTORY_SEPARATOR . 'vendor' .DIRECTORY_SEPARATOR . 'autoload.php')) { + $this->files->requireOnce($autoload); + if (!class_exists($module->getEntry())) { + throw new \Exception('Module load fail!'); + } + } else { + throw new \Exception('Module load fail!'); + } + } + $module->setEntry($provider); method_exists($provider, 'script') && $module->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $module->setStylesheet(call_user_func([$provider, 'stylesheet'])); $this->modules->put($name, $module); diff --git a/src/Module/ModuleServiceProvider.php b/src/Module/ModuleServiceProvider.php index 462f7436..420d9053 100644 --- a/src/Module/ModuleServiceProvider.php +++ b/src/Module/ModuleServiceProvider.php @@ -48,16 +48,6 @@ class ModuleServiceProvider extends ServiceProvider $this->app->make(ModuleManager::class)->getModules()->each(function (Module $module) { $path = $module->getDirectory(); if ($this->files->isDirectory($path) && is_string($module->getEntry())) { - if (!class_exists($module->getEntry())) { - if ($this->files->exists($autoload = $path . DIRECTORY_SEPARATOR . 'vendor' .DIRECTORY_SEPARATOR . 'autoload.php')) { - $this->files->requireOnce($autoload); - if (!class_exists($module->getEntry())) { - throw new \Exception('Module load fail!'); - } - } else { - throw new \Exception('Module load fail!'); - } - } $this->app->register($module->getEntry()); } }); -- Gitee From 0d484311f9c34d153441b12714fe1334351a4229 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 8 Mar 2017 12:31:53 +0800 Subject: [PATCH 58/93] rename name to identification for extension --- src/Extension/Commands/ListCommand.php | 2 +- src/Extension/Extension.php | 27 ++++++++++++++++++--- src/Extension/ExtensionManager.php | 10 ++++---- src/Extension/Handlers/ExtensionHandler.php | 2 +- src/Module/ModuleManager.php | 10 ++++---- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/Extension/Commands/ListCommand.php b/src/Extension/Commands/ListCommand.php index c46fe24c..494bfb7e 100644 --- a/src/Extension/Commands/ListCommand.php +++ b/src/Extension/Commands/ListCommand.php @@ -57,7 +57,7 @@ class ListCommand extends Command $author = $data->get('name'); $data->has('email') ? $author .= ' <' . $data->get('email') . '>' : null; $list->push([ - $extension->getName(), + $extension->getIdentification(), $author, $extension->getDescription(), $path, diff --git a/src/Extension/Extension.php b/src/Extension/Extension.php index 1e6ff8e5..5917ce57 100644 --- a/src/Extension/Extension.php +++ b/src/Extension/Extension.php @@ -38,6 +38,11 @@ class Extension */ protected $entry; + /** + * @var string + */ + protected $identification; + /** * @var bool */ @@ -71,11 +76,11 @@ class Extension /** * Extension constructor. * - * @param string $name + * @param string $identification */ - public function __construct($name) + public function __construct($identification) { - $this->name = $name; + $this->identification = $identification; } /** @@ -112,6 +117,14 @@ class Extension return $this->entry; } + /** + * @return string + */ + public function getIdentification(): string + { + return $this->identification; + } + /** * @return string */ @@ -228,6 +241,14 @@ class Extension $this->installed = $installed; } + /** + * @param string $identification + */ + public function setIdentification(string $identification) + { + $this->identification = $identification; + } + /** * @param string $name */ diff --git a/src/Extension/ExtensionManager.php b/src/Extension/ExtensionManager.php index 540080d4..7f3dc166 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -107,14 +107,14 @@ class ExtensionManager collect($this->files->directories($vendor))->each(function ($directory) { if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) { $package = new Collection(json_decode($this->files->get($file), true)); - $name = Arr::get($package, 'name'); + $identification = Arr::get($package, 'name'); $type = Arr::get($package, 'type'); - if ($type == 'notadd-extension' && $name) { - $extension = new Extension($name); + if ($type == 'notadd-extension' && $identification) { + $extension = new Extension($identification); $extension->setAuthor(Arr::get($package, 'authors')); $extension->setDescription(Arr::get($package, 'description')); $extension->setDirectory($directory); - $extension->setEnabled($this->container->make('setting')->get('extension.' . $name . '.enabled', false)); + $extension->setEnabled($this->container->make('setting')->get('extension.' . $identification . '.enabled', false)); $provider = ''; if ($entries = data_get($package, 'autoload.psr-4')) { foreach ($entries as $namespace => $entry) { @@ -124,7 +124,7 @@ class ExtensionManager } method_exists($provider, 'script') && $extension->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $extension->setStylesheet(call_user_func([$provider, 'stylesheet'])); - $this->extensions->put($name, $extension); + $this->extensions->put($identification, $extension); } } }); diff --git a/src/Extension/Handlers/ExtensionHandler.php b/src/Extension/Handlers/ExtensionHandler.php index 65d32f82..ac82d2a1 100644 --- a/src/Extension/Handlers/ExtensionHandler.php +++ b/src/Extension/Handlers/ExtensionHandler.php @@ -61,7 +61,7 @@ class ExtensionHandler extends DataHandler 'author' => $extension->getAuthor(), 'enabled' => $extension->isEnabled(), 'description' => $extension->getDescription(), - 'name' => $extension->getName(), + 'name' => $extension->getIdentification(), ]; }); diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index 797eaa39..30a42b17 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -98,14 +98,14 @@ class ModuleManager collect($this->files->directories($this->getModulePath()))->each(function ($directory) { if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) { $package = new Collection(json_decode($this->files->get($file), true)); - $name = Arr::get($package, 'name'); + $identification = Arr::get($package, 'name'); $type = Arr::get($package, 'type'); - if ($type == 'notadd-module' && $name) { - $module = new Module($name); + if ($type == 'notadd-module' && $identification) { + $module = new Module($identification); $module->setAuthor(Arr::get($package, 'authors')); $module->setDescription(Arr::get($package, 'description')); $module->setDirectory($directory); - $status = $this->container->isInstalled() ? $this->container->make('setting')->get('module.' . $name . '.enabled', false) : false; + $status = $this->container->isInstalled() ? $this->container->make('setting')->get('module.' . $identification . '.enabled', false) : false; $module->setEnabled($status); $provider = ''; if ($entries = data_get($package, 'autoload.psr-4')) { @@ -126,7 +126,7 @@ class ModuleManager $module->setEntry($provider); method_exists($provider, 'script') && $module->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $module->setStylesheet(call_user_func([$provider, 'stylesheet'])); - $this->modules->put($name, $module); + $this->modules->put($identification, $module); } } }); -- Gitee From 1da3e26fa099e73fa964e7e9dc52e267a9c2dee9 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 8 Mar 2017 12:33:32 +0800 Subject: [PATCH 59/93] checking class exists on listing extensions --- src/Extension/ExtensionManager.php | 12 +++++++++++- src/Extension/ExtensionServiceProvider.php | 10 ---------- src/Module/ModuleManager.php | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Extension/ExtensionManager.php b/src/Extension/ExtensionManager.php index 7f3dc166..502f47c4 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -119,9 +119,19 @@ class ExtensionManager if ($entries = data_get($package, 'autoload.psr-4')) { foreach ($entries as $namespace => $entry) { $provider = $namespace . 'Extension'; - $extension->setEntry($provider); } } + if (!class_exists($provider)) { + if ($this->files->exists($autoload = $directory . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php')) { + $this->files->requireOnce($autoload); + if (!class_exists($provider)) { + throw new \Exception('Extension load fail!'); + } + } else { + throw new \Exception('Extension load fail!'); + } + } + $extension->setEntry($provider); method_exists($provider, 'script') && $extension->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $extension->setStylesheet(call_user_func([$provider, 'stylesheet'])); $this->extensions->put($identification, $extension); diff --git a/src/Extension/ExtensionServiceProvider.php b/src/Extension/ExtensionServiceProvider.php index 5d60d9c4..2578547e 100644 --- a/src/Extension/ExtensionServiceProvider.php +++ b/src/Extension/ExtensionServiceProvider.php @@ -49,16 +49,6 @@ class ExtensionServiceProvider extends ServiceProvider $this->app->make(ExtensionManager::class)->getExtensions()->each(function (Extension $extension) { $path = $extension->getDirectory(); if ($this->files->isDirectory($path) && is_string($extension->getEntry())) { - if (!class_exists($extension->getEntry())) { - if ($this->files->exists($autoload = $path . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php')) { - $this->files->requireOnce($autoload); - if (!class_exists($extension->getEntry())) { - throw new \Exception('Extension load fail!'); - } - } else { - throw new \Exception('Extension load fail!'); - } - } $this->app->register($extension->getEntry()); } }); diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index 30a42b17..3d5e4306 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -113,10 +113,10 @@ class ModuleManager $provider = $namespace . 'ModuleServiceProvider'; } } - if (!class_exists($module->getEntry())) { + if (!class_exists($provider)) { if ($this->files->exists($autoload = $directory . DIRECTORY_SEPARATOR . 'vendor' .DIRECTORY_SEPARATOR . 'autoload.php')) { $this->files->requireOnce($autoload); - if (!class_exists($module->getEntry())) { + if (!class_exists($provider)) { throw new \Exception('Module load fail!'); } } else { -- Gitee From e6f7e71cd0cbf933d6d81eeb5bc80e148c7c1062 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 8 Mar 2017 15:13:25 +0800 Subject: [PATCH 60/93] load name and description from provider --- src/Extension/ExtensionManager.php | 2 ++ src/Module/ModuleManager.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Extension/ExtensionManager.php b/src/Extension/ExtensionManager.php index 502f47c4..0d7d15c2 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -132,6 +132,8 @@ class ExtensionManager } } $extension->setEntry($provider); + method_exists($provider, 'description') && $extension->setDescription(call_user_func([$provider, 'description'])); + method_exists($provider, 'name') && $extension->setName(call_user_func([$provider, 'name'])); method_exists($provider, 'script') && $extension->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $extension->setStylesheet(call_user_func([$provider, 'stylesheet'])); $this->extensions->put($identification, $extension); diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index 3d5e4306..ead3f243 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -124,6 +124,8 @@ class ModuleManager } } $module->setEntry($provider); + method_exists($provider, 'description') && $module->setDescription(call_user_func([$provider, 'description'])); + method_exists($provider, 'name') && $module->setName(call_user_func([$provider, 'name'])); method_exists($provider, 'script') && $module->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $module->setStylesheet(call_user_func([$provider, 'stylesheet'])); $this->modules->put($identification, $module); -- Gitee From 42edc9cbaeb9c49c153f478b9c06562f530e5564 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 8 Mar 2017 15:15:36 +0800 Subject: [PATCH 61/93] must provider name and description info --- src/Extension/Abstracts/Extension.php | 14 ++++++++++++++ src/Module/Abstracts/Module.php | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Extension/Abstracts/Extension.php b/src/Extension/Abstracts/Extension.php index 0aeddf16..366280a9 100644 --- a/src/Extension/Abstracts/Extension.php +++ b/src/Extension/Abstracts/Extension.php @@ -43,6 +43,13 @@ abstract class Extension extends ServiceProvider */ abstract public function boot(); + /** + * Description of extension + * + * @return string + */ + abstract public function description(); + /** * Install extension. * @@ -50,6 +57,13 @@ abstract class Extension extends ServiceProvider */ abstract public function install(); + /** + * Name of extension. + * + * @return string + */ + abstract public function name(); + /** * Register extension extra providers. */ diff --git a/src/Module/Abstracts/Module.php b/src/Module/Abstracts/Module.php index 38e7917b..10886ba3 100644 --- a/src/Module/Abstracts/Module.php +++ b/src/Module/Abstracts/Module.php @@ -43,6 +43,13 @@ abstract class Module extends ServiceProvider */ abstract public function boot(); + /** + * Description of module + * + * @return string + */ + abstract public function description(); + /** * Install module. * @@ -50,6 +57,13 @@ abstract class Module extends ServiceProvider */ abstract public function install(); + /** + * Name of module. + * + * @return string + */ + abstract public function name(); + /** * Register module extra providers. */ -- Gitee From a890b58605dd7ddb7ec94d308e56a42c0b24647b Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 8 Mar 2017 15:45:23 +0800 Subject: [PATCH 62/93] fix static method calling --- src/Module/Abstracts/Module.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Module/Abstracts/Module.php b/src/Module/Abstracts/Module.php index 10886ba3..d2a6a666 100644 --- a/src/Module/Abstracts/Module.php +++ b/src/Module/Abstracts/Module.php @@ -48,7 +48,7 @@ abstract class Module extends ServiceProvider * * @return string */ - abstract public function description(); + abstract public static function description(); /** * Install module. @@ -62,7 +62,7 @@ abstract class Module extends ServiceProvider * * @return string */ - abstract public function name(); + abstract public static function name(); /** * Register module extra providers. -- Gitee From eebcef0846550cad101da625f8f5b3dac8d00470 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Wed, 8 Mar 2017 15:57:56 +0800 Subject: [PATCH 63/93] differentiate name and identification --- src/Extension/Handlers/ExtensionHandler.php | 3 ++- src/Module/Handlers/ModuleHandler.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Extension/Handlers/ExtensionHandler.php b/src/Extension/Handlers/ExtensionHandler.php index ac82d2a1..07f2c3f9 100644 --- a/src/Extension/Handlers/ExtensionHandler.php +++ b/src/Extension/Handlers/ExtensionHandler.php @@ -61,7 +61,8 @@ class ExtensionHandler extends DataHandler 'author' => $extension->getAuthor(), 'enabled' => $extension->isEnabled(), 'description' => $extension->getDescription(), - 'name' => $extension->getIdentification(), + 'identification' => $extension->getIdentification(), + 'name' => $extension->getName(), ]; }); diff --git a/src/Module/Handlers/ModuleHandler.php b/src/Module/Handlers/ModuleHandler.php index a64f104a..3dac9771 100644 --- a/src/Module/Handlers/ModuleHandler.php +++ b/src/Module/Handlers/ModuleHandler.php @@ -60,7 +60,8 @@ class ModuleHandler extends DataHandler 'author' => $module->getAuthor(), 'enabled' => $module->isEnabled(), 'description' => $module->getDescription(), - 'name' => $module->getIdentification(), + 'identification' => $module->getIdentification(), + 'name' => $module->getName(), ]; }); -- Gitee From 64033d3d631d33b1d3b5aef005916e5f33fd2e09 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 17:54:27 +0800 Subject: [PATCH 64/93] static method install and uninstall --- src/Extension/Abstracts/Extension.php | 4 ++-- src/Module/Abstracts/Module.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Extension/Abstracts/Extension.php b/src/Extension/Abstracts/Extension.php index 366280a9..fd092342 100644 --- a/src/Extension/Abstracts/Extension.php +++ b/src/Extension/Abstracts/Extension.php @@ -55,7 +55,7 @@ abstract class Extension extends ServiceProvider * * @return bool */ - abstract public function install(); + abstract public static function install(); /** * Name of extension. @@ -76,5 +76,5 @@ abstract class Extension extends ServiceProvider * * @return mixed */ - abstract public function uninstall(); + abstract public static function uninstall(); } diff --git a/src/Module/Abstracts/Module.php b/src/Module/Abstracts/Module.php index d2a6a666..4571a90f 100644 --- a/src/Module/Abstracts/Module.php +++ b/src/Module/Abstracts/Module.php @@ -55,7 +55,7 @@ abstract class Module extends ServiceProvider * * @return bool */ - abstract public function install(); + abstract public static function install(); /** * Name of module. @@ -76,5 +76,5 @@ abstract class Module extends ServiceProvider * * @return mixed */ - abstract public function uninstall(); + abstract public static function uninstall(); } -- Gitee From ed4f82fbfff194b1081c0abf5ed3df37cc3000be Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 17:55:04 +0800 Subject: [PATCH 65/93] correct method type for module extension --- src/Extension/Abstracts/Extension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Extension/Abstracts/Extension.php b/src/Extension/Abstracts/Extension.php index fd092342..22308a69 100644 --- a/src/Extension/Abstracts/Extension.php +++ b/src/Extension/Abstracts/Extension.php @@ -48,7 +48,7 @@ abstract class Extension extends ServiceProvider * * @return string */ - abstract public function description(); + abstract public static function description(); /** * Install extension. @@ -62,7 +62,7 @@ abstract class Extension extends ServiceProvider * * @return string */ - abstract public function name(); + abstract public static function name(); /** * Register extension extra providers. -- Gitee From 78cc0f0c7c711fa7bad7f19f7ebed5c6e265400f Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 18:03:52 +0800 Subject: [PATCH 66/93] add install logic for extension --- src/Extension/Abstracts/Installer.php | 52 +++++++++++++++++++++++ src/Extension/Handlers/InstallHandler.php | 10 +++-- 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 src/Extension/Abstracts/Installer.php diff --git a/src/Extension/Abstracts/Installer.php b/src/Extension/Abstracts/Installer.php new file mode 100644 index 00000000..352c8e95 --- /dev/null +++ b/src/Extension/Abstracts/Installer.php @@ -0,0 +1,52 @@ +container = $container; + } + + /** + * @return bool + */ + abstract public function handle(); + + /** + * @return bool + */ + public function install() + { + if (!$this->require()) { + return false; + } + return $this->handle(); + } + + /** + * @return bool + */ + abstract public function require(); +} diff --git a/src/Extension/Handlers/InstallHandler.php b/src/Extension/Handlers/InstallHandler.php index 3cecc1cf..da8e0641 100644 --- a/src/Extension/Handlers/InstallHandler.php +++ b/src/Extension/Handlers/InstallHandler.php @@ -54,11 +54,15 @@ class InstallHandler extends SetHandler public function execute() { $extension = $this->manager->get($this->request->input('name')); - if ($extension && method_exists($provider = $extension->getEntry(), 'install')) { - return call_user_func([ + if ($extension && method_exists($provider = $extension->getEntry(), 'install') && $class = call_user_func([ $provider, 'install', - ]); + ]) + ) { + if (class_exists($class)) { + $installer = $this->container->make($class); + return $installer->install(); + } } return false; -- Gitee From 228fc72d7b7b907d831a493fb9a12f0b9a788e8e Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 18:09:03 +0800 Subject: [PATCH 67/93] add install logic for module --- src/Extension/Handlers/InstallHandler.php | 1 + src/Module/Abstracts/Installer.php | 52 +++++++++++++++++++++++ src/Module/Handlers/InstallHandler.php | 9 ++-- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 src/Module/Abstracts/Installer.php diff --git a/src/Extension/Handlers/InstallHandler.php b/src/Extension/Handlers/InstallHandler.php index da8e0641..9c5995b4 100644 --- a/src/Extension/Handlers/InstallHandler.php +++ b/src/Extension/Handlers/InstallHandler.php @@ -61,6 +61,7 @@ class InstallHandler extends SetHandler ) { if (class_exists($class)) { $installer = $this->container->make($class); + return $installer->install(); } } diff --git a/src/Module/Abstracts/Installer.php b/src/Module/Abstracts/Installer.php new file mode 100644 index 00000000..9c73cec3 --- /dev/null +++ b/src/Module/Abstracts/Installer.php @@ -0,0 +1,52 @@ +container = $container; + } + + /** + * @return bool + */ + abstract public function handle(); + + /** + * @return bool + */ + public function install() + { + if (!$this->require()) { + return false; + } + return $this->handle(); + } + + /** + * @return bool + */ + abstract public function require(); +} diff --git a/src/Module/Handlers/InstallHandler.php b/src/Module/Handlers/InstallHandler.php index 82a63866..70c88051 100644 --- a/src/Module/Handlers/InstallHandler.php +++ b/src/Module/Handlers/InstallHandler.php @@ -54,11 +54,14 @@ class InstallHandler extends SetHandler public function execute() { $module = $this->manager->get($this->request->input('name')); - if ($module && method_exists($provider = $module->getEntry(), 'install')) { - return call_user_func([ + if ($module && method_exists($provider = $module->getEntry(), 'install') && $class = call_user_func([ $provider, 'install', - ]); + ]) + ) { + $installer = $this->container->make($class); + + return $installer->install(); } return false; -- Gitee From e09a3dad7b304936d124e621e055f09fc562fa3c Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 18:22:46 +0800 Subject: [PATCH 68/93] add uninstall logic for extension --- src/Extension/Abstracts/Uninstaller.php | 51 +++++++++++++++++++++ src/Extension/Handlers/UninstallHandler.php | 8 ++-- 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/Extension/Abstracts/Uninstaller.php diff --git a/src/Extension/Abstracts/Uninstaller.php b/src/Extension/Abstracts/Uninstaller.php new file mode 100644 index 00000000..a67ff5e7 --- /dev/null +++ b/src/Extension/Abstracts/Uninstaller.php @@ -0,0 +1,51 @@ +container = $container; + } + + /** + * @return bool + */ + abstract public function handle(); + + /** + * @return bool + */ + public abstract function require(); + + /** + * @return bool + */ + public function uninstall() { + if (!$this->require()) { + return false; + } + + return $this->handle(); + } +} diff --git a/src/Extension/Handlers/UninstallHandler.php b/src/Extension/Handlers/UninstallHandler.php index 27eda677..fe260e1f 100644 --- a/src/Extension/Handlers/UninstallHandler.php +++ b/src/Extension/Handlers/UninstallHandler.php @@ -54,11 +54,13 @@ class UninstallHandler extends SetHandler public function execute() { $extension = $this->manager->get($this->request->input('name')); - if ($extension && method_exists($provider = $extension->getEntry(), 'uninstall')) { - return call_user_func([ + if ($extension && method_exists($provider = $extension->getEntry(), 'uninstall') && $class = call_user_func([ $provider, 'uninstall', - ]); + ]) + ) { + $unInstaller = $this->container->make($class); + $unInstaller->uninstall(); } return false; -- Gitee From c30bea4dac5fdd5b7d7ac309e4bef1beb86b9260 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 18:26:16 +0800 Subject: [PATCH 69/93] add uninstall logic for module --- src/Module/Abstracts/Uninstaller.php | 52 ++++++++++++++++++++++++ src/Module/Handlers/UninstallHandler.php | 8 ++-- 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 src/Module/Abstracts/Uninstaller.php diff --git a/src/Module/Abstracts/Uninstaller.php b/src/Module/Abstracts/Uninstaller.php new file mode 100644 index 00000000..9736465b --- /dev/null +++ b/src/Module/Abstracts/Uninstaller.php @@ -0,0 +1,52 @@ +container = $container; + } + + /** + * @return mixed + */ + abstract public function handle(); + + /** + * @return mixed + */ + abstract public function require(); + + /** + * @return bool + */ + public function uninstall() + { + if (!$this->require()) { + return false; + } + + return $this->handle(); + } +} \ No newline at end of file diff --git a/src/Module/Handlers/UninstallHandler.php b/src/Module/Handlers/UninstallHandler.php index 886c441b..7a231050 100644 --- a/src/Module/Handlers/UninstallHandler.php +++ b/src/Module/Handlers/UninstallHandler.php @@ -54,11 +54,13 @@ class UninstallHandler extends SetHandler public function execute() { $module = $this->manager->get($this->request->input('name')); - if ($module && method_exists($provider = $module->getEntry(), 'uninstall')) { - return call_user_func([ + if ($module && method_exists($provider = $module->getEntry(), 'uninstall') && $class = call_user_func([ $provider, 'uninstall', - ]); + ])) { + $uninstaller = $this->container->make($class); + + return $uninstaller->uninstall(); } return false; -- Gitee From a8e3ebf0625ed5fe971a6a56b7e1a55253ae05d0 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 19:02:09 +0800 Subject: [PATCH 70/93] check instance of for installer and uninstaller --- src/Extension/Handlers/InstallHandler.php | 6 ++++-- src/Extension/Handlers/UninstallHandler.php | 7 +++++-- src/Module/Handlers/InstallHandler.php | 6 ++++-- src/Module/Handlers/UninstallHandler.php | 6 ++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Extension/Handlers/InstallHandler.php b/src/Extension/Handlers/InstallHandler.php index 9c5995b4..da8da124 100644 --- a/src/Extension/Handlers/InstallHandler.php +++ b/src/Extension/Handlers/InstallHandler.php @@ -9,6 +9,7 @@ namespace Notadd\Foundation\Extension\Handlers; use Illuminate\Container\Container; +use Notadd\Foundation\Extension\Abstracts\Installer; use Notadd\Foundation\Extension\ExtensionManager; use Notadd\Foundation\Passport\Abstracts\SetHandler; @@ -61,8 +62,9 @@ class InstallHandler extends SetHandler ) { if (class_exists($class)) { $installer = $this->container->make($class); - - return $installer->install(); + if ($installer instanceof Installer) { + return $installer->install(); + } } } diff --git a/src/Extension/Handlers/UninstallHandler.php b/src/Extension/Handlers/UninstallHandler.php index fe260e1f..d76d3cce 100644 --- a/src/Extension/Handlers/UninstallHandler.php +++ b/src/Extension/Handlers/UninstallHandler.php @@ -9,6 +9,7 @@ namespace Notadd\Foundation\Extension\Handlers; use Illuminate\Container\Container; +use Notadd\Foundation\Extension\Abstracts\Uninstaller; use Notadd\Foundation\Extension\ExtensionManager; use Notadd\Foundation\Passport\Abstracts\SetHandler; @@ -59,8 +60,10 @@ class UninstallHandler extends SetHandler 'uninstall', ]) ) { - $unInstaller = $this->container->make($class); - $unInstaller->uninstall(); + $uninstaller = $this->container->make($class); + if ($uninstaller instanceof Uninstaller) { + return $uninstaller->uninstall(); + } } return false; diff --git a/src/Module/Handlers/InstallHandler.php b/src/Module/Handlers/InstallHandler.php index 70c88051..115779db 100644 --- a/src/Module/Handlers/InstallHandler.php +++ b/src/Module/Handlers/InstallHandler.php @@ -9,6 +9,7 @@ namespace Notadd\Foundation\Module\Handlers; use Illuminate\Container\Container; +use Notadd\Foundation\Module\Abstracts\Installer; use Notadd\Foundation\Module\ModuleManager; use Notadd\Foundation\Passport\Abstracts\SetHandler; @@ -60,8 +61,9 @@ class InstallHandler extends SetHandler ]) ) { $installer = $this->container->make($class); - - return $installer->install(); + if ($installer instanceof Installer) { + return $installer->install(); + } } return false; diff --git a/src/Module/Handlers/UninstallHandler.php b/src/Module/Handlers/UninstallHandler.php index 7a231050..accc81ac 100644 --- a/src/Module/Handlers/UninstallHandler.php +++ b/src/Module/Handlers/UninstallHandler.php @@ -9,6 +9,7 @@ namespace Notadd\Foundation\Module\Handlers; use Illuminate\Container\Container; +use Notadd\Foundation\Module\Abstracts\Uninstaller; use Notadd\Foundation\Module\ModuleManager; use Notadd\Foundation\Passport\Abstracts\SetHandler; @@ -59,8 +60,9 @@ class UninstallHandler extends SetHandler 'uninstall', ])) { $uninstaller = $this->container->make($class); - - return $uninstaller->uninstall(); + if ($uninstaller instanceof Uninstaller) { + return $uninstaller->uninstall(); + } } return false; -- Gitee From 99e597f955e765e21e34e3fa52c85f4148c1e1fc Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 19:21:58 +0800 Subject: [PATCH 71/93] fix method return types for install and uninstall --- src/Extension/Abstracts/Extension.php | 8 ++++---- src/Module/Abstracts/Module.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Extension/Abstracts/Extension.php b/src/Extension/Abstracts/Extension.php index 22308a69..cc3c6033 100644 --- a/src/Extension/Abstracts/Extension.php +++ b/src/Extension/Abstracts/Extension.php @@ -51,9 +51,9 @@ abstract class Extension extends ServiceProvider abstract public static function description(); /** - * Install extension. + * Installer for extension. * - * @return bool + * @return string */ abstract public static function install(); @@ -72,9 +72,9 @@ abstract class Extension extends ServiceProvider } /** - * Uninstall extension. + * Uninstall for extension. * - * @return mixed + * @return string */ abstract public static function uninstall(); } diff --git a/src/Module/Abstracts/Module.php b/src/Module/Abstracts/Module.php index 4571a90f..985b3739 100644 --- a/src/Module/Abstracts/Module.php +++ b/src/Module/Abstracts/Module.php @@ -51,9 +51,9 @@ abstract class Module extends ServiceProvider abstract public static function description(); /** - * Install module. + * Install for module. * - * @return bool + * @return string */ abstract public static function install(); @@ -72,9 +72,9 @@ abstract class Module extends ServiceProvider } /** - * Uninstall module. + * Uninstall for module. * - * @return mixed + * @return string */ abstract public static function uninstall(); } -- Gitee From 7f844641aaf64e428bd701bbc89b052f0ee5b3ae Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 19:33:51 +0800 Subject: [PATCH 72/93] clear codes for module attachment --- .../Controllers/AttachmentController.php | 20 +----------------- src/Attachment/Controllers/CdnController.php | 20 +----------------- .../Controllers/StorageController.php | 21 +++---------------- .../Controllers/WatermarkController.php | 21 +++---------------- 4 files changed, 8 insertions(+), 74 deletions(-) diff --git a/src/Attachment/Controllers/AttachmentController.php b/src/Attachment/Controllers/AttachmentController.php index 63ed876e..c9be14c7 100644 --- a/src/Attachment/Controllers/AttachmentController.php +++ b/src/Attachment/Controllers/AttachmentController.php @@ -13,28 +13,10 @@ use Notadd\Foundation\Routing\Abstracts\Controller; use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** - * Class AttachmentApi. + * Class AttachmentController. */ class AttachmentController extends Controller { - /** - * @var \Notadd\Foundation\Setting\Contracts\SettingsRepository - */ - protected $settings; - - /** - * WatermarkController constructor. - * - * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings - * - * @throws \Illuminate\Contracts\Container\BindingResolutionException - */ - public function __construct(SettingsRepository $settings) - { - parent::__construct(); - $this->settings = $settings; - } - /** * Api handler. * diff --git a/src/Attachment/Controllers/CdnController.php b/src/Attachment/Controllers/CdnController.php index f60091f7..ac590674 100644 --- a/src/Attachment/Controllers/CdnController.php +++ b/src/Attachment/Controllers/CdnController.php @@ -13,28 +13,10 @@ use Notadd\Foundation\Routing\Abstracts\Controller; use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** - * Class CdnApi. + * Class CdnController. */ class CdnController extends Controller { - /** - * @var \Notadd\Foundation\Setting\Contracts\SettingsRepository - */ - protected $settings; - - /** - * WatermarkController constructor. - * - * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings - * - * @throws \Illuminate\Contracts\Container\BindingResolutionException - */ - public function __construct(SettingsRepository $settings) - { - parent::__construct(); - $this->settings = $settings; - } - /** * Api handler. * diff --git a/src/Attachment/Controllers/StorageController.php b/src/Attachment/Controllers/StorageController.php index 04b0eaba..bafaaa44 100644 --- a/src/Attachment/Controllers/StorageController.php +++ b/src/Attachment/Controllers/StorageController.php @@ -12,26 +12,11 @@ use Notadd\Foundation\Attachment\Handlers\StorageSetHandler; use Notadd\Foundation\Routing\Abstracts\Controller; use Notadd\Foundation\Setting\Contracts\SettingsRepository; +/** + * Class StorageController. + */ class StorageController extends Controller { - /** - * @var \Notadd\Foundation\Setting\Contracts\SettingsRepository - */ - protected $settings; - - /** - * WatermarkController constructor. - * - * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings - * - * @throws \Illuminate\Contracts\Container\BindingResolutionException - */ - public function __construct(SettingsRepository $settings) - { - parent::__construct(); - $this->settings = $settings; - } - /** * Api handler. * diff --git a/src/Attachment/Controllers/WatermarkController.php b/src/Attachment/Controllers/WatermarkController.php index d1e55695..18c3ab03 100644 --- a/src/Attachment/Controllers/WatermarkController.php +++ b/src/Attachment/Controllers/WatermarkController.php @@ -12,26 +12,11 @@ use Notadd\Foundation\Attachment\Handlers\WatermarkSetHandler; use Notadd\Foundation\Routing\Abstracts\Controller; use Notadd\Foundation\Setting\Contracts\SettingsRepository; +/** + * Class WatermarkController. + */ class WatermarkController extends Controller { - /** - * @var \Notadd\Foundation\Setting\Contracts\SettingsRepository - */ - protected $settings; - - /** - * WatermarkController constructor. - * - * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings - * - * @throws \Illuminate\Contracts\Container\BindingResolutionException - */ - public function __construct(SettingsRepository $settings) - { - parent::__construct(); - $this->settings = $settings; - } - /** * Api handler. * -- Gitee From 06e7858e85d9d8a00281e46406c837f6ae9da393 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 19:35:01 +0800 Subject: [PATCH 73/93] clear codes for module debug --- src/Attachment/Controllers/AttachmentController.php | 1 - src/Attachment/Controllers/CdnController.php | 1 - src/Attachment/Controllers/StorageController.php | 1 - src/Attachment/Controllers/WatermarkController.php | 1 - src/Debug/Controllers/DebugController.php | 3 +-- 5 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Attachment/Controllers/AttachmentController.php b/src/Attachment/Controllers/AttachmentController.php index c9be14c7..5d7ff42b 100644 --- a/src/Attachment/Controllers/AttachmentController.php +++ b/src/Attachment/Controllers/AttachmentController.php @@ -10,7 +10,6 @@ namespace Notadd\Foundation\Attachment\Controllers; use Notadd\Foundation\Attachment\Handlers\AttachmentSetHandler; use Notadd\Foundation\Routing\Abstracts\Controller; -use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** * Class AttachmentController. diff --git a/src/Attachment/Controllers/CdnController.php b/src/Attachment/Controllers/CdnController.php index ac590674..c2e1ecb4 100644 --- a/src/Attachment/Controllers/CdnController.php +++ b/src/Attachment/Controllers/CdnController.php @@ -10,7 +10,6 @@ namespace Notadd\Foundation\Attachment\Controllers; use Notadd\Foundation\Attachment\Handlers\CdnSetHandler; use Notadd\Foundation\Routing\Abstracts\Controller; -use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** * Class CdnController. diff --git a/src/Attachment/Controllers/StorageController.php b/src/Attachment/Controllers/StorageController.php index bafaaa44..d8ada9bc 100644 --- a/src/Attachment/Controllers/StorageController.php +++ b/src/Attachment/Controllers/StorageController.php @@ -10,7 +10,6 @@ namespace Notadd\Foundation\Attachment\Controllers; use Notadd\Foundation\Attachment\Handlers\StorageSetHandler; use Notadd\Foundation\Routing\Abstracts\Controller; -use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** * Class StorageController. diff --git a/src/Attachment/Controllers/WatermarkController.php b/src/Attachment/Controllers/WatermarkController.php index 18c3ab03..2267892e 100644 --- a/src/Attachment/Controllers/WatermarkController.php +++ b/src/Attachment/Controllers/WatermarkController.php @@ -10,7 +10,6 @@ namespace Notadd\Foundation\Attachment\Controllers; use Notadd\Foundation\Attachment\Handlers\WatermarkSetHandler; use Notadd\Foundation\Routing\Abstracts\Controller; -use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** * Class WatermarkController. diff --git a/src/Debug/Controllers/DebugController.php b/src/Debug/Controllers/DebugController.php index d75037d6..0643d4e5 100644 --- a/src/Debug/Controllers/DebugController.php +++ b/src/Debug/Controllers/DebugController.php @@ -10,10 +10,9 @@ namespace Notadd\Foundation\Debug\Controllers; use Notadd\Foundation\Debug\Handlers\SetHandler; use Notadd\Foundation\Routing\Abstracts\Controller; -use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** - * Class DebugApi. + * Class DebugController. */ class DebugController extends Controller { -- Gitee From 5cc3d7a40111578265230a63b2c4727328754328 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 19:36:23 +0800 Subject: [PATCH 74/93] clear codes for module mail --- src/Mail/Controllers/MailController.php | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/Mail/Controllers/MailController.php b/src/Mail/Controllers/MailController.php index 2f9d2f82..444916e0 100644 --- a/src/Mail/Controllers/MailController.php +++ b/src/Mail/Controllers/MailController.php @@ -13,26 +13,11 @@ use Notadd\Foundation\Mail\Handlers\TestHandler; use Notadd\Foundation\Routing\Abstracts\Controller; use Notadd\Foundation\Setting\Contracts\SettingsRepository; +/** + * Class MailController. + */ class MailController extends Controller { - /** - * @var \Notadd\Foundation\Setting\Contracts\SettingsRepository - */ - protected $settings; - - /** - * WatermarkController constructor. - * - * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings - * - * @throws \Illuminate\Contracts\Container\BindingResolutionException - */ - public function __construct(SettingsRepository $settings) - { - parent::__construct(); - $this->settings = $settings; - } - /** * Api handler. * -- Gitee From 836d681a457818ecd1823959754a76284bdc40bd Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 19:38:01 +0800 Subject: [PATCH 75/93] clear codes for module SearchEngine --- src/Mail/Controllers/MailController.php | 1 - .../Controllers/AccessTokenController.php | 1 - src/SearchEngine/Controllers/SeoController.php | 17 ----------------- 3 files changed, 19 deletions(-) diff --git a/src/Mail/Controllers/MailController.php b/src/Mail/Controllers/MailController.php index 444916e0..c9ea1f05 100644 --- a/src/Mail/Controllers/MailController.php +++ b/src/Mail/Controllers/MailController.php @@ -11,7 +11,6 @@ namespace Notadd\Foundation\Mail\Controllers; use Notadd\Foundation\Mail\Handlers\SetHandler; use Notadd\Foundation\Mail\Handlers\TestHandler; use Notadd\Foundation\Routing\Abstracts\Controller; -use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** * Class MailController. diff --git a/src/Passport/Controllers/AccessTokenController.php b/src/Passport/Controllers/AccessTokenController.php index ca4568fd..f92ada7b 100644 --- a/src/Passport/Controllers/AccessTokenController.php +++ b/src/Passport/Controllers/AccessTokenController.php @@ -10,7 +10,6 @@ namespace Notadd\Foundation\Passport\Controllers; use Illuminate\Http\Response; use Laravel\Passport\Http\Controllers\HandlesOAuthErrors; -use Laravel\Passport\Passport; use Laravel\Passport\TokenRepository; use Lcobucci\JWT\Parser as JwtParser; use League\OAuth2\Server\AuthorizationServer; diff --git a/src/SearchEngine/Controllers/SeoController.php b/src/SearchEngine/Controllers/SeoController.php index 108c8b08..f2849481 100644 --- a/src/SearchEngine/Controllers/SeoController.php +++ b/src/SearchEngine/Controllers/SeoController.php @@ -10,29 +10,12 @@ namespace Notadd\Foundation\SearchEngine\Controllers; use Notadd\Foundation\Routing\Abstracts\ApiController; use Notadd\Foundation\SearchEngine\Handlers\SetHandler; -use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** * Class SeoController. */ class SeoController extends ApiController { - /** - * @var \Notadd\Foundation\Setting\Contracts\SettingsRepository - */ - protected $settings; - - /** - * WatermarkController constructor. - * - * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings - */ - public function __construct(SettingsRepository $settings) - { - parent::__construct(); - $this->settings = $settings; - } - /** * Api handler. * -- Gitee From 546f98be56c6eb7e98e92780ebcec6ee2c0657ea Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 19:38:38 +0800 Subject: [PATCH 76/93] clear codes for module setting --- src/Setting/Controllers/SettingController.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/Setting/Controllers/SettingController.php b/src/Setting/Controllers/SettingController.php index 1eea83ba..9937217a 100644 --- a/src/Setting/Controllers/SettingController.php +++ b/src/Setting/Controllers/SettingController.php @@ -9,7 +9,6 @@ namespace Notadd\Foundation\Setting\Controllers; use Notadd\Foundation\Routing\Abstracts\Controller; -use Notadd\Foundation\Setting\Contracts\SettingsRepository; use Notadd\Foundation\Setting\Handlers\AllHandler; use Notadd\Foundation\Setting\Handlers\SetHandler; @@ -18,24 +17,6 @@ use Notadd\Foundation\Setting\Handlers\SetHandler; */ class SettingController extends Controller { - /** - * @var \Notadd\Foundation\Setting\Contracts\SettingsRepository - */ - protected $settings; - - /** - * SettingController constructor. - * - * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings - * - * @throws \Illuminate\Contracts\Container\BindingResolutionException - */ - public function __construct(SettingsRepository $settings) - { - parent::__construct(); - $this->settings = $settings; - } - /** * All handler. * -- Gitee From 0f1d56b63a19f95907cbcbf1c9b59c0231b2543d Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 20:08:35 +0800 Subject: [PATCH 77/93] add helper method for checking extension or module exist --- src/Extension/ExtensionManager.php | 12 ++++++++++++ src/Module/ModuleManager.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Extension/ExtensionManager.php b/src/Extension/ExtensionManager.php index 0d7d15c2..7b75aa22 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -147,6 +147,18 @@ class ExtensionManager return $this->extensions; } + /** + * Check for extension exist. + * + * @param $name + * + * @return bool + */ + public function has($name) + { + return $this->extensions->has($name); + } + /** * Vendor Path. * diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index ead3f243..1d695bed 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -138,6 +138,18 @@ class ModuleManager return $this->modules; } + /** + * Check for module exist. + * + * @param $name + * + * @return bool + */ + public function has($name) + { + return $this->modules->has($name); + } + /** * Module path. * -- Gitee From 3a76ee3538b7947b0cb193af31f688b7e8cb1a95 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Thu, 9 Mar 2017 22:59:23 +0800 Subject: [PATCH 78/93] add version info for module --- src/Extension/Abstracts/Extension.php | 7 +++++++ src/Extension/Extension.php | 16 ++++++++-------- src/Module/Abstracts/Module.php | 7 +++++++ src/Module/Module.php | 25 +++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/Extension/Abstracts/Extension.php b/src/Extension/Abstracts/Extension.php index cc3c6033..98f28846 100644 --- a/src/Extension/Abstracts/Extension.php +++ b/src/Extension/Abstracts/Extension.php @@ -77,4 +77,11 @@ abstract class Extension extends ServiceProvider * @return string */ abstract public static function uninstall(); + + /** + * Version of extension. + * + * @return string + */ + abstract public static function version(); } diff --git a/src/Extension/Extension.php b/src/Extension/Extension.php index 5917ce57..2759c15b 100644 --- a/src/Extension/Extension.php +++ b/src/Extension/Extension.php @@ -141,14 +141,6 @@ class Extension return $this->path; } - /** - * @return string - */ - public function getVersion(): string - { - return $this->version; - } - /** * Script of module. * @@ -169,6 +161,14 @@ class Extension return $this->stylesheet; } + /** + * @return string + */ + public function getVersion(): string + { + return $this->version; + } + /** * @return bool */ diff --git a/src/Module/Abstracts/Module.php b/src/Module/Abstracts/Module.php index 985b3739..b2afe598 100644 --- a/src/Module/Abstracts/Module.php +++ b/src/Module/Abstracts/Module.php @@ -77,4 +77,11 @@ abstract class Module extends ServiceProvider * @return string */ abstract public static function uninstall(); + + /** + * Version of module. + * + * @return string + */ + abstract public static function version(); } diff --git a/src/Module/Module.php b/src/Module/Module.php index cc2543eb..20fb407d 100644 --- a/src/Module/Module.php +++ b/src/Module/Module.php @@ -63,6 +63,11 @@ class Module */ protected $stylesheet; + /** + * @var string + */ + protected $version; + /** * Module constructor. * @@ -153,6 +158,16 @@ class Module return $this->stylesheet; } + /** + * Version of module. + * + * @return string + */ + public function getVersion(): string + { + return $this->version; + } + /** * Enabled of module. * @@ -278,4 +293,14 @@ class Module { $this->stylesheet = $stylesheet; } + + /** + * Set module's version. + * + * @param string $version + */ + public function setVersion(string $version) + { + $this->version = $version; + } } -- Gitee From 9dfd3e008cbfdad87e411e9d5e94cf2da271bbe4 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 10 Mar 2017 11:17:37 +0800 Subject: [PATCH 79/93] add version info while listing extension or module --- src/Extension/ExtensionManager.php | 1 + src/Module/ModuleManager.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Extension/ExtensionManager.php b/src/Extension/ExtensionManager.php index 7b75aa22..dee24b9a 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -136,6 +136,7 @@ class ExtensionManager method_exists($provider, 'name') && $extension->setName(call_user_func([$provider, 'name'])); method_exists($provider, 'script') && $extension->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $extension->setStylesheet(call_user_func([$provider, 'stylesheet'])); + method_exists($provider, 'version') && $extension->setStylesheet(call_user_func([$provider, 'version'])); $this->extensions->put($identification, $extension); } } diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index 1d695bed..4451c341 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -128,6 +128,7 @@ class ModuleManager method_exists($provider, 'name') && $module->setName(call_user_func([$provider, 'name'])); method_exists($provider, 'script') && $module->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $module->setStylesheet(call_user_func([$provider, 'stylesheet'])); + method_exists($provider, 'version') && $module->setStylesheet(call_user_func([$provider, 'version'])); $this->modules->put($identification, $module); } } -- Gitee From 1c74ae6e59e0be83da2c06a69bd3d688f43d890a Mon Sep 17 00:00:00 2001 From: qiyueshiyi Date: Fri, 10 Mar 2017 13:47:32 +0800 Subject: [PATCH 80/93] Renamed Permission::ADMIN_PREFIX value to admin. --- src/Member/Permission.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Member/Permission.php b/src/Member/Permission.php index 3f477f87..c30ecb80 100644 --- a/src/Member/Permission.php +++ b/src/Member/Permission.php @@ -25,7 +25,7 @@ use Notadd\Foundation\Database\Model; */ class Permission extends Model { - const ADMIN_PREFIX = 'admin-'; + const ADMIN_PREFIX = 'admin.'; protected $table = 'permissions'; -- Gitee From 168f8d8a66b63b1e44de286187ef9c1f1e9df15e Mon Sep 17 00:00:00 2001 From: qiyueshiyi Date: Fri, 10 Mar 2017 13:54:09 +0800 Subject: [PATCH 81/93] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=89=8D=E5=8F=B0?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=B7=BB=E5=8A=A0=E6=96=B9=E6=B3=95=E5=92=8C?= =?UTF-8?q?=E7=9B=B8=E5=BA=94=E7=9A=84=E5=89=8D=E5=8F=B0=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Member/Permission.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Member/Permission.php b/src/Member/Permission.php index c30ecb80..79c8c74d 100644 --- a/src/Member/Permission.php +++ b/src/Member/Permission.php @@ -25,6 +25,14 @@ use Notadd\Foundation\Database\Model; */ class Permission extends Model { + /** + * 前台的权限前缀 + */ + const FRONT_PREFIX = 'front.'; + + /** + * 后台的权限前缀 + */ const ADMIN_PREFIX = 'admin.'; protected $table = 'permissions'; @@ -56,6 +64,20 @@ class Permission extends Model return $permission; } + /** + * 添加前台权限 + * + * @param $name + * @param null $display_name + * @param null $description + * + * @return \Notadd\Foundation\Member\Permission + */ + public static function addFrontPermission($name, $display_name = null, $description = null) + { + return static::addPermission(static::FRONT_PREFIX . $name, $display_name, $description); + } + /** * 添加后台权限 * -- Gitee From b4082f4c57c0a1bac13443cc51de28718b1a32fb Mon Sep 17 00:00:00 2001 From: qiyueshiyi Date: Fri, 10 Mar 2017 13:56:25 +0800 Subject: [PATCH 82/93] Add scopeWhereFront function to Permission model --- src/Member/Permission.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Member/Permission.php b/src/Member/Permission.php index 79c8c74d..f6c32fbb 100644 --- a/src/Member/Permission.php +++ b/src/Member/Permission.php @@ -92,6 +92,19 @@ class Permission extends Model return static::addPermission(static::ADMIN_PREFIX . $name, $display_name, $description); } + /** + * 查询前台权限 + * + * @param $query + * @param $name + * + * @return mixed + */ + public function scopeWhereFront($query, $name) + { + return $query->where('name', static::FRONT_PREFIX . $name); + } + /** * 查询后台权限 * -- Gitee From cb095be7e222ff8036429e17a01d1ff506b0985d Mon Sep 17 00:00:00 2001 From: qiyueshiyi Date: Fri, 10 Mar 2017 14:05:27 +0800 Subject: [PATCH 83/93] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=89=8D=E5=8F=B0?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=88=86=E7=BB=84=E7=9A=84=20key=20=E4=B8=BA?= =?UTF-8?q?=20front,=20=E5=B9=B6=E4=BF=AE=E6=94=B9=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=89=8D=E5=8F=B0=E6=9D=83=E9=99=90=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=BA=20Permission::addFrontPermission?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Member/Commands/PermissionCommand.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Member/Commands/PermissionCommand.php b/src/Member/Commands/PermissionCommand.php index cbebe8ac..b02362f5 100644 --- a/src/Member/Commands/PermissionCommand.php +++ b/src/Member/Commands/PermissionCommand.php @@ -77,20 +77,20 @@ class PermissionCommand extends Command $i = 0; - $frontendPermissions = array_get($permissions, 'frontend', []); + $frontPermissions = array_get($permissions, 'front', []); $adminPermissions = array_get($permissions, 'admin', []); // 添加前台权限 - foreach ($frontendPermissions as $frontendPermission) { - if (! isset($frontendPermission['display_name']) || ! isset($frontendPermission['name']) || empty($frontendPermission['display_name']) || empty($frontendPermission['name'])) { + foreach ($frontPermissions as $frontPermission) { + if (! isset($frontPermission['display_name']) || ! isset($frontPermission['name']) || empty($frontPermission['display_name']) || empty($frontPermission['name'])) { continue; } - if (Permission::where('name', $frontendPermission['name'])->count()) { + if (Permission::whereFront($frontPermission['name'])->count()) { continue; } - Permission::addPermission($frontendPermission['name'], $frontendPermission['display_name'], isset($frontendPermission['description']) ? $frontendPermission['description'] : ''); + Permission::addFrontPermission($frontPermission['name'], $frontPermission['display_name'], isset($frontPermission['description']) ? $frontPermission['description'] : ''); $i++; } -- Gitee From 63b9d1ced91d54fdf4bc0919581f1cd6212a411e Mon Sep 17 00:00:00 2001 From: qiyueshiyi Date: Fri, 10 Mar 2017 14:12:32 +0800 Subject: [PATCH 84/93] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20Permission::addFront?= =?UTF-8?q?Permission=20and=20Permission::addAdminPermission,=20=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E5=A6=82=E6=9E=9C=E6=9C=89=E7=9B=B8=E5=BA=94=E7=9A=84?= =?UTF-8?q?=E5=89=8D=E7=BC=80=E5=B0=B1=E4=B8=8D=E5=86=8D=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Member/Permission.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Member/Permission.php b/src/Member/Permission.php index f6c32fbb..99475564 100644 --- a/src/Member/Permission.php +++ b/src/Member/Permission.php @@ -9,6 +9,7 @@ namespace Notadd\Foundation\Member; +use Illuminate\Support\Str; use Notadd\Foundation\Database\Model; /** @@ -75,7 +76,11 @@ class Permission extends Model */ public static function addFrontPermission($name, $display_name = null, $description = null) { - return static::addPermission(static::FRONT_PREFIX . $name, $display_name, $description); + return static::addPermission( + Str::startsWith($name, static::FRONT_PREFIX) ? $name : static::FRONT_PREFIX . $name, + $display_name, + $description + ); } /** @@ -89,7 +94,11 @@ class Permission extends Model */ public static function addAdminPermission($name, $display_name = null, $description = null) { - return static::addPermission(static::ADMIN_PREFIX . $name, $display_name, $description); + return static::addPermission( + Str::startsWith($name, static::ADMIN_PREFIX) ? $name : static::ADMIN_PREFIX . $name, + $display_name, + $description + ); } /** -- Gitee From 60002ebbc360370193a599419ed1e57feb40effd Mon Sep 17 00:00:00 2001 From: qiyueshiyi Date: Fri, 10 Mar 2017 14:27:39 +0800 Subject: [PATCH 85/93] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20User::hasAdminPermis?= =?UTF-8?q?sion=20=E9=87=8C=E5=88=A4=E6=96=AD=E6=9D=83=E9=99=90=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=9C=89=20*=20=E5=8F=B7=E7=9A=84=E9=80=BB=E8=BE=91,?= =?UTF-8?q?=20=E6=94=B9=E4=B8=BA=E5=88=A4=E6=96=AD=E6=9C=AB=E5=B0=BE?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=9C=89=20*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Member/Member.php | 4 ++-- src/Member/Permission.php | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Member/Member.php b/src/Member/Member.php index 5b66baef..2b64605b 100644 --- a/src/Member/Member.php +++ b/src/Member/Member.php @@ -178,7 +178,7 @@ class Member extends Authenticatable if (is_array($name)) { $adminName = array_map(function ($val) { - if (str_contains($val, '*')) { + if (ends_with($val, '*')) { return $val; } @@ -186,7 +186,7 @@ class Member extends Authenticatable }, $name); } else { - if (! str_contains($name, '*')) { + if (! ends_with($name, '*')) { $adminName = Permission::ADMIN_PREFIX . $name; } } diff --git a/src/Member/Permission.php b/src/Member/Permission.php index 99475564..abe6ecdf 100644 --- a/src/Member/Permission.php +++ b/src/Member/Permission.php @@ -50,6 +50,15 @@ class Permission extends Model return $this->belongsToMany(Member::class, 'member_permission', 'permission_id', 'member_id'); } + /** + * 添加权限 + * + * @param $name + * @param null $display_name + * @param null $description + * + * @return static + */ public static function addPermission($name, $display_name = null, $description = null) { $permission = static::where('name', $name)->first(); @@ -118,7 +127,7 @@ class Permission extends Model * 查询后台权限 * * @param $query - * @param $name + * @param $nameMember * * @return mixed */ -- Gitee From ffc53a80d6da7e96d74cf650fbd0001d53b9fe3a Mon Sep 17 00:00:00 2001 From: qiyueshiyi Date: Fri, 10 Mar 2017 14:31:54 +0800 Subject: [PATCH 86/93] Add hasFrontPermission function to Member model --- src/Member/Member.php | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/Member/Member.php b/src/Member/Member.php index 2b64605b..62ac502a 100644 --- a/src/Member/Member.php +++ b/src/Member/Member.php @@ -164,6 +164,34 @@ class Member extends Authenticatable return false; } + /** + * 判断是否有前台的权限, 支持 * 通赔符 + * + * @param $name + * @param bool $requireAll + * + * @return bool + */ + public function hasFrontPermission($name, $requireAll = false) + { + if (is_array($name)) { + $name = array_map(function ($val) { + if (ends_with($val, '*')) { + return $val; + } + + return Permission::FRONT_PREFIX . $val; + }, $name); + } else { + + if (! ends_with($name, '*')) { + $name = Permission::FRONT_PREFIX . $name; + } + } + + return $this->hasPermission($name, $requireAll); + } + /** * Checks if the member has a admin permission by its name. * @@ -174,10 +202,8 @@ class Member extends Authenticatable */ public function hasAdminPermission($name, $requireAll = false) { - $adminName = $name; - if (is_array($name)) { - $adminName = array_map(function ($val) { + $name = array_map(function ($val) { if (ends_with($val, '*')) { return $val; } @@ -187,11 +213,11 @@ class Member extends Authenticatable } else { if (! ends_with($name, '*')) { - $adminName = Permission::ADMIN_PREFIX . $name; + $name = Permission::ADMIN_PREFIX . $name; } } - return $this->hasPermission($adminName, $requireAll); + return $this->hasPermission($name, $requireAll); } /** -- Gitee From 08de0800fe0e6039566561db37845e6e4afe0958 Mon Sep 17 00:00:00 2001 From: qiyueshiyi Date: Fri, 10 Mar 2017 15:12:28 +0800 Subject: [PATCH 87/93] Add FrontPermission middleware class and add permission.front middleware, renamed admin-permission to permission.admin middleware --- src/Member/MemberServiceProvider.php | 4 ++- src/Member/Middleware/FrontPermission.php | 39 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/Member/Middleware/FrontPermission.php diff --git a/src/Member/MemberServiceProvider.php b/src/Member/MemberServiceProvider.php index 144600fe..85319ec6 100644 --- a/src/Member/MemberServiceProvider.php +++ b/src/Member/MemberServiceProvider.php @@ -10,6 +10,7 @@ namespace Notadd\Foundation\Member; use Illuminate\Support\ServiceProvider; use Notadd\Foundation\Member\Middleware\Permission; +use Notadd\Foundation\Member\Middleware\FrontPermission; use Notadd\Foundation\Member\Middleware\AdminPermission; use Notadd\Foundation\Member\Commands\PermissionCommand; @@ -42,7 +43,8 @@ class MemberServiceProvider extends ServiceProvider public function registerMiddleware() { $this->app['router']->middleware('permission', Permission::class); - $this->app['router']->middleware('admin-permission', AdminPermission::class); + $this->app['router']->middleware('permission.admin', AdminPermission::class); + $this->app['router']->middleware('permission.front', FrontPermission::class); } public function registerCommands() diff --git a/src/Member/Middleware/FrontPermission.php b/src/Member/Middleware/FrontPermission.php new file mode 100644 index 00000000..4abdd7c4 --- /dev/null +++ b/src/Member/Middleware/FrontPermission.php @@ -0,0 +1,39 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 15:08 + */ + +namespace Notadd\Foundation\Member\Middleware; + +use Closure; +use Illuminate\Http\Request; +use Illuminate\Http\JsonResponse; + +class FrontPermission extends Permission +{ + /** + * Handle an incoming request. + * + * @param \Illuminate\Http\Request $request + * @param Closure $next + * @param $permissions + * + * @return mixed + */ + public function handle(Request $request, Closure $next, $permissions, $guard = 'admin') + { + if ($this->auth->guard($guard)->guest() || ! $request->user($guard)->hasFrontPermission(explode('|', $permissions))) { + if ($this->wantsJson()) { + return new JsonResponse('Forbidden', 403); + } + + abort(403); + } + + return $next($request); + } +} -- Gitee From 34c523d0b9486b9549ae040255d2519cac687f51 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 10 Mar 2017 15:13:40 +0800 Subject: [PATCH 88/93] fix set version method --- src/Extension/ExtensionManager.php | 2 +- src/Module/ModuleManager.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Extension/ExtensionManager.php b/src/Extension/ExtensionManager.php index dee24b9a..cbb09d4c 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -136,7 +136,7 @@ class ExtensionManager method_exists($provider, 'name') && $extension->setName(call_user_func([$provider, 'name'])); method_exists($provider, 'script') && $extension->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $extension->setStylesheet(call_user_func([$provider, 'stylesheet'])); - method_exists($provider, 'version') && $extension->setStylesheet(call_user_func([$provider, 'version'])); + method_exists($provider, 'version') && $extension->setVersion(call_user_func([$provider, 'version'])); $this->extensions->put($identification, $extension); } } diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index 4451c341..be53e49b 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -128,7 +128,7 @@ class ModuleManager method_exists($provider, 'name') && $module->setName(call_user_func([$provider, 'name'])); method_exists($provider, 'script') && $module->setScript(call_user_func([$provider, 'script'])); method_exists($provider, 'stylesheet') && $module->setStylesheet(call_user_func([$provider, 'stylesheet'])); - method_exists($provider, 'version') && $module->setStylesheet(call_user_func([$provider, 'version'])); + method_exists($provider, 'version') && $module->setVersion(call_user_func([$provider, 'version'])); $this->modules->put($identification, $module); } } -- Gitee From 787e975c12cf8342cefe1624bd4fde24e725a2e1 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 10 Mar 2017 16:21:37 +0800 Subject: [PATCH 89/93] make status to 500 while status is bigger then 599 --- src/Passport/Responses/ApiResponse.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Passport/Responses/ApiResponse.php b/src/Passport/Responses/ApiResponse.php index f90715a6..ce86dcf9 100644 --- a/src/Passport/Responses/ApiResponse.php +++ b/src/Passport/Responses/ApiResponse.php @@ -34,6 +34,7 @@ class ApiResponse is_null($response) && $response = new Response(); $params && $this->params = array_merge($this->params, $params); $status = collect($this->params)->get('code', 200); + $status > 598 && $status = 500; $response = $response->withStatus($status) ->withHeader('pragma', 'no-cache') ->withHeader('cache-control', 'no-store') -- Gitee From 37dd21039e1f1adab7d72089c198bb72f7cc744a Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Fri, 10 Mar 2017 16:45:06 +0800 Subject: [PATCH 90/93] replace summary info --- src/Debug/DebugServiceProvider.php | 9 +++++---- src/Debug/Listeners/RouteRegister.php | 9 +++++---- src/Extension/Abstracts/Installer.php | 10 +++++----- src/Extension/Abstracts/Uninstaller.php | 11 ++++++----- src/Module/Abstracts/Installer.php | 10 +++++----- src/Module/Abstracts/Uninstaller.php | 9 +++++---- 6 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/Debug/DebugServiceProvider.php b/src/Debug/DebugServiceProvider.php index 25b4049d..b3112672 100644 --- a/src/Debug/DebugServiceProvider.php +++ b/src/Debug/DebugServiceProvider.php @@ -1,9 +1,10 @@ + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14:12 */ namespace Notadd\Foundation\Debug; diff --git a/src/Debug/Listeners/RouteRegister.php b/src/Debug/Listeners/RouteRegister.php index ab30f6cc..ad254c85 100644 --- a/src/Debug/Listeners/RouteRegister.php +++ b/src/Debug/Listeners/RouteRegister.php @@ -1,9 +1,10 @@ + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14:12 */ namespace Notadd\Foundation\Debug\Listeners; diff --git a/src/Extension/Abstracts/Installer.php b/src/Extension/Abstracts/Installer.php index 352c8e95..1413020d 100644 --- a/src/Extension/Abstracts/Installer.php +++ b/src/Extension/Abstracts/Installer.php @@ -1,11 +1,11 @@ + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14:12 */ - namespace Notadd\Foundation\Extension\Abstracts; use Illuminate\Container\Container; diff --git a/src/Extension/Abstracts/Uninstaller.php b/src/Extension/Abstracts/Uninstaller.php index a67ff5e7..8b03757c 100644 --- a/src/Extension/Abstracts/Uninstaller.php +++ b/src/Extension/Abstracts/Uninstaller.php @@ -1,12 +1,13 @@ + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14:12 */ - namespace Notadd\Foundation\Extension\Abstracts; + use Illuminate\Container\Container; /** diff --git a/src/Module/Abstracts/Installer.php b/src/Module/Abstracts/Installer.php index 9c73cec3..b3ceda2c 100644 --- a/src/Module/Abstracts/Installer.php +++ b/src/Module/Abstracts/Installer.php @@ -1,11 +1,11 @@ + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14:12 */ - namespace Notadd\Foundation\Module\Abstracts; use Illuminate\Container\Container; diff --git a/src/Module/Abstracts/Uninstaller.php b/src/Module/Abstracts/Uninstaller.php index 9736465b..a79714e8 100644 --- a/src/Module/Abstracts/Uninstaller.php +++ b/src/Module/Abstracts/Uninstaller.php @@ -1,9 +1,10 @@ + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14:12 */ namespace Notadd\Foundation\Module\Abstracts; -- Gitee From 03cca01dcf2e0e3b9761af8e0e7c00a1c37251a2 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Mon, 13 Mar 2017 18:14:17 +0800 Subject: [PATCH 91/93] move base data definition to top class, and return data base on attributes --- src/Passport/Abstracts/DataHandler.php | 5 ----- src/Passport/Abstracts/Handler.php | 30 ++++++++++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Passport/Abstracts/DataHandler.php b/src/Passport/Abstracts/DataHandler.php index a099d92b..aaa6e40c 100644 --- a/src/Passport/Abstracts/DataHandler.php +++ b/src/Passport/Abstracts/DataHandler.php @@ -16,11 +16,6 @@ use Notadd\Foundation\Passport\Responses\ApiResponse; */ abstract class DataHandler extends Handler { - /** - * @var int - */ - protected $code = 200; - /** * @var bool */ diff --git a/src/Passport/Abstracts/Handler.php b/src/Passport/Abstracts/Handler.php index afe1fd90..01eefc92 100644 --- a/src/Passport/Abstracts/Handler.php +++ b/src/Passport/Abstracts/Handler.php @@ -18,6 +18,22 @@ use Notadd\Foundation\Validation\ValidatesRequests; abstract class Handler { use ValidatesRequests; + + /** + * @var int + */ + protected $code = 200; + + /** + * @var array + */ + protected $data = []; + + /** + * @var array + */ + protected $errors = []; + /** * @var \Illuminate\Container\Container|\Notadd\Foundation\Application */ @@ -28,6 +44,11 @@ abstract class Handler */ protected $log; + /** + * @var array + */ + protected $messages = []; + /** * @var \Illuminate\Http\Request */ @@ -55,32 +76,29 @@ abstract class Handler * Http code. * * @return int - * @throws \Exception */ public function code() { - throw new Exception('Code is not setted!'); + return $this->code; } /** * Errors for handler. * * @return array - * @throws \Exception */ public function errors() { - throw new Exception('Error is not setted!'); + return $this->errors; } /** * Messages for handler. * * @return array - * @throws \Exception */ public function messages() { - throw new Exception('Message is not setted!'); + return $this->messages; } } -- Gitee From 9b9e702a7d6a4ae59c5ea12ac2a6c21a188361c1 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Mon, 13 Mar 2017 18:26:51 +0800 Subject: [PATCH 92/93] remove unnecessary code methods --- src/Passport/Abstracts/DataHandler.php | 8 ++++++-- src/Passport/Abstracts/Handler.php | 5 ----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Passport/Abstracts/DataHandler.php b/src/Passport/Abstracts/DataHandler.php index aaa6e40c..c6dd0206 100644 --- a/src/Passport/Abstracts/DataHandler.php +++ b/src/Passport/Abstracts/DataHandler.php @@ -16,6 +16,11 @@ use Notadd\Foundation\Passport\Responses\ApiResponse; */ abstract class DataHandler extends Handler { + /** + * @var array + */ + protected $data = []; + /** * @var bool */ @@ -30,11 +35,10 @@ abstract class DataHandler extends Handler * Data for handler. * * @return array - * @throws \Exception */ public function data() { - throw new Exception('Data is not setted!'); + return $this->data; } /** diff --git a/src/Passport/Abstracts/Handler.php b/src/Passport/Abstracts/Handler.php index 01eefc92..401936eb 100644 --- a/src/Passport/Abstracts/Handler.php +++ b/src/Passport/Abstracts/Handler.php @@ -24,11 +24,6 @@ abstract class Handler */ protected $code = 200; - /** - * @var array - */ - protected $data = []; - /** * @var array */ -- Gitee From d76e65e5646a33539a972e66549014f65084ea53 Mon Sep 17 00:00:00 2001 From: twilroad <269044570@qq.com> Date: Mon, 13 Mar 2017 22:20:57 +0800 Subject: [PATCH 93/93] add with helper methods --- src/Passport/Abstracts/Handler.php | 42 +++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/Passport/Abstracts/Handler.php b/src/Passport/Abstracts/Handler.php index 401936eb..990dda1e 100644 --- a/src/Passport/Abstracts/Handler.php +++ b/src/Passport/Abstracts/Handler.php @@ -72,7 +72,7 @@ abstract class Handler * * @return int */ - public function code() + protected function code() { return $this->code; } @@ -82,7 +82,7 @@ abstract class Handler * * @return array */ - public function errors() + protected function errors() { return $this->errors; } @@ -92,8 +92,44 @@ abstract class Handler * * @return array */ - public function messages() + protected function messages() { return $this->messages; } + + /** + * @param int $code + * + * @return $this + */ + protected function withCode($code) + { + $this->code = $code; + + return $this; + } + + /** + * @param array|string $errors + * + * @return $this + */ + protected function withErrors($errors) + { + $this->errors = array_merge($this->errors, (array)$errors); + + return $this; + } + + /** + * @param array|string $messages + * + * @return $this + */ + protected function withMessages($messages) + { + $this->messages = array_merge($this->messages, (array)$messages); + + return $this; + } } -- Gitee