diff --git a/composer.json b/composer.json index f6a7ac406bae3527ae1da2f6f66e448ea99a9b43..1ae0cb647cbb1fed849294effa36c2686e15ffa6 100644 --- a/composer.json +++ b/composer.json @@ -30,64 +30,65 @@ "php": ">=7.0", "ext-mbstring": "*", "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", + "laravel/passport": "^2.0", "league/flysystem": "~1.0", "monolog/monolog": "~1.11", "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 diff --git a/configurations/app.php b/configurations/app.php index b9954eaa24e94f276c436840af4d5c38fd368178..32b1ccf269f11b733fd781a9225f4ace2a2ccf27 100644 --- a/configurations/app.php +++ b/configurations/app.php @@ -20,21 +20,19 @@ 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, - Illuminate\Queue\ConsoleServiceProvider::class, + Notadd\Foundation\Console\ConsoleServiceProvider::class, Illuminate\Cookie\CookieServiceProvider::class, Notadd\Foundation\Database\DatabaseServiceProvider::class, Notadd\Foundation\Debug\DebugServiceProvider::class, 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, @@ -51,13 +49,11 @@ 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, 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 b6987fe3cd9d0da064993dafa7b10a05d18c5a79..5c93271b7096b41fc7e3eff853e2553fec3f6ebb 100644 --- a/src/Application.php +++ b/src/Application.php @@ -12,14 +12,16 @@ 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 Notadd\Foundation\Translation\Events\LocaleUpdated; use RuntimeException; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -34,7 +36,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn /** * @var string */ - const VERSION = '1.0'; + const VERSION = '0.2.1'; /** * @var string @@ -160,6 +162,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)); } @@ -175,9 +178,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]); } } @@ -188,7 +191,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); } /** @@ -604,7 +607,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; } @@ -1014,7 +1017,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(LocaleUpdated::class, [$locale]); } /** @@ -1035,124 +1038,115 @@ 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', - ], - 'filesystem.disk' => ['Illuminate\Contracts\Filesystem\Filesystem'], - 'filesystem.cloud' => ['Illuminate\Contracts\Filesystem\Cloud'], - 'hash' => ['Illuminate\Contracts\Hashing\Hasher'], - 'translator' => [ - 'Illuminate\Translation\Translator', - 'Symfony\Component\Translation\TranslatorInterface', + \Illuminate\Filesystem\FilesystemManager::class, + \Illuminate\Contracts\Filesystem\Factory::class, ], + 'filesystem.disk' => [\Illuminate\Contracts\Filesystem\Filesystem::class], + 'filesystem.cloud' => [\Illuminate\Contracts\Filesystem\Cloud::class], + 'hash' => [\Illuminate\Contracts\Hashing\Hasher::class], + 'images' => [\Notadd\Foundation\Image\ImageManager::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::class], + 'theme' => [\Notadd\Foundation\Theme\ThemeManager::class], + 'translator' => [ + \Illuminate\Translation\Translator::class, + \Illuminate\Contracts\Translation\Translator::class, ], - 'setting' => ['Notadd\Foundation\Setting\Contracts\SettingsRepository'], - 'theme' => ['Notadd\Foundation\Theme\ThemeManager'], '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) { diff --git a/src/Attachment/AttachmentServiceProvider.php b/src/Attachment/AttachmentServiceProvider.php index 6e876d5c425a6634e885e45fe5432a24656a9747..1419167d4abefb270c3890c3260b467b3c5918b5 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/Controllers/AttachmentController.php b/src/Attachment/Controllers/AttachmentController.php index 63ed876ed6b09d1484279e73421c98b7853b51b9..5d7ff42b46319393b58f862008759f666a665cd0 100644 --- a/src/Attachment/Controllers/AttachmentController.php +++ b/src/Attachment/Controllers/AttachmentController.php @@ -10,31 +10,12 @@ namespace Notadd\Foundation\Attachment\Controllers; use Notadd\Foundation\Attachment\Handlers\AttachmentSetHandler; 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 f60091f76eccad7792821621abbd4ac273868698..c2e1ecb41f1286d0b77261e028d1aa831e57d16e 100644 --- a/src/Attachment/Controllers/CdnController.php +++ b/src/Attachment/Controllers/CdnController.php @@ -10,31 +10,12 @@ namespace Notadd\Foundation\Attachment\Controllers; use Notadd\Foundation\Attachment\Handlers\CdnSetHandler; 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 04b0eaba1ac9ec6fb9953bc1b8638e579947f42c..d8ada9bca5c8f77d0863e6cff915ce6b90d28b86 100644 --- a/src/Attachment/Controllers/StorageController.php +++ b/src/Attachment/Controllers/StorageController.php @@ -10,28 +10,12 @@ 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. + */ 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 d1e55695b96a6027933dded9d628b8512f2c9c05..2267892e69239d13ce83d36afba232a463688885 100644 --- a/src/Attachment/Controllers/WatermarkController.php +++ b/src/Attachment/Controllers/WatermarkController.php @@ -10,28 +10,12 @@ 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. + */ 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. * diff --git a/src/Attachment/Listeners/RouteRegistrar.php b/src/Attachment/Listeners/RouteRegister.php similarity index 86% rename from src/Attachment/Listeners/RouteRegistrar.php rename to src/Attachment/Listeners/RouteRegister.php index 31465a28d9ef66d85f58c10ce8e52645d4dfb581..1ab84886ab50d59f1721d8dbadd19253c9b86924 100644 --- a/src/Attachment/Listeners/RouteRegistrar.php +++ b/src/Attachment/Listeners/RouteRegister.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 5be41306c8f42aa0b705e0d6daa6d6ea66e67311..32742c3f2e2c631208cd753c6460475cb534a075 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/RouteRegister.php similarity index 88% rename from src/Auth/Listeners/RouteRegistrar.php rename to src/Auth/Listeners/RouteRegister.php index a40c98cf7eaab0ab5e3ac54609986de9f90aafc1..173b9f345f711ba61e1663d3e3ac69f09065a5c9 100644 --- a/src/Auth/Listeners/RouteRegistrar.php +++ b/src/Auth/Listeners/RouteRegister.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/Bootstrap/DetectEnvironment.php b/src/Bootstrap/LoadEnvironmentVariables.php similarity index 98% rename from src/Bootstrap/DetectEnvironment.php rename to src/Bootstrap/LoadEnvironmentVariables.php index 1fee8cf99ad5efc3fca33610ffe2c85f3ea9a2e9..cd6091eec65793b4ed5e1f05d1ef805a296a048c 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/Composer/ComposerScripts.php b/src/Composer/ComposerScripts.php index 39aec499ec143f9d07597505a4501613a699fec2..941189ef1d7fa3666bad5c388d48cf7fa434c0b0 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); } } diff --git a/src/Console/Application.php b/src/Console/Application.php index 3e5ce1d19f74747818f0ff0e5d5a32d2cd6822a8..e269f57e17bb4d66484f60e06063a579854e873c 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); diff --git a/src/Console/Commands/OptimizeCommand.php b/src/Console/Commands/OptimizeCommand.php index 09b00c093213c8b7f655a29ad32a855dc8b1259c..8cd1f03eb06e1c2826feca36f7ec9a81bdfb29a5 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'); } /** diff --git a/src/Console/Commands/TinkerCommand.php b/src/Console/Commands/TinkerCommand.php deleted file mode 100644 index 5c419e9251f5e796a34264a1cbb62b4f4215f27f..0000000000000000000000000000000000000000 --- 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/Console/ArtisanServiceProvider.php b/src/Console/ConsoleServiceProvider.php similarity index 79% rename from src/Console/ArtisanServiceProvider.php rename to src/Console/ConsoleServiceProvider.php index 8b8e77211ae900053ad9fd5c06e2f60f0d532124..311755ee6d1ff788c3a8928be3e70e60e03ae19c 100644 --- a/src/Console/ArtisanServiceProvider.php +++ b/src/Console/ConsoleServiceProvider.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; @@ -45,7 +51,7 @@ use Notadd\Foundation\Session\Commands\SessionTableCommand; /** * Class ArtisanServiceProvider. */ -class ArtisanServiceProvider extends ServiceProvider +class ConsoleServiceProvider extends ServiceProvider { /** * @var bool @@ -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/Kernel.php b/src/Console/Kernel.php index 6ea311b9ac8cc6954426a233261e99d039af83f5..30a42abdd226ffb8e5f0571d90ee76ee18b676a2 100644 --- a/src/Console/Kernel.php +++ b/src/Console/Kernel.php @@ -12,12 +12,13 @@ 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; 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; @@ -65,7 +66,7 @@ class Kernel implements KernelContract * @var array */ protected $bootstrappers = [ - DetectEnvironment::class, + LoadEnvironmentVariables::class, LoadConfiguration::class, ConfigureLogging::class, HandleExceptions::class, @@ -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); } diff --git a/src/Database/MigrationServiceProvider.php b/src/Database/MigrationServiceProvider.php index ebd2d6e129af6c6dccb1cbe66f6caa4039101b8d..8982461a52e331b791ec61993d240dd53aefaa81 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. */ diff --git a/src/Debug/Controllers/DebugController.php b/src/Debug/Controllers/DebugController.php index d75037d61c2390a33670f253d13f0916e9c9696d..0643d4e50de6c1fc34cd5b5797a0301c968cfeb2 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 { diff --git a/src/Debug/DebugServiceProvider.php b/src/Debug/DebugServiceProvider.php index 532f4c16e814a6483b9c48814d2b7aeea2d398f2..b3112672f5e0b3c5976be99e0166c8ff5299123d 100644 --- a/src/Debug/DebugServiceProvider.php +++ b/src/Debug/DebugServiceProvider.php @@ -1,16 +1,17 @@ + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14:12 */ 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 +24,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/RouteRegister.php similarity index 62% rename from src/Debug/Listeners/RouteRegistrar.php rename to src/Debug/Listeners/RouteRegister.php index 4b7b974bc544797cf9eda06f0db90bfda99f4d1f..ad254c8532504295ed5ca970a9b99be3d7d00747 100644 --- a/src/Debug/Listeners/RouteRegistrar.php +++ b/src/Debug/Listeners/RouteRegister.php @@ -1,19 +1,20 @@ + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14: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/Controllers/UEditorController.php b/src/Editor/Controllers/UEditorController.php index 9d4fb6da2059cbb3967cdbf8466511e68b23d0e9..70124c0037aa7b16cca1bfd35352614867acb978 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(); } @@ -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')), ]; } diff --git a/src/Editor/EditorServiceProvider.php b/src/Editor/EditorServiceProvider.php index c50185325a0108e0ce24b6767850381f92df683f..9e6aeea6586f2e60d16e50c0d8cc8375029428ac 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/RouteRegister.php similarity index 80% rename from src/Editor/Listeners/RouteRegistrar.php rename to src/Editor/Listeners/RouteRegister.php index 8389b4e14015801a335bb24db42ab1067b09e646..6773554b030fd021f7c32493fa66c88a1b3b7c37 100644 --- a/src/Editor/Listeners/RouteRegistrar.php +++ b/src/Editor/Listeners/RouteRegister.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/Abstracts/Extension.php b/src/Extension/Abstracts/Extension.php index 7e7a87b640c38e16eef9f8c2c1d585aff9bdaf47..98f28846331224e2f3e96a1e4e5aaf251290c3cc 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,28 @@ class Extension extends ServiceProvider /** * Boot extension. */ - public function boot() { - } + abstract public function boot(); + + /** + * Description of extension + * + * @return string + */ + abstract public static function description(); + + /** + * Installer for extension. + * + * @return string + */ + abstract public static function install(); + + /** + * Name of extension. + * + * @return string + */ + abstract public static function name(); /** * Register extension extra providers. @@ -50,4 +70,18 @@ class Extension extends ServiceProvider public function register() { } + + /** + * Uninstall for extension. + * + * @return string + */ + abstract public static function uninstall(); + + /** + * Version of extension. + * + * @return string + */ + abstract public static function version(); } diff --git a/src/Extension/Abstracts/Installer.php b/src/Extension/Abstracts/Installer.php new file mode 100644 index 0000000000000000000000000000000000000000..1413020dd64b01607085c1117bbbc8a141feec8f --- /dev/null +++ b/src/Extension/Abstracts/Installer.php @@ -0,0 +1,52 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14:12 + */ +namespace Notadd\Foundation\Extension\Abstracts; + +use Illuminate\Container\Container; + +/** + * Class Installer. + */ +abstract class Installer +{ + /** + * @var Container + */ + protected $container; + + /** + * Installer constructor. + * @param Container $container + */ + public function __construct(Container $container) + { + $this->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/Abstracts/Uninstaller.php b/src/Extension/Abstracts/Uninstaller.php new file mode 100644 index 0000000000000000000000000000000000000000..8b03757c76570232c14dc454d38f1e220e9887da --- /dev/null +++ b/src/Extension/Abstracts/Uninstaller.php @@ -0,0 +1,52 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14:12 + */ +namespace Notadd\Foundation\Extension\Abstracts; + +use Illuminate\Container\Container; + +/** + * Class Uninstaller. + */ +abstract class Uninstaller +{ + /** + * @var Container + */ + protected $container; + + /** + * Uninstaller constructor. + * @param Container $container + */ + public function __construct(Container $container) + { + $this->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/Commands/ListCommand.php b/src/Extension/Commands/ListCommand.php index c46fe24c1080b3db4339fcb853abd29ff8e76d79..494bfb7e7e1a94715a9683a06bc22d972594e506 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/Controllers/ExtensionController.php b/src/Extension/Controllers/ExtensionController.php index aa2ea47b29ecbf3b4b62e652234a09cd232ed711..623e1168f338a4618b41362e817982eb97a32332 100644 --- a/src/Extension/Controllers/ExtensionController.php +++ b/src/Extension/Controllers/ExtensionController.php @@ -10,6 +10,9 @@ 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\Extension\Handlers\UpdateHandler; use Notadd\Foundation\Routing\Abstracts\Controller; /** @@ -42,4 +45,43 @@ class ExtensionController extends Controller { return $handler->toResponse()->generateHttpResponse(); } + + /** + * 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(); + } + + /** + * 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(); + } + + /** + * 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/Extension.php b/src/Extension/Extension.php index 96674ea4ce84a9310a49e27f19590b233dae5882..2759c15b2a038de0b662e5caf7374f13e9c2f11d 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 */ @@ -33,6 +38,11 @@ class Extension */ protected $entry; + /** + * @var string + */ + protected $identification; + /** * @var bool */ @@ -66,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; } /** @@ -89,6 +99,16 @@ class Extension return $this->description; } + /** + * Get directory of extension. + * + * @return string + */ + public function getDirectory(): string + { + return $this->directory; + } + /** * @return string */ @@ -100,25 +120,25 @@ class Extension /** * @return string */ - public function getName(): string + public function getIdentification(): string { - return $this->name; + return $this->identification; } /** * @return string */ - public function getPath(): string + public function getName(): string { - return $this->path; + return $this->name; } /** * @return string */ - public function getVersion(): string + public function getPath(): string { - return $this->version; + return $this->path; } /** @@ -141,6 +161,14 @@ class Extension return $this->stylesheet; } + /** + * @return string + */ + public function getVersion(): string + { + return $this->version; + } + /** * @return bool */ @@ -179,6 +207,16 @@ class Extension $this->description = $description; } + /** + * Set directory of extension. + * + * @param string $directory + */ + public function setDirectory(string $directory) + { + $this->directory = $directory; + } + /** * @param string $entry */ @@ -203,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 e3b8c21661bbde4312b31b85b3e96780a77a1f1c..cbb09d4c702704a31c67a8c21732ea22577b3f5a 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. * @@ -95,23 +107,37 @@ 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.' . $identification . '.enabled', false)); $provider = ''; 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, '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'])); - $extension->setEnabled($this->container->make('setting')->get('extension.' . $name . '.enabled', false)); - $this->extensions->put($directory, $extension); + method_exists($provider, 'version') && $extension->setVersion(call_user_func([$provider, 'version'])); + $this->extensions->put($identification, $extension); } } }); @@ -122,6 +148,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/Extension/ExtensionServiceProvider.php b/src/Extension/ExtensionServiceProvider.php index dc8dc01c5e9afd2c307571816454cba5156e7443..2578547e3945d8a4a181e0c199a9984faf86671f 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,22 @@ use Notadd\Foundation\Extension\Listeners\RouteRegister; */ class ExtensionServiceProvider extends ServiceProvider { + /** + * @var \Illuminate\Filesystem\Filesystem + */ + protected $files; + + /** + * ExtensionServiceProvider constructor. + * + * @param \Illuminate\Contracts\Foundation\Application $app + */ + public function __construct(Application $app) + { + parent::__construct($app); + $this->files = $app->make(Filesystem::class); + } + /** * Boot service provider. * @@ -28,8 +46,9 @@ 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 = $extension->getDirectory(); + if ($this->files->isDirectory($path) && is_string($extension->getEntry())) { $this->app->register($extension->getEntry()); } }); diff --git a/src/Extension/Handlers/ExtensionHandler.php b/src/Extension/Handlers/ExtensionHandler.php index 65d32f8287ea1164bab84e0ee7129c6e814dbe81..07f2c3f94be1b754ed7c3e8a648cc1862999e0c0 100644 --- a/src/Extension/Handlers/ExtensionHandler.php +++ b/src/Extension/Handlers/ExtensionHandler.php @@ -61,6 +61,7 @@ class ExtensionHandler extends DataHandler 'author' => $extension->getAuthor(), 'enabled' => $extension->isEnabled(), 'description' => $extension->getDescription(), + 'identification' => $extension->getIdentification(), 'name' => $extension->getName(), ]; }); diff --git a/src/Extension/Handlers/InstallHandler.php b/src/Extension/Handlers/InstallHandler.php new file mode 100644 index 0000000000000000000000000000000000000000..da8da1241f67612228f04ea3158d2e11c26eb8f5 --- /dev/null +++ b/src/Extension/Handlers/InstallHandler.php @@ -0,0 +1,85 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-02 15:51 + */ +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; + +/** + * 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() + { + $extension = $this->manager->get($this->request->input('name')); + if ($extension && method_exists($provider = $extension->getEntry(), 'install') && $class = call_user_func([ + $provider, + 'install', + ]) + ) { + if (class_exists($class)) { + $installer = $this->container->make($class); + if ($installer instanceof Installer) { + return $installer->install(); + } + } + } + + return false; + } + + /** + * Messages for handler. + * + * @return array + */ + public function messages() + { + return [ + $this->translator->trans(''), + ]; + } +} diff --git a/src/Extension/Handlers/UninstallHandler.php b/src/Extension/Handlers/UninstallHandler.php new file mode 100644 index 0000000000000000000000000000000000000000..d76d3cce8071d32f203def6a2d3aafc02d4aeddc --- /dev/null +++ b/src/Extension/Handlers/UninstallHandler.php @@ -0,0 +1,83 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-02 16:10 + */ +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; + +/** + * Class UninstallHandler. + */ +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') && $class = call_user_func([ + $provider, + 'uninstall', + ]) + ) { + $uninstaller = $this->container->make($class); + if ($uninstaller instanceof Uninstaller) { + return $uninstaller->uninstall(); + } + } + + return false; + } + + /** + * Messages for handler. + * + * @return array + */ + public function messages() + { + return [ + $this->translator->trans(''), + ]; + } +} diff --git a/src/Extension/Handlers/UpdateHandler.php b/src/Extension/Handlers/UpdateHandler.php new file mode 100644 index 0000000000000000000000000000000000000000..7822ec9df3ddade4031af260e4d9c890c6668d38 --- /dev/null +++ b/src/Extension/Handlers/UpdateHandler.php @@ -0,0 +1,78 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-03 15:33 + */ +namespace Notadd\Foundation\Extension\Handlers; + +use Illuminate\Container\Container; +use Notadd\Foundation\Extension\ExtensionManager; +use Notadd\Foundation\Passport\Abstracts\SetHandler; + +/** + * Class UpdateHandler. + */ +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(''), + ]; + } +} diff --git a/src/Extension/Listeners/RouteRegister.php b/src/Extension/Listeners/RouteRegister.php index f08071b485e9090dcead1dc17f4e1945596573e7..13c027cf374bfaccb1e4b074a6ed318a63cabead 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. @@ -23,6 +23,9 @@ 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/update', ExtensionController::class . '@update'); $this->router->post('extension', ExtensionController::class . '@handle'); }); } diff --git a/src/Http/Events/RequestHandled.php b/src/Http/Events/RequestHandled.php new file mode 100644 index 0000000000000000000000000000000000000000..47a2e3783ff2d45dcd406d7251adabcc02484fcc --- /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/HttpServiceProvider.php b/src/Http/HttpServiceProvider.php index e60a1ffc7a24c2c65eb9ed90871c7842dd4d5f3f..d4b5dd62efe100382d3ead945ce6a72f0d14ee1e 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')); } /** diff --git a/src/Http/Kernel.php b/src/Http/Kernel.php index 89b6d32b74e7c6ad8dda71be0d853cba22c64499..45fb350459ec3da806f3905c1294938e7ad69078 100644 --- a/src/Http/Kernel.php +++ b/src/Http/Kernel.php @@ -28,13 +28,14 @@ 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; use Notadd\Foundation\Bootstrap\RegisterFacades; use Notadd\Foundation\Bootstrap\RegisterRouter; use Notadd\Foundation\Http\Middlewares\CheckForCloseMode; +use Notadd\Foundation\Http\Events\RequestHandled; use Notadd\Foundation\Http\Middlewares\CheckForMaintenanceMode; use Notadd\Foundation\Http\Middlewares\EnableCrossRequest; use Notadd\Foundation\Http\Middlewares\RedirectIfAuthenticated; @@ -62,7 +63,7 @@ class Kernel implements KernelContract * @var array */ protected $bootstrappers = [ - DetectEnvironment::class, + LoadEnvironmentVariables::class, LoadConfiguration::class, ConfigureLogging::class, HandleExceptions::class, @@ -140,7 +141,7 @@ class Kernel implements KernelContract $router->middlewareGroup($key, $middleware); } foreach ($this->routeMiddleware as $key => $middleware) { - $router->middleware($key, $middleware); + $router->aliasMiddleware($key, $middleware); } } @@ -163,7 +164,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/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 093b3a4371c02c819a2935e5a7412e005735888f..9080ba48da466c37920a0b3218e501502a4370f5 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); diff --git a/src/Image/ImageServiceProvider.php b/src/Image/ImageServiceProvider.php index 6826905a65547421f70701251fc725a251b61304..703de5696dce9adda61e6884aafbf3297c9cba46 100644 --- a/src/Image/ImageServiceProvider.php +++ b/src/Image/ImageServiceProvider.php @@ -51,10 +51,9 @@ 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/Mail/Controllers/MailController.php b/src/Mail/Controllers/MailController.php index 2f9d2f821fd24bc1134e2f419304cd9e840b8fe1..c9ea1f05130ef682cb5dd211bdb4ca0c0547b50c 100644 --- a/src/Mail/Controllers/MailController.php +++ b/src/Mail/Controllers/MailController.php @@ -11,28 +11,12 @@ 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. + */ 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. * diff --git a/src/Mail/Listeners/RouterRegistrar.php b/src/Mail/Listeners/RouterRegister.php similarity index 82% rename from src/Mail/Listeners/RouterRegistrar.php rename to src/Mail/Listeners/RouterRegister.php index 4d2dca035755026fe7100a9f746bf07acecceb30..8f854b0af84321c6c4224cba8ff1aaffba8e808c 100644 --- a/src/Mail/Listeners/RouterRegistrar.php +++ b/src/Mail/Listeners/RouterRegister.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 67f69e06f5100a87b67e30fd0b2789433732bf59..48d14f009dd4455212b22e57bee13d9bc3ddce34 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/Member/Commands/PermissionCommand.php b/src/Member/Commands/PermissionCommand.php index cbebe8accff3e0db18d4b2a8529830d8396319e2..b02362f5cee6c5a7a064dcd8081e598aa9074ee1 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++; } diff --git a/src/Member/Member.php b/src/Member/Member.php index 5b66baef50fe3ba895fa0a2e29f9285b48e135c9..62ac502a5c10b17bcdce5736360a7e49c7d68362 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,11 +202,9 @@ class Member extends Authenticatable */ public function hasAdminPermission($name, $requireAll = false) { - $adminName = $name; - if (is_array($name)) { - $adminName = array_map(function ($val) { - if (str_contains($val, '*')) { + $name = array_map(function ($val) { + if (ends_with($val, '*')) { return $val; } @@ -186,12 +212,12 @@ class Member extends Authenticatable }, $name); } else { - if (! str_contains($name, '*')) { - $adminName = Permission::ADMIN_PREFIX . $name; + if (! ends_with($name, '*')) { + $name = Permission::ADMIN_PREFIX . $name; } } - return $this->hasPermission($adminName, $requireAll); + return $this->hasPermission($name, $requireAll); } /** diff --git a/src/Member/MemberServiceProvider.php b/src/Member/MemberServiceProvider.php index 144600fe44345931a0d459faa6e872a1af4852fa..8a95d859e0d08eab0f773e5b338f63116f9cbe31 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; @@ -41,8 +42,9 @@ 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('permission.admin', AdminPermission::class); + $this->app['router']->aliasMiddleware('permission.front', FrontPermission::class); } public function registerCommands() @@ -54,7 +56,7 @@ class MemberServiceProvider extends ServiceProvider public function registerPermission() { - $this->app->bind('permission', function ($app) { + $this->app->singleton('permission', function ($app) { return new PermissionManager; }); } diff --git a/src/Member/Middleware/FrontPermission.php b/src/Member/Middleware/FrontPermission.php new file mode 100644 index 0000000000000000000000000000000000000000..4abdd7c4cebaec1487a9f31003124a5f53e862f7 --- /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); + } +} diff --git a/src/Member/Permission.php b/src/Member/Permission.php index 3f477f8790c0aba1e81a973def50413d55eb7d50..abe6ecdf13195f33f4edaa5a140113bfcbbcebc7 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; /** @@ -25,7 +26,15 @@ use Notadd\Foundation\Database\Model; */ class Permission extends Model { - const ADMIN_PREFIX = 'admin-'; + /** + * 前台的权限前缀 + */ + const FRONT_PREFIX = 'front.'; + + /** + * 后台的权限前缀 + */ + const ADMIN_PREFIX = 'admin.'; protected $table = 'permissions'; @@ -41,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(); @@ -56,6 +74,24 @@ 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( + Str::startsWith($name, static::FRONT_PREFIX) ? $name : static::FRONT_PREFIX . $name, + $display_name, + $description + ); + } + /** * 添加后台权限 * @@ -67,17 +103,34 @@ 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 + ); } /** - * 查询后台权限 + * 查询前台权限 * * @param $query * @param $name * * @return mixed */ + public function scopeWhereFront($query, $name) + { + return $query->where('name', static::FRONT_PREFIX . $name); + } + + /** + * 查询后台权限 + * + * @param $query + * @param $nameMember + * + * @return mixed + */ public function scopeWhereAdmin($query, $name) { return $query->where('name', static::ADMIN_PREFIX . $name); diff --git a/src/Module/Abstracts/Installer.php b/src/Module/Abstracts/Installer.php new file mode 100644 index 0000000000000000000000000000000000000000..b3ceda2c61cf84e7db4841779fb956f434b8a21b --- /dev/null +++ b/src/Module/Abstracts/Installer.php @@ -0,0 +1,52 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14:12 + */ +namespace Notadd\Foundation\Module\Abstracts; + +use Illuminate\Container\Container; + +/** + * Class Installer. + */ +abstract class Installer +{ + /** + * @var Container + */ + protected $container; + + /** + * Installer constructor. + * @param Container $container + */ + public function __construct(Container $container) + { + $this->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/Abstracts/Module.php b/src/Module/Abstracts/Module.php new file mode 100644 index 0000000000000000000000000000000000000000..b2afe598e8dfb50bf5a3b01c5a2c55d8eec97eb4 --- /dev/null +++ b/src/Module/Abstracts/Module.php @@ -0,0 +1,87 @@ + + * @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(); + + /** + * Description of module + * + * @return string + */ + abstract public static function description(); + + /** + * Install for module. + * + * @return string + */ + abstract public static function install(); + + /** + * Name of module. + * + * @return string + */ + abstract public static function name(); + + /** + * Register module extra providers. + */ + public function register() + { + } + + /** + * Uninstall for module. + * + * @return string + */ + abstract public static function uninstall(); + + /** + * Version of module. + * + * @return string + */ + abstract public static function version(); +} diff --git a/src/Module/Abstracts/Uninstaller.php b/src/Module/Abstracts/Uninstaller.php new file mode 100644 index 0000000000000000000000000000000000000000..a79714e889840531eaa4faf856c9ef729cae8dce --- /dev/null +++ b/src/Module/Abstracts/Uninstaller.php @@ -0,0 +1,53 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-10 14:12 + */ +namespace Notadd\Foundation\Module\Abstracts; + +use Illuminate\Container\Container; + +/** + * Class Uninstaller. + */ +abstract class Uninstaller +{ + /** + * @var Container + */ + protected $container; + + /** + * Uninstaller constructor. + * @param Container $container + */ + public function __construct(Container $container) + { + $this->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/Commands/ListCommand.php b/src/Module/Commands/ListCommand.php index 603fde7cbcb31f216f18c00467a98dca1a534999..472b9f1de25072c873e9d77c764d73b1897de2e9 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/Controllers/ModuleController.php b/src/Module/Controllers/ModuleController.php index b7163a471f7a7cb891bbd78348881cbaf7aa5eb4..fdf7c1b9f9ed8c82c5cd7955888e405ef1570d32 100644 --- a/src/Module/Controllers/ModuleController.php +++ b/src/Module/Controllers/ModuleController.php @@ -9,7 +9,10 @@ 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; +use Notadd\Foundation\Module\Handlers\UpdateHandler; /** * Class ModuleController. @@ -41,4 +44,43 @@ 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(); + } + + /** + * 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(); + } + + /** + * 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/InstallHandler.php b/src/Module/Handlers/InstallHandler.php new file mode 100644 index 0000000000000000000000000000000000000000..115779db5a7f1bc75c223af48bc1c8b96da6bca8 --- /dev/null +++ b/src/Module/Handlers/InstallHandler.php @@ -0,0 +1,83 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-02 15:34 + */ +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; + +/** + * Class InstallHandler. + */ +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')); + if ($module && method_exists($provider = $module->getEntry(), 'install') && $class = call_user_func([ + $provider, + 'install', + ]) + ) { + $installer = $this->container->make($class); + if ($installer instanceof Installer) { + return $installer->install(); + } + } + + return false; + } + + /** + * Messages for handler. + * + * @throws array + */ + public function messages() + { + return [ + $this->translator->trans(''), + ]; + } +} diff --git a/src/Module/Handlers/ModuleHandler.php b/src/Module/Handlers/ModuleHandler.php index d96beac7ddf33a3ba3ab92fdbced522ffb7e41d0..3dac9771773fdeee138a1c1165b9e166eeb1f2f0 100644 --- a/src/Module/Handlers/ModuleHandler.php +++ b/src/Module/Handlers/ModuleHandler.php @@ -60,6 +60,7 @@ class ModuleHandler extends DataHandler 'author' => $module->getAuthor(), 'enabled' => $module->isEnabled(), 'description' => $module->getDescription(), + 'identification' => $module->getIdentification(), 'name' => $module->getName(), ]; }); diff --git a/src/Module/Handlers/UninstallHandler.php b/src/Module/Handlers/UninstallHandler.php new file mode 100644 index 0000000000000000000000000000000000000000..accc81acd5e0b7d6b726964a38a2180fb7435e63 --- /dev/null +++ b/src/Module/Handlers/UninstallHandler.php @@ -0,0 +1,82 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-02 16:00 + */ +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; + +/** + * 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() + { + $module = $this->manager->get($this->request->input('name')); + if ($module && method_exists($provider = $module->getEntry(), 'uninstall') && $class = call_user_func([ + $provider, + 'uninstall', + ])) { + $uninstaller = $this->container->make($class); + if ($uninstaller instanceof Uninstaller) { + return $uninstaller->uninstall(); + } + } + + return false; + } + + /** + * Messages for handler. + * + * @return array + */ + public function messages() + { + return [ + $this->translator->trans(''), + ]; + } +} diff --git a/src/Module/Handlers/UpdateHandler.php b/src/Module/Handlers/UpdateHandler.php new file mode 100644 index 0000000000000000000000000000000000000000..e371e2888b8641cc2ec16ce78db612ff563e9a12 --- /dev/null +++ b/src/Module/Handlers/UpdateHandler.php @@ -0,0 +1,78 @@ + + * @copyright (c) 2017, iBenchu.org + * @datetime 2017-03-03 15:27 + */ +namespace Notadd\Foundation\Module\Handlers; + +use Illuminate\Container\Container; +use Notadd\Foundation\Module\ModuleManager; +use Notadd\Foundation\Passport\Abstracts\SetHandler; + +/** + * Class UpdateHandler. + */ +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(''), + ]; + } +} diff --git a/src/Module/Listeners/RouteRegister.php b/src/Module/Listeners/RouteRegister.php index d8f40491705a80218d5f084c63582c12c7712177..622c210e1f5adebac7864113a169680f0cd35b84 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. @@ -23,6 +23,9 @@ 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/update', ModuleController::class . '@update'); $this->router->post('module', ModuleController::class . '@handle'); }); } diff --git a/src/Module/Module.php b/src/Module/Module.php index 11d9ed343e0e19b5d86b7b1d370582edfbf4a419..20fb407d296d8246774f61c19bc2c0f724503ff9 100644 --- a/src/Module/Module.php +++ b/src/Module/Module.php @@ -28,11 +28,21 @@ class Module */ protected $description; + /** + * @var string + */ + protected $directory; + /** * @var string */ protected $entry; + /** + * @var string + */ + protected $identification; + /** * @var bool */ @@ -53,6 +63,11 @@ class Module */ protected $stylesheet; + /** + * @var string + */ + protected $version; + /** * Module constructor. * @@ -60,7 +75,7 @@ class Module */ public function __construct($name = null) { - $this->name = $name; + $this->identification = $name; } /** @@ -83,6 +98,16 @@ class Module return $this->description; } + /** + * Directory of module. + * + * @return string + */ + public function getDirectory() + { + return $this->directory; + } + /** * Entry of module. * @@ -93,12 +118,22 @@ class Module return $this->entry; } + /** + * Identification of module. + * + * @return string + */ + public function getIdentification() + { + return $this->identification; + } + /** * Name of module. * * @return string */ - public function getName() + public function getName(): string { return $this->name; } @@ -123,6 +158,16 @@ class Module return $this->stylesheet; } + /** + * Version of module. + * + * @return string + */ + public function getVersion(): string + { + return $this->version; + } + /** * Enabled of module. * @@ -179,6 +224,16 @@ class Module $this->description = $description; } + /** + * Set module's directory. + * + * @param string $directory + */ + public function setDirectory($directory) + { + $this->directory = $directory; + } + /** * Set module's entry. * @@ -199,12 +254,22 @@ class Module $this->installed = $installed; } + /** + * Set module's identification. + * + * @param string $identification + */ + public function setIdentification($identification) + { + $this->identification = $identification; + } + /** * Set module's name. * * @param string $name */ - public function setName($name) + public function setName(string $name) { $this->name = $name; } @@ -228,4 +293,14 @@ class Module { $this->stylesheet = $stylesheet; } + + /** + * Set module's version. + * + * @param string $version + */ + public function setVersion(string $version) + { + $this->version = $version; + } } diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index 2750fd8491f45d2e60cbb7eedc6f97b22de7fc51..be53e49bf53bf39a5f6f13c8e36e1a76fa2084b6 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -68,12 +68,24 @@ class ModuleManager return $list; } $this->modules->each(function (Module $module) use ($list) { - $module->isEnabled() && $list->push($module); + $module->isEnabled() && $list->put($module->getIdentification(), $module); }); 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. * @@ -86,24 +98,38 @@ 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.' . $identification . '.enabled', false) : false; + $module->setEnabled($status); $provider = ''; if ($entries = data_get($package, 'autoload.psr-4')) { foreach ($entries as $namespace => $entry) { $provider = $namespace . 'ModuleServiceProvider'; - $module->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('Module load fail!'); + } + } else { + throw new \Exception('Module load fail!'); + } + } + $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'])); - $status = $this->container->isInstalled() ? $this->container->make('setting')->get('module.' . $name . '.enabled', false) : false; - $module->setEnabled($status); - $this->modules->put($directory, $module); + method_exists($provider, 'version') && $module->setVersion(call_user_func([$provider, 'version'])); + $this->modules->put($identification, $module); } } }); @@ -113,6 +139,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. * diff --git a/src/Module/ModuleServiceProvider.php b/src/Module/ModuleServiceProvider.php index e400400926b744b3e387357a4021c5218744f849..420d9053ec35336d9c00faa43de6aacb215a31e7 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,18 +22,35 @@ use Notadd\Foundation\Module\Listeners\RouteRegister; */ class ModuleServiceProvider extends ServiceProvider { + /** + * @var \Illuminate\Filesystem\Filesystem + */ + protected $files; + + /** + * ModuleServiceProvider constructor. + * + * @param \Illuminate\Contracts\Foundation\Application $app + */ + public function __construct(Application $app) + { + parent::__construct($app); + $this->files = $app->make(Filesystem::class); + } + /** * 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->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 = $module->getDirectory(); + if ($this->files->isDirectory($path) && is_string($module->getEntry())) { $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 diff --git a/src/Navigation/Listeners/RouteRegister.php b/src/Navigation/Listeners/RouteRegister.php index 4baac58c9c6a685134c559caabd84c362d804a42..4695fa612c79f5ed876020cbdb02a2d48eb153b5 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/Abstracts/DataHandler.php b/src/Passport/Abstracts/DataHandler.php index 65827d56092d3766716c1d1fc01df4b90a6b2992..c6dd020687b4c3ca54315fce20b83a1babe9765e 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; } /** @@ -66,18 +70,26 @@ abstract class DataHandler extends Handler */ public function toResponse() { - $data = $this->data(); - if (empty($data)) { - $messages = $this->errors(); - } else { - $messages = $this->messages(); - } $response = new ApiResponse(); + try { + $data = $this->data(); + if (empty($data)) { + $messages = $this->errors(); + } else { + $messages = $this->messages(); + } - return $response->withParams([ - 'code' => $this->code(), - 'data' => $data, - 'message' => $messages, - ]); + return $response->withParams([ + 'code' => $this->code(), + 'data' => $data, + 'message' => $messages, + ]); + } catch (Exception $exception) { + return $response->withParams([ + 'code' => $exception->getCode(), + 'message' => $exception->getMessage(), + 'trace' => $exception->getTrace(), + ]); + } } } diff --git a/src/Passport/Abstracts/Handler.php b/src/Passport/Abstracts/Handler.php index afe1fd9020dcb3937416f2cca460570ea40e6bbb..990dda1ee1a93ebbd0411ce931927f8cc6ceaa40 100644 --- a/src/Passport/Abstracts/Handler.php +++ b/src/Passport/Abstracts/Handler.php @@ -18,6 +18,17 @@ use Notadd\Foundation\Validation\ValidatesRequests; abstract class Handler { use ValidatesRequests; + + /** + * @var int + */ + protected $code = 200; + + /** + * @var array + */ + protected $errors = []; + /** * @var \Illuminate\Container\Container|\Notadd\Foundation\Application */ @@ -28,6 +39,11 @@ abstract class Handler */ protected $log; + /** + * @var array + */ + protected $messages = []; + /** * @var \Illuminate\Http\Request */ @@ -55,32 +71,65 @@ abstract class Handler * Http code. * * @return int - * @throws \Exception */ - public function code() + protected function code() { - throw new Exception('Code is not setted!'); + return $this->code; } /** * Errors for handler. * * @return array - * @throws \Exception */ - public function errors() + protected function errors() { - throw new Exception('Error is not setted!'); + return $this->errors; } /** * Messages for handler. * * @return array - * @throws \Exception */ - public function messages() + protected function messages() + { + return $this->messages; + } + + /** + * @param int $code + * + * @return $this + */ + protected function withCode($code) { - throw new Exception('Message is not setted!'); + $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; } } diff --git a/src/Passport/Abstracts/SetHandler.php b/src/Passport/Abstracts/SetHandler.php index 80dacd2d2d7170f9eec17a6991268f0c2eb7c4ad..3c4c4cea3e5e902fd00bff6b86c88e053c737fe8 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; } /** @@ -56,18 +56,26 @@ abstract class SetHandler extends DataHandler */ public function toResponse() { - $result = $this->execute(); - if ($result) { - $messages = $this->messages(); - } else { - $messages = $this->errors(); - } $response = new ApiResponse(); + try { + $result = $this->execute(); + if ($result) { + $messages = $this->messages(); + } else { + $messages = $this->errors(); + } - return $response->withParams([ - 'code' => $this->code(), - 'data' => $this->data(), - 'message' => $messages, - ]); + return $response->withParams([ + 'code' => $this->code(), + 'data' => $this->data(), + 'message' => $messages, + ]); + } catch (Exception $exception) { + return $response->withParams([ + 'code' => $exception->getCode(), + 'message' => $exception->getMessage(), + 'trace' => $exception->getTrace(), + ]); + } } } diff --git a/src/Passport/Controllers/AccessTokenController.php b/src/Passport/Controllers/AccessTokenController.php index 325c6b970805fbca2e1634fb12b5e469fba1c780..f92ada7b9c9a511412d814d2fde89b19033da14f 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; @@ -93,29 +92,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); } } diff --git a/src/Passport/Controllers/AuthorizationController.php b/src/Passport/Controllers/AuthorizationController.php index 47e3f3229745640102ab24e8b55c332bfea723fd..3843e5f92889b416cd8bab3d57234455252096a4 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 7745d0b1cc6ecf9e5437b127611d6b3452285b11..a34fc77d5e8eae9638bc06804b58003e5e229471 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/Listeners/RouterRegistrar.php b/src/Passport/Listeners/RouterRegister.php similarity index 94% rename from src/Passport/Listeners/RouterRegistrar.php rename to src/Passport/Listeners/RouterRegister.php index 53ce362a181f7da3cc31563206e7f84ae5b58dcf..e6dbefaf5b5b99f5b09aee257f9578d89420f254 100644 --- a/src/Passport/Listeners/RouterRegistrar.php +++ b/src/Passport/Listeners/RouterRegister.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 3c008cf3131e0391cb449a210569775b97566719..55dbe492a337bd690f688f93b920a8f827c2d0f9 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/Passport/Responses/ApiResponse.php b/src/Passport/Responses/ApiResponse.php index 9b6668d625167e5e7c1a10c382d0e22c04b6b855..ce86dcf930b0398b9f592d2a359be5dd06125dd2 100644 --- a/src/Passport/Responses/ApiResponse.php +++ b/src/Passport/Responses/ApiResponse.php @@ -33,7 +33,9 @@ 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); + $status > 598 && $status = 500; + $response = $response->withStatus($status) ->withHeader('pragma', 'no-cache') ->withHeader('cache-control', 'no-store') ->withHeader('content-type', 'application/json; charset=UTF-8'); 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 6747e9a550f2e41996564696a9206b2a1b5d933f..463aac9629afd027f7df8dd1b2019e516465a3a8 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/Routing/RoutingServiceProvider.php b/src/Routing/RoutingServiceProvider.php index da6dc857576c40e491225472e5c166eb7b7be393..722838ca952406ab4120dd0dcb1b54c41c206808 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']); diff --git a/src/SearchEngine/Controllers/SeoController.php b/src/SearchEngine/Controllers/SeoController.php index 108c8b0818e3dffbef10662c4ba4f4a5b34e7452..f2849481f89315ca57438d47f0e26361289fa4b6 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. * diff --git a/src/SearchEngine/Listeners/RouterRegistrar.php b/src/SearchEngine/Listeners/RouterRegister.php similarity index 81% rename from src/SearchEngine/Listeners/RouterRegistrar.php rename to src/SearchEngine/Listeners/RouterRegister.php index 56c14fadc5cc26ff226e726638fd91217b8bffe7..c9feb3381520791e4050104dedfc1a0cc1866c0b 100644 --- a/src/SearchEngine/Listeners/RouterRegistrar.php +++ b/src/SearchEngine/Listeners/RouterRegister.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 0cb808968a23d512eb2c7ae8a7ffb96c4cc70759..a763766a9b0c35cf3329e12aa7ec542d45e3db18 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/Controllers/SettingController.php b/src/Setting/Controllers/SettingController.php index 1eea83ba91c8ad07cd64e36c776876a1b1e84b93..9937217a13cc7dbbb01e3d8b06a72eeabb4d0ec1 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. * diff --git a/src/Setting/Listeners/RouteRegistrar.php b/src/Setting/Listeners/RouteRegister.php similarity index 83% rename from src/Setting/Listeners/RouteRegistrar.php rename to src/Setting/Listeners/RouteRegister.php index 3af55b1f5e03a853c86bc4b97d12d4dd833ef187..f687200f8cebcf03fdd305d6b0eb6fa4084f6e83 100644 --- a/src/Setting/Listeners/RouteRegistrar.php +++ b/src/Setting/Listeners/RouteRegister.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 6d09554cf6b389bc3dc2ca7a00f90802abacba7d..ccc43781ea5f97a38c7b8b06221484f7d983ad8d 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/RouteRegister.php similarity index 75% rename from src/Sitemap/Listeners/RouteRegistrar.php rename to src/Sitemap/Listeners/RouteRegister.php index 97d56ef9d0af000f2db58d130ee42c08c1a9f3db..cc4d3122dd7fb4cfa65661b613fc72a2b42540b0 100644 --- a/src/Sitemap/Listeners/RouteRegistrar.php +++ b/src/Sitemap/Listeners/RouteRegister.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 34dd56978bd72d4fa7dc4f42e0414bc808239f45..44f59330fffeec82e254a4d2f1a1a69d3675b6df 100644 --- a/src/Sitemap/SitemapServiceProvider.php +++ b/src/Sitemap/SitemapServiceProvider.php @@ -11,9 +11,10 @@ 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; +use Notadd\Foundation\Sitemap\Listeners\RouteRegister; /** * Class SitemapServiceProvider. @@ -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)) { @@ -41,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() diff --git a/src/Testing/Concerns/MocksApplicationServices.php b/src/Testing/Concerns/MocksApplicationServices.php index 6868af4d07fe7d62113d561f9c57f8e267b7ca3d..d70270803a3da30629defb523f85fcf099b101e0 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); diff --git a/src/Translation/Events/LocaleUpdated.php b/src/Translation/Events/LocaleUpdated.php new file mode 100644 index 0000000000000000000000000000000000000000..10ffa4c869bc8d4f6b7ee935201b4f0338d67935 --- /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/Passport/Traits/PassportHelpers.php b/src/Translation/TranslationServiceProvider.php similarity index 32% rename from src/Passport/Traits/PassportHelpers.php rename to src/Translation/TranslationServiceProvider.php index fc53ea2314fc008027382dfd3fd04d1d3373e233..2f45094a58fd75d3ec583f02ec08669a9033ac56 100644 --- a/src/Passport/Traits/PassportHelpers.php +++ b/src/Translation/TranslationServiceProvider.php @@ -4,14 +4,15 @@ * * @author TwilRoad <269044570@qq.com> * @copyright (c) 2017, iBenchu.org - * @datetime 2017-01-08 20:07 + * @datetime 2017-03-01 15:27 */ -namespace Notadd\Foundation\Passport\Traits; +namespace Notadd\Foundation\Translation; + +use Illuminate\Translation\TranslationServiceProvider as IlluminateTranslationServiceProvider; /** - * Class PassportHelpers. + * Class TranslationServiceProvider. */ -trait PassportHelpers +class TranslationServiceProvider extends IlluminateTranslationServiceProvider { - } diff --git a/src/helpers.php b/src/helpers.php index c7686c24fe3ed5baa0e5443a7ba2fd2741406f80..43f3f19b107d950b63d183d9cbee971544184b51 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.'); } @@ -499,7 +500,7 @@ if (!function_exists('event')) { */ function event(...$args) { - return app('events')->fire(...$args); + return app('events')->dispatch(...$args); } }