diff --git a/composer.json b/composer.json index 1ae0cb647cbb1fed849294effa36c2686e15ffa6..f6a7ac406bae3527ae1da2f6f66e448ea99a9b43 100644 --- a/composer.json +++ b/composer.json @@ -30,65 +30,64 @@ "php": ">=7.0", "ext-mbstring": "*", "ext-openssl": "*", + "classpreloader/classpreloader": "~3.0", "doctrine/inflector": "~1.0", - "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.*", + "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.*", "jeremeamia/superclosure": "~2.2", - "laravel/passport": "^2.0", + "laravel/passport": "^1.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.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", + "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.*", "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.7", + "phpunit/phpunit": "~5.4", "predis/predis": "~1.0", - "symfony/css-selector": "3.2.*", - "symfony/dom-crawler": "3.2.*" + "symfony/css-selector": "3.1.*", + "symfony/dom-crawler": "3.1.*" }, "minimum-stability": "dev" } \ No newline at end of file diff --git a/configurations/app.php b/configurations/app.php index 32b1ccf269f11b733fd781a9225f4ace2a2ccf27..b9954eaa24e94f276c436840af4d5c38fd368178 100644 --- a/configurations/app.php +++ b/configurations/app.php @@ -20,19 +20,21 @@ return [ 'log' => env('APP_LOG', 'daily'), 'log_level' => env('APP_LOG_LEVEL', 'debug'), 'providers' => [ + Notadd\Foundation\Console\ArtisanServiceProvider::class, Notadd\Foundation\Attachment\AttachmentServiceProvider::class, Notadd\Foundation\Auth\AuthServiceProvider::class, Illuminate\Broadcasting\BroadcastServiceProvider::class, Notadd\Foundation\Bus\BusServiceProvider::class, Notadd\Foundation\Cache\CacheServiceProvider::class, Notadd\Foundation\Composer\ComposerServiceProvider::class, - Notadd\Foundation\Console\ConsoleServiceProvider::class, + Illuminate\Queue\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, @@ -49,11 +51,13 @@ 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, - Notadd\Foundation\Translation\TranslationServiceProvider::class, + Illuminate\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 5c93271b7096b41fc7e3eff853e2553fec3f6ebb..b6987fe3cd9d0da064993dafa7b10a05d18c5a79 100644 --- a/src/Application.php +++ b/src/Application.php @@ -12,16 +12,14 @@ 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\LoadEnvironmentVariables; +use Notadd\Foundation\Bootstrap\DetectEnvironment; 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; @@ -36,7 +34,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn /** * @var string */ - const VERSION = '0.2.1'; + const VERSION = '1.0'; /** * @var string @@ -162,7 +160,6 @@ 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)); } @@ -178,9 +175,9 @@ class Application extends Container implements ApplicationContract, HttpKernelIn { $this->hasBeenBootstrapped = true; foreach ($bootstrappers as $bootstrapper) { - $this['events']->dispatch('bootstrapping: ' . $bootstrapper, [$this]); + $this['events']->fire('bootstrapping: ' . $bootstrapper, [$this]); $this->make($bootstrapper)->bootstrap($this); - $this['events']->dispatch('bootstrapped: ' . $bootstrapper, [$this]); + $this['events']->fire('bootstrapped: ' . $bootstrapper, [$this]); } } @@ -191,7 +188,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn */ public function afterLoadingEnvironment(Closure $callback) { - return $this->afterBootstrapping(LoadEnvironmentVariables::class, $callback); + return $this->afterBootstrapping(DetectEnvironment::class, $callback); } /** @@ -607,7 +604,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn */ protected function markAsRegistered($provider) { - $this['events']->dispatch($class = get_class($provider), [$provider]); + $this['events']->fire($class = get_class($provider), [$provider]); $this->serviceProviders[] = $provider; $this->loadedProviders[$class] = true; } @@ -1017,7 +1014,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn { $this['config']->set('app.locale', $locale); $this['translator']->setLocale($locale); - $this['events']->dispatch(LocaleUpdated::class, [$locale]); + $this['events']->fire('locale.changed', [$locale]); } /** @@ -1038,115 +1035,124 @@ class Application extends Container implements ApplicationContract, HttpKernelIn public function registerCoreContainerAliases() { $aliases = [ - 'administration' => [\Notadd\Foundation\Administration\Administration::class], + 'administration' => ['Notadd\Foundation\Administration\Administration'], 'app' => [ - \Illuminate\Contracts\Container\Container::class, - \Illuminate\Contracts\Foundation\Application::class, - \Notadd\Foundation\Application::class, + 'Illuminate\Contracts\Container\Container', + 'Illuminate\Contracts\Foundation\Application', + 'Notadd\Foundation\Application', ], 'auth' => [ - \Illuminate\Auth\AuthManager::class, - \Illuminate\Contracts\Auth\Factory::class, + 'Illuminate\Auth\AuthManager', + 'Illuminate\Contracts\Auth\Factory', ], - 'blade.compiler' => [\Illuminate\View\Compilers\BladeCompiler::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'], 'cache' => [ - \Illuminate\Cache\CacheManager::class, - \Illuminate\Contracts\Cache\Factory::class, + 'Illuminate\Cache\CacheManager', + 'Illuminate\Contracts\Cache\Factory', ], 'cache.store' => [ - \Illuminate\Cache\Repository::class, - \Illuminate\Contracts\Cache\Repository::class, + 'Illuminate\Cache\Repository', + 'Illuminate\Contracts\Cache\Repository', ], + 'composer' => ['Illuminate\Support\Composer'], 'config' => [ - \Illuminate\Contracts\Config\Repository::class, - \Notadd\Foundation\Configuration\Repository::class, + 'Illuminate\Contracts\Config\Repository', + 'Notadd\Foundation\Configuration\Repository', ], 'cookie' => [ - \Illuminate\Cookie\CookieJar::class, - \Illuminate\Contracts\Cookie\Factory::class, - \Illuminate\Contracts\Cookie\QueueingFactory::class, + 'Illuminate\Cookie\CookieJar', + 'Illuminate\Contracts\Cookie\Factory', + 'Illuminate\Contracts\Cookie\QueueingFactory', ], 'encrypter' => [ - \Illuminate\Encryption\Encrypter::class, - \Illuminate\Contracts\Encryption\Encrypter::class, + 'Illuminate\Encryption\Encrypter', + 'Illuminate\Contracts\Encryption\Encrypter', ], - 'db' => [\Illuminate\Database\DatabaseManager::class], + 'db' => ['Illuminate\Database\DatabaseManager'], 'db.connection' => [ - \Illuminate\Database\Connection::class, - \Illuminate\Database\ConnectionInterface::class, + 'Illuminate\Database\Connection', + 'Illuminate\Database\ConnectionInterface', ], - 'extension' => [\Notadd\Foundation\Extension\ExtensionManager::class], + 'extension' => ['Notadd\Foundation\Extension\ExtensionManager'], 'events' => [ - \Illuminate\Events\Dispatcher::class, - \Illuminate\Contracts\Events\Dispatcher::class, + 'Illuminate\Events\Dispatcher', + 'Illuminate\Contracts\Events\Dispatcher', ], - 'files' => [\Illuminate\Filesystem\Filesystem::class], + 'files' => ['Illuminate\Filesystem\Filesystem'], 'filesystem' => [ - \Illuminate\Filesystem\FilesystemManager::class, - \Illuminate\Contracts\Filesystem\Factory::class, + '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', ], - '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::class, - \Illuminate\Contracts\Logging\Log::class, - \Psr\Log\LoggerInterface::class, + 'Illuminate\Log\Writer', + 'Illuminate\Contracts\Logging\Log', + 'Psr\Log\LoggerInterface', ], 'mailer' => [ - \Illuminate\Mail\Mailer::class, - \Illuminate\Contracts\Mail\Mailer::class, - \Illuminate\Contracts\Mail\MailQueue::class, + 'Illuminate\Mail\Mailer', + 'Illuminate\Contracts\Mail\Mailer', + 'Illuminate\Contracts\Mail\MailQueue', ], - 'member' => [\Notadd\Foundation\Member\MemberManagement::class], - 'module' => [\Notadd\Foundation\Module\ModuleManager::class], + 'member' => ['Notadd\Foundation\Member\MemberManagement'], + 'module' => ['Notadd\Foundation\Module\ModuleManager'], 'queue' => [ - \Illuminate\Queue\QueueManager::class, - \Illuminate\Contracts\Queue\Factory::class, - \Illuminate\Contracts\Queue\Monitor::class, + 'Illuminate\Queue\QueueManager', + 'Illuminate\Contracts\Queue\Factory', + 'Illuminate\Contracts\Queue\Monitor', ], - 'queue.connection' => [\Illuminate\Contracts\Queue\Queue::class], - 'queue.failer' => [\Illuminate\Queue\Failed\FailedJobProviderInterface::class], + 'queue.connection' => ['Illuminate\Contracts\Queue\Queue'], + 'queue.failer' => ['Illuminate\Queue\Failed\FailedJobProviderInterface'], 'redirect' => [ - \Illuminate\Routing\Redirector::class, - \Notadd\Foundation\Routing\Redirector::class, + 'Illuminate\Routing\Redirector', + 'Notadd\Foundation\Routing\Redirector', ], 'redis' => [ - \Illuminate\Redis\RedisManager::class, - \Illuminate\Contracts\Redis\Factory::class, + 'Illuminate\Redis\Database', + 'Illuminate\Contracts\Redis\Database', ], 'request' => [ - \Illuminate\Http\Request::class, - \Symfony\Component\HttpFoundation\Request::class, + 'Illuminate\Http\Request', + 'Symfony\Component\HttpFoundation\Request', ], 'router' => [ - \Illuminate\Routing\Router::class, - \Illuminate\Contracts\Routing\Registrar::class, + 'Illuminate\Routing\Router', + 'Illuminate\Contracts\Routing\Registrar', ], - 'searchengine.optimization' => [\Notadd\Foundation\SearchEngine\Optimization::class], - 'session' => [\Illuminate\Session\SessionManager::class], + 'searchengine.optimization' => ['Notadd\Foundation\SearchEngine\Optimization'], + 'session' => ['Illuminate\Session\SessionManager'], 'session.store' => [ - \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, + 'Illuminate\Session\Store', + 'Symfony\Component\HttpFoundation\Session\SessionInterface', ], + 'setting' => ['Notadd\Foundation\Setting\Contracts\SettingsRepository'], + 'theme' => ['Notadd\Foundation\Theme\ThemeManager'], 'url' => [ - \Illuminate\Routing\UrlGenerator::class, - \Illuminate\Contracts\Routing\UrlGenerator::class, + 'Illuminate\Routing\UrlGenerator', + 'Illuminate\Contracts\Routing\UrlGenerator', ], 'validator' => [ - \Illuminate\Validation\Factory::class, - \Illuminate\Contracts\Validation\Factory::class, + 'Illuminate\Validation\Factory', + 'Illuminate\Contracts\Validation\Factory', ], 'view' => [ - \Illuminate\View\Factory::class, - \Illuminate\Contracts\View\Factory::class, + 'Illuminate\View\Factory', + 'Illuminate\Contracts\View\Factory', ], ]; foreach ($aliases as $key => $aliases) { diff --git a/src/Attachment/AttachmentServiceProvider.php b/src/Attachment/AttachmentServiceProvider.php index 1419167d4abefb270c3890c3260b467b3c5918b5..6e876d5c425a6634e885e45fe5432a24656a9747 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\RouteRegister; +use Notadd\Foundation\Attachment\Listeners\RouteRegistrar; /** * 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(RouteRegister::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); } } diff --git a/src/Attachment/Controllers/AttachmentController.php b/src/Attachment/Controllers/AttachmentController.php index 5d7ff42b46319393b58f862008759f666a665cd0..63ed876ed6b09d1484279e73421c98b7853b51b9 100644 --- a/src/Attachment/Controllers/AttachmentController.php +++ b/src/Attachment/Controllers/AttachmentController.php @@ -10,12 +10,31 @@ namespace Notadd\Foundation\Attachment\Controllers; use Notadd\Foundation\Attachment\Handlers\AttachmentSetHandler; use Notadd\Foundation\Routing\Abstracts\Controller; +use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** - * Class AttachmentController. + * Class AttachmentApi. */ 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 c2e1ecb41f1286d0b77261e028d1aa831e57d16e..f60091f76eccad7792821621abbd4ac273868698 100644 --- a/src/Attachment/Controllers/CdnController.php +++ b/src/Attachment/Controllers/CdnController.php @@ -10,12 +10,31 @@ namespace Notadd\Foundation\Attachment\Controllers; use Notadd\Foundation\Attachment\Handlers\CdnSetHandler; use Notadd\Foundation\Routing\Abstracts\Controller; +use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** - * Class CdnController. + * Class CdnApi. */ 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 d8ada9bca5c8f77d0863e6cff915ce6b90d28b86..04b0eaba1ac9ec6fb9953bc1b8638e579947f42c 100644 --- a/src/Attachment/Controllers/StorageController.php +++ b/src/Attachment/Controllers/StorageController.php @@ -10,12 +10,28 @@ 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 2267892e69239d13ce83d36afba232a463688885..d1e55695b96a6027933dded9d628b8512f2c9c05 100644 --- a/src/Attachment/Controllers/WatermarkController.php +++ b/src/Attachment/Controllers/WatermarkController.php @@ -10,12 +10,28 @@ 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/RouteRegister.php b/src/Attachment/Listeners/RouteRegistrar.php similarity index 86% rename from src/Attachment/Listeners/RouteRegister.php rename to src/Attachment/Listeners/RouteRegistrar.php index 1ab84886ab50d59f1721d8dbadd19253c9b86924..31465a28d9ef66d85f58c10ce8e52645d4dfb581 100644 --- a/src/Attachment/Listeners/RouteRegister.php +++ b/src/Attachment/Listeners/RouteRegistrar.php @@ -11,12 +11,12 @@ namespace Notadd\Foundation\Attachment\Listeners; use Notadd\Foundation\Attachment\Controllers\AttachmentController; use Notadd\Foundation\Attachment\Controllers\CdnController; use Notadd\Foundation\Attachment\Controllers\StorageController; -use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; /** * Class RouteRegistrar. */ -class RouteRegister extends AbstractRouteRegister +class RouteRegistrar extends AbstractRouteRegistrar { /** * Handle Route Registrar. diff --git a/src/Auth/AuthServiceProvider.php b/src/Auth/AuthServiceProvider.php index 32742c3f2e2c631208cd753c6460475cb534a075..5be41306c8f42aa0b705e0d6daa6d6ea66e67311 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\RouteRegister; +use Notadd\Foundation\Auth\Listeners\RouteRegistrar; /** * Class AuthServiceProvider. @@ -22,6 +22,6 @@ class AuthServiceProvider extends IlluminateAuthServiceProvider */ public function boot() { - $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); } } diff --git a/src/Auth/Listeners/RouteRegister.php b/src/Auth/Listeners/RouteRegistrar.php similarity index 88% rename from src/Auth/Listeners/RouteRegister.php rename to src/Auth/Listeners/RouteRegistrar.php index 173b9f345f711ba61e1663d3e3ac69f09065a5c9..a40c98cf7eaab0ab5e3ac54609986de9f90aafc1 100644 --- a/src/Auth/Listeners/RouteRegister.php +++ b/src/Auth/Listeners/RouteRegistrar.php @@ -9,12 +9,12 @@ namespace Notadd\Foundation\Auth\Listeners; use Notadd\Foundation\Auth\Controllers\AuthController; -use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; /** * Class RouterRegistrar. */ -class RouteRegister extends AbstractRouteRegister +class RouteRegistrar extends AbstractRouteRegistrar { /** * Handle Route Registrar. diff --git a/src/Bootstrap/LoadEnvironmentVariables.php b/src/Bootstrap/DetectEnvironment.php similarity index 98% rename from src/Bootstrap/LoadEnvironmentVariables.php rename to src/Bootstrap/DetectEnvironment.php index cd6091eec65793b4ed5e1f05d1ef805a296a048c..1fee8cf99ad5efc3fca33610ffe2c85f3ea9a2e9 100644 --- a/src/Bootstrap/LoadEnvironmentVariables.php +++ b/src/Bootstrap/DetectEnvironment.php @@ -16,7 +16,7 @@ use Symfony\Component\Console\Input\ArgvInput; /** * Class DetectEnvironment. */ -class LoadEnvironmentVariables +class DetectEnvironment { /** * Bootstrap the given application. diff --git a/src/Composer/ComposerScripts.php b/src/Composer/ComposerScripts.php index 941189ef1d7fa3666bad5c388d48cf7fa434c0b0..39aec499ec143f9d07597505a4501613a699fec2 100644 --- a/src/Composer/ComposerScripts.php +++ b/src/Composer/ComposerScripts.php @@ -47,6 +47,12 @@ class ComposerScripts */ protected static function clearCompiled() { - file_exists($servicesPath = (new Application(getcwd()))->getCachedCompilePath()) && @unlink($servicesPath); + $laravel = new Application(getcwd()); + if (file_exists($compiledPath = $laravel->getCachedCompilePath())) { + @unlink($compiledPath); + } + if (file_exists($servicesPath = $laravel->getCachedServicesPath())) { + @unlink($servicesPath); + } } } diff --git a/src/Console/Application.php b/src/Console/Application.php index e269f57e17bb4d66484f60e06063a579854e873c..3e5ce1d19f74747818f0ff0e5d5a32d2cd6822a8 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -48,16 +48,14 @@ 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 = [], $outputBuffer = null) + public function call($command, array $parameters = []) { $parameters = collect($parameters)->prepend($command); - $this->lastOutput = $outputBuffer ?: new BufferedOutput(); + $this->lastOutput = new BufferedOutput(); $this->setCatchExceptions(false); $result = $this->run(new ArrayInput($parameters->toArray()), $this->lastOutput); $this->setCatchExceptions(true); diff --git a/src/Console/ConsoleServiceProvider.php b/src/Console/ArtisanServiceProvider.php similarity index 79% rename from src/Console/ConsoleServiceProvider.php rename to src/Console/ArtisanServiceProvider.php index 311755ee6d1ff788c3a8928be3e70e60e03ae19c..8b8e77211ae900053ad9fd5c06e2f60f0d532124 100644 --- a/src/Console/ConsoleServiceProvider.php +++ b/src/Console/ArtisanServiceProvider.php @@ -10,13 +10,6 @@ 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; @@ -31,6 +24,7 @@ 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; @@ -51,7 +45,7 @@ use Notadd\Foundation\Session\Commands\SessionTableCommand; /** * Class ArtisanServiceProvider. */ -class ConsoleServiceProvider extends ServiceProvider +class ArtisanServiceProvider extends ServiceProvider { /** * @var bool @@ -62,32 +56,28 @@ class ConsoleServiceProvider 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', - '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', + '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', ]; /** * @var array */ protected $devCommands = [ + //'AppName' => 'command.app.name', 'AuthMake' => 'command.auth.make', 'CacheTable' => 'command.cache.table', 'ConsoleMake' => 'command.console.make', @@ -318,93 +308,6 @@ class ConsoleServiceProvider 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. */ @@ -545,6 +448,16 @@ class ConsoleServiceProvider extends ServiceProvider }); } + /** + * Register the command. + */ + protected function registerTinkerCommand() + { + $this->app->singleton('command.tinker', function () { + return new TinkerCommand(); + }); + } + /** * Register the command. */ diff --git a/src/Console/Commands/OptimizeCommand.php b/src/Console/Commands/OptimizeCommand.php index 8cd1f03eb06e1c2826feca36f7ec9a81bdfb29a5..09b00c093213c8b7f655a29ad32a855dc8b1259c 100644 --- a/src/Console/Commands/OptimizeCommand.php +++ b/src/Console/Commands/OptimizeCommand.php @@ -8,6 +8,8 @@ */ 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; @@ -17,6 +19,195 @@ 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 */ @@ -54,7 +245,50 @@ class OptimizeCommand extends Command } else { $this->composer->dumpOptimized(); } - $this->call('clear-compiled'); + 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); } /** diff --git a/src/Console/Commands/TinkerCommand.php b/src/Console/Commands/TinkerCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..5c419e9251f5e796a34264a1cbb62b4f4215f27f --- /dev/null +++ b/src/Console/Commands/TinkerCommand.php @@ -0,0 +1,104 @@ + + * @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/Kernel.php b/src/Console/Kernel.php index 30a42abdd226ffb8e5f0571d90ee76ee18b676a2..6ea311b9ac8cc6954426a233261e99d039af83f5 100644 --- a/src/Console/Kernel.php +++ b/src/Console/Kernel.php @@ -12,13 +12,12 @@ 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\LoadEnvironmentVariables; +use Notadd\Foundation\Bootstrap\DetectEnvironment; use Notadd\Foundation\Bootstrap\HandleExceptions; use Notadd\Foundation\Bootstrap\LoadConfiguration; use Notadd\Foundation\Bootstrap\LoadSetting; @@ -66,7 +65,7 @@ class Kernel implements KernelContract * @var array */ protected $bootstrappers = [ - LoadEnvironmentVariables::class, + DetectEnvironment::class, LoadConfiguration::class, ConfigureLogging::class, HandleExceptions::class, @@ -100,7 +99,7 @@ class Kernel implements KernelContract */ protected function defineConsoleSchedule() { - $this->app->instance(Schedule::class, $schedule = new Schedule($this->app[Cache::class])); + $this->app->instance('Illuminate\Console\Scheduling\Schedule', $schedule = new Schedule()); $this->schedule($schedule); } diff --git a/src/Database/MigrationServiceProvider.php b/src/Database/MigrationServiceProvider.php index 8982461a52e331b791ec61993d240dd53aefaa81..ebd2d6e129af6c6dccb1cbe66f6caa4039101b8d 100644 --- a/src/Database/MigrationServiceProvider.php +++ b/src/Database/MigrationServiceProvider.php @@ -8,6 +8,7 @@ */ 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; @@ -27,6 +28,16 @@ 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 0643d4e50de6c1fc34cd5b5797a0301c968cfeb2..d75037d61c2390a33670f253d13f0916e9c9696d 100644 --- a/src/Debug/Controllers/DebugController.php +++ b/src/Debug/Controllers/DebugController.php @@ -10,9 +10,10 @@ namespace Notadd\Foundation\Debug\Controllers; use Notadd\Foundation\Debug\Handlers\SetHandler; use Notadd\Foundation\Routing\Abstracts\Controller; +use Notadd\Foundation\Setting\Contracts\SettingsRepository; /** - * Class DebugController. + * Class DebugApi. */ class DebugController extends Controller { diff --git a/src/Debug/DebugServiceProvider.php b/src/Debug/DebugServiceProvider.php index b3112672f5e0b3c5976be99e0166c8ff5299123d..532f4c16e814a6483b9c48814d2b7aeea2d398f2 100644 --- a/src/Debug/DebugServiceProvider.php +++ b/src/Debug/DebugServiceProvider.php @@ -1,17 +1,16 @@ - * @copyright (c) 2017, iBenchu.org - * @datetime 2017-03-10 14:12 + * Created by PhpStorm. + * User: TwilRoad + * Date: 2016/11/16 0016 + * Time: 13:52. */ namespace Notadd\Foundation\Debug; use Illuminate\Events\Dispatcher; use Illuminate\Support\ServiceProvider; use Notadd\Foundation\Debug\Listeners\CsrfTokenRegister; -use Notadd\Foundation\Debug\Listeners\RouteRegister; +use Notadd\Foundation\Debug\Listeners\RouteRegistrar; /** * Class DebugServiceProvider. @@ -24,6 +23,6 @@ class DebugServiceProvider extends ServiceProvider public function boot() { $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); - $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); } } diff --git a/src/Debug/Listeners/RouteRegister.php b/src/Debug/Listeners/RouteRegistrar.php similarity index 62% rename from src/Debug/Listeners/RouteRegister.php rename to src/Debug/Listeners/RouteRegistrar.php index ad254c8532504295ed5ca970a9b99be3d7d00747..4b7b974bc544797cf9eda06f0db90bfda99f4d1f 100644 --- a/src/Debug/Listeners/RouteRegister.php +++ b/src/Debug/Listeners/RouteRegistrar.php @@ -1,20 +1,19 @@ - * @copyright (c) 2017, iBenchu.org - * @datetime 2017-03-10 14:12 + * Created by PhpStorm. + * User: TwilRoad + * Date: 2016/11/16 0016 + * Time: 13:54. */ namespace Notadd\Foundation\Debug\Listeners; use Notadd\Foundation\Debug\Controllers\DebugController; -use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; /** * Class RouteRegistrar. */ -class RouteRegister extends AbstractRouteRegister +class RouteRegistrar extends AbstractRouteRegistrar { /** * Handle Route Registrar. diff --git a/src/Editor/Controllers/UEditorController.php b/src/Editor/Controllers/UEditorController.php index 70124c0037aa7b16cca1bfd35352614867acb978..9d4fb6da2059cbb3967cdbf8466511e68b23d0e9 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('images'); + $this->image = $this->container->make('image'); $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' => asset($this->setting->get('attachment.watermark.file', 'watermark.png')), + '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')), ]; } diff --git a/src/Editor/EditorServiceProvider.php b/src/Editor/EditorServiceProvider.php index 9e6aeea6586f2e60d16e50c0d8cc8375029428ac..c50185325a0108e0ce24b6767850381f92df683f 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\RouteRegister; +use Notadd\Foundation\Editor\Listeners\RouteRegistrar; /** * 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(RouteRegister::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); } } diff --git a/src/Editor/Listeners/RouteRegister.php b/src/Editor/Listeners/RouteRegistrar.php similarity index 80% rename from src/Editor/Listeners/RouteRegister.php rename to src/Editor/Listeners/RouteRegistrar.php index 6773554b030fd021f7c32493fa66c88a1b3b7c37..8389b4e14015801a335bb24db42ab1067b09e646 100644 --- a/src/Editor/Listeners/RouteRegister.php +++ b/src/Editor/Listeners/RouteRegistrar.php @@ -9,12 +9,12 @@ namespace Notadd\Foundation\Editor\Listeners; use Notadd\Foundation\Editor\Controllers\UEditorController; -use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; /** * Class RouteRegistrar. */ -class RouteRegister extends AbstractRouteRegister +class RouteRegistrar extends AbstractRouteRegistrar { /** * Handle Route Registrar. diff --git a/src/Extension/Abstracts/Extension.php b/src/Extension/Abstracts/Extension.php index 98f28846331224e2f3e96a1e4e5aaf251290c3cc..7e7a87b640c38e16eef9f8c2c1d585aff9bdaf47 100644 --- a/src/Extension/Abstracts/Extension.php +++ b/src/Extension/Abstracts/Extension.php @@ -14,7 +14,7 @@ use Illuminate\Support\ServiceProvider; /** * Class Extension. */ -abstract class Extension extends ServiceProvider +class Extension extends ServiceProvider { /** * @var \Illuminate\Events\Dispatcher @@ -41,28 +41,8 @@ abstract class Extension extends ServiceProvider /** * Boot extension. */ - 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(); + public function boot() { + } /** * Register extension extra providers. @@ -70,18 +50,4 @@ abstract 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 deleted file mode 100644 index 1413020dd64b01607085c1117bbbc8a141feec8f..0000000000000000000000000000000000000000 --- a/src/Extension/Abstracts/Installer.php +++ /dev/null @@ -1,52 +0,0 @@ - - * @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 deleted file mode 100644 index 8b03757c76570232c14dc454d38f1e220e9887da..0000000000000000000000000000000000000000 --- a/src/Extension/Abstracts/Uninstaller.php +++ /dev/null @@ -1,52 +0,0 @@ - - * @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 494bfb7e7e1a94715a9683a06bc22d972594e506..c46fe24c1080b3db4339fcb853abd29ff8e76d79 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->getIdentification(), + $extension->getName(), $author, $extension->getDescription(), $path, diff --git a/src/Extension/Controllers/ExtensionController.php b/src/Extension/Controllers/ExtensionController.php index 623e1168f338a4618b41362e817982eb97a32332..aa2ea47b29ecbf3b4b62e652234a09cd232ed711 100644 --- a/src/Extension/Controllers/ExtensionController.php +++ b/src/Extension/Controllers/ExtensionController.php @@ -10,9 +10,6 @@ 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; /** @@ -45,43 +42,4 @@ 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 2759c15b2a038de0b662e5caf7374f13e9c2f11d..96674ea4ce84a9310a49e27f19590b233dae5882 100644 --- a/src/Extension/Extension.php +++ b/src/Extension/Extension.php @@ -23,11 +23,6 @@ class Extension */ protected $description; - /** - * @var string - */ - protected $directory; - /** * @var bool */ @@ -38,11 +33,6 @@ class Extension */ protected $entry; - /** - * @var string - */ - protected $identification; - /** * @var bool */ @@ -76,11 +66,11 @@ class Extension /** * Extension constructor. * - * @param string $identification + * @param string $name */ - public function __construct($identification) + public function __construct($name) { - $this->identification = $identification; + $this->name = $name; } /** @@ -99,16 +89,6 @@ class Extension return $this->description; } - /** - * Get directory of extension. - * - * @return string - */ - public function getDirectory(): string - { - return $this->directory; - } - /** * @return string */ @@ -120,25 +100,25 @@ class Extension /** * @return string */ - public function getIdentification(): string + public function getName(): string { - return $this->identification; + return $this->name; } /** * @return string */ - public function getName(): string + public function getPath(): string { - return $this->name; + return $this->path; } /** * @return string */ - public function getPath(): string + public function getVersion(): string { - return $this->path; + return $this->version; } /** @@ -161,14 +141,6 @@ class Extension return $this->stylesheet; } - /** - * @return string - */ - public function getVersion(): string - { - return $this->version; - } - /** * @return bool */ @@ -207,16 +179,6 @@ class Extension $this->description = $description; } - /** - * Set directory of extension. - * - * @param string $directory - */ - public function setDirectory(string $directory) - { - $this->directory = $directory; - } - /** * @param string $entry */ @@ -241,14 +203,6 @@ 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 cbb09d4c702704a31c67a8c21732ea22577b3f5a..e3b8c21661bbde4312b31b85b3e96780a77a1f1c 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -54,18 +54,6 @@ 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. * @@ -107,37 +95,23 @@ 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)); - $identification = Arr::get($package, 'name'); + $name = Arr::get($package, 'name'); $type = Arr::get($package, 'type'); - if ($type == 'notadd-extension' && $identification) { - $extension = new Extension($identification); + if ($type == 'notadd-extension' && $name) { + $extension = new Extension($name); $extension->setAuthor(Arr::get($package, 'authors')); $extension->setDescription(Arr::get($package, 'description')); - $extension->setDirectory($directory); - $extension->setEnabled($this->container->make('setting')->get('extension.' . $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'])); - method_exists($provider, 'version') && $extension->setVersion(call_user_func([$provider, 'version'])); - $this->extensions->put($identification, $extension); + $extension->setEnabled($this->container->make('setting')->get('extension.' . $name . '.enabled', false)); + $this->extensions->put($directory, $extension); } } }); @@ -148,18 +122,6 @@ 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 2578547e3945d8a4a181e0c199a9984faf86671f..dc8dc01c5e9afd2c307571816454cba5156e7443 100644 --- a/src/Extension/ExtensionServiceProvider.php +++ b/src/Extension/ExtensionServiceProvider.php @@ -8,9 +8,7 @@ */ 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; @@ -21,22 +19,6 @@ 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. * @@ -46,9 +28,8 @@ class ExtensionServiceProvider extends ServiceProvider { $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); - $this->app->make(ExtensionManager::class)->getExtensions()->each(function (Extension $extension) { - $path = $extension->getDirectory(); - if ($this->files->isDirectory($path) && is_string($extension->getEntry())) { + $this->app->make('extension')->getExtensions()->each(function (Extension $extension, $path) { + if ($this->app->make('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 07f2c3f94be1b754ed7c3e8a648cc1862999e0c0..65d32f8287ea1164bab84e0ee7129c6e814dbe81 100644 --- a/src/Extension/Handlers/ExtensionHandler.php +++ b/src/Extension/Handlers/ExtensionHandler.php @@ -61,7 +61,6 @@ 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 deleted file mode 100644 index da8da1241f67612228f04ea3158d2e11c26eb8f5..0000000000000000000000000000000000000000 --- a/src/Extension/Handlers/InstallHandler.php +++ /dev/null @@ -1,85 +0,0 @@ - - * @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 deleted file mode 100644 index d76d3cce8071d32f203def6a2d3aafc02d4aeddc..0000000000000000000000000000000000000000 --- a/src/Extension/Handlers/UninstallHandler.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @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 deleted file mode 100644 index 7822ec9df3ddade4031af260e4d9c890c6668d38..0000000000000000000000000000000000000000 --- a/src/Extension/Handlers/UpdateHandler.php +++ /dev/null @@ -1,78 +0,0 @@ - - * @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 13c027cf374bfaccb1e4b074a6ed318a63cabead..f08071b485e9090dcead1dc17f4e1945596573e7 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\RouteRegister as AbstractRouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; /** * Class RouteRegistrar. */ -class RouteRegister extends AbstractRouteRegister +class RouteRegister extends AbstractRouteRegistrar { /** * Handle Route Registrar. @@ -23,9 +23,6 @@ class RouteRegister extends AbstractRouteRegister { $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 deleted file mode 100644 index 47a2e3783ff2d45dcd406d7251adabcc02484fcc..0000000000000000000000000000000000000000 --- a/src/Http/Events/RequestHandled.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @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 d4b5dd62efe100382d3ead945ce6a72f0d14ee1e..e60a1ffc7a24c2c65eb9ed90871c7842dd4d5f3f 100644 --- a/src/Http/HttpServiceProvider.php +++ b/src/Http/HttpServiceProvider.php @@ -25,16 +25,26 @@ class HttpServiceProvider extends ServiceProvider */ public function boot() { - $this->app->afterResolving(ValidatesWhenResolved::class, function (ValidatesWhenResolved $resolved) { + 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) { $resolved->validate(); }); - $this->app->make('request')->getMethod() == 'OPTIONS' && $this->app->make(KernelContract::class)->prependMiddleware(CrossPreflight::class); - $this->app->resolving(FormRequest::class, function (FormRequest $request, $app) { + $this->app->resolving(function (FormRequest $request, $app) { $this->initializeRequest($request, $app['request']); - $request->setContainer($app)->setRedirector($this->app->make(Redirector::class)); + $request->setContainer($app)->setRedirector($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 45fb350459ec3da806f3905c1294938e7ad69078..89b6d32b74e7c6ad8dda71be0d853cba22c64499 100644 --- a/src/Http/Kernel.php +++ b/src/Http/Kernel.php @@ -28,14 +28,13 @@ 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\LoadEnvironmentVariables; +use Notadd\Foundation\Bootstrap\DetectEnvironment; 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; @@ -63,7 +62,7 @@ class Kernel implements KernelContract * @var array */ protected $bootstrappers = [ - LoadEnvironmentVariables::class, + DetectEnvironment::class, LoadConfiguration::class, ConfigureLogging::class, HandleExceptions::class, @@ -141,7 +140,7 @@ class Kernel implements KernelContract $router->middlewareGroup($key, $middleware); } foreach ($this->routeMiddleware as $key => $middleware) { - $router->aliasMiddleware($key, $middleware); + $router->middleware($key, $middleware); } } @@ -164,7 +163,7 @@ class Kernel implements KernelContract $this->reportException($e = new FatalThrowableError($e)); $response = $this->renderException($request, $e); } - $this->application['events']->dispatch(RequestHandled::class, [ + $this->application['events']->fire('kernel.handled', [ $request, $response, ]); diff --git a/src/Http/Middlewares/ValidatePostSize.php b/src/Http/Middlewares/VerifyPostSize.php similarity index 79% rename from src/Http/Middlewares/ValidatePostSize.php rename to src/Http/Middlewares/VerifyPostSize.php index 9080ba48da466c37920a0b3218e501502a4370f5..093b3a4371c02c819a2935e5a7412e005735888f 100644 --- a/src/Http/Middlewares/ValidatePostSize.php +++ b/src/Http/Middlewares/VerifyPostSize.php @@ -9,12 +9,12 @@ namespace Notadd\Foundation\Http\Middlewares; use Closure; -use Illuminate\Http\Exceptions\PostTooLargeException; +use Illuminate\Http\Exception\PostTooLargeException; /** * Class VerifyPostSize. */ -class ValidatePostSize +class VerifyPostSize { /** * Middleware handler. @@ -22,15 +22,13 @@ class ValidatePostSize * @param \Illuminate\Http\Request $request * @param \Closure $next * - * @throws \Illuminate\Http\Exceptions\PostTooLargeException + * @throws \Illuminate\Http\Exception\PostTooLargeException * @return mixed */ public function handle($request, Closure $next) { - $max = $this->getPostMaxSize(); - - if ($max > 0 && $request->server('CONTENT_LENGTH') > $max) { - throw new PostTooLargeException; + if ($request->server('CONTENT_LENGTH') > $this->getPostMaxSize()) { + throw new PostTooLargeException(); } return $next($request); diff --git a/src/Image/ImageServiceProvider.php b/src/Image/ImageServiceProvider.php index 703de5696dce9adda61e6884aafbf3297c9cba46..6826905a65547421f70701251fc725a251b61304 100644 --- a/src/Image/ImageServiceProvider.php +++ b/src/Image/ImageServiceProvider.php @@ -51,9 +51,10 @@ class ImageServiceProvider extends ServiceProvider */ public function register() { - $this->app->singleton('images', function () { + $this->app['image'] = $this->app->share(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 c9ea1f05130ef682cb5dd211bdb4ca0c0547b50c..2f9d2f821fd24bc1134e2f419304cd9e840b8fe1 100644 --- a/src/Mail/Controllers/MailController.php +++ b/src/Mail/Controllers/MailController.php @@ -11,12 +11,28 @@ 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/RouterRegister.php b/src/Mail/Listeners/RouterRegistrar.php similarity index 82% rename from src/Mail/Listeners/RouterRegister.php rename to src/Mail/Listeners/RouterRegistrar.php index 8f854b0af84321c6c4224cba8ff1aaffba8e808c..4d2dca035755026fe7100a9f746bf07acecceb30 100644 --- a/src/Mail/Listeners/RouterRegister.php +++ b/src/Mail/Listeners/RouterRegistrar.php @@ -9,12 +9,12 @@ namespace Notadd\Foundation\Mail\Listeners; use Notadd\Foundation\Mail\Controllers\MailController; -use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; /** * Class RouterRegistrar. */ -class RouterRegister extends AbstractRouteRegister +class RouterRegistrar extends AbstractRouteRegistrar { /** * Handle Route Registrar. diff --git a/src/Mail/MailServiceProvider.php b/src/Mail/MailServiceProvider.php index 48d14f009dd4455212b22e57bee13d9bc3ddce34..67f69e06f5100a87b67e30fd0b2789433732bf59 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\RouterRegister; +use Notadd\Foundation\Mail\Listeners\RouterRegistrar; /** * 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(RouterRegister::class); + $this->app->make(Dispatcher::class)->subscribe(RouterRegistrar::class); } } diff --git a/src/Member/Commands/PermissionCommand.php b/src/Member/Commands/PermissionCommand.php index b02362f5cee6c5a7a064dcd8081e598aa9074ee1..cbebe8accff3e0db18d4b2a8529830d8396319e2 100644 --- a/src/Member/Commands/PermissionCommand.php +++ b/src/Member/Commands/PermissionCommand.php @@ -77,20 +77,20 @@ class PermissionCommand extends Command $i = 0; - $frontPermissions = array_get($permissions, 'front', []); + $frontendPermissions = array_get($permissions, 'frontend', []); $adminPermissions = array_get($permissions, 'admin', []); // 添加前台权限 - foreach ($frontPermissions as $frontPermission) { - if (! isset($frontPermission['display_name']) || ! isset($frontPermission['name']) || empty($frontPermission['display_name']) || empty($frontPermission['name'])) { + foreach ($frontendPermissions as $frontendPermission) { + if (! isset($frontendPermission['display_name']) || ! isset($frontendPermission['name']) || empty($frontendPermission['display_name']) || empty($frontendPermission['name'])) { continue; } - if (Permission::whereFront($frontPermission['name'])->count()) { + if (Permission::where('name', $frontendPermission['name'])->count()) { continue; } - Permission::addFrontPermission($frontPermission['name'], $frontPermission['display_name'], isset($frontPermission['description']) ? $frontPermission['description'] : ''); + Permission::addPermission($frontendPermission['name'], $frontendPermission['display_name'], isset($frontendPermission['description']) ? $frontendPermission['description'] : ''); $i++; } diff --git a/src/Member/Member.php b/src/Member/Member.php index 62ac502a5c10b17bcdce5736360a7e49c7d68362..5b66baef50fe3ba895fa0a2e29f9285b48e135c9 100644 --- a/src/Member/Member.php +++ b/src/Member/Member.php @@ -164,34 +164,6 @@ 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. * @@ -202,9 +174,11 @@ class Member extends Authenticatable */ public function hasAdminPermission($name, $requireAll = false) { + $adminName = $name; + if (is_array($name)) { - $name = array_map(function ($val) { - if (ends_with($val, '*')) { + $adminName = array_map(function ($val) { + if (str_contains($val, '*')) { return $val; } @@ -212,12 +186,12 @@ class Member extends Authenticatable }, $name); } else { - if (! ends_with($name, '*')) { - $name = Permission::ADMIN_PREFIX . $name; + if (! str_contains($name, '*')) { + $adminName = Permission::ADMIN_PREFIX . $name; } } - return $this->hasPermission($name, $requireAll); + return $this->hasPermission($adminName, $requireAll); } /** diff --git a/src/Member/MemberServiceProvider.php b/src/Member/MemberServiceProvider.php index 8a95d859e0d08eab0f773e5b338f63116f9cbe31..144600fe44345931a0d459faa6e872a1af4852fa 100644 --- a/src/Member/MemberServiceProvider.php +++ b/src/Member/MemberServiceProvider.php @@ -10,7 +10,6 @@ namespace Notadd\Foundation\Member; use Illuminate\Support\ServiceProvider; use Notadd\Foundation\Member\Middleware\Permission; -use Notadd\Foundation\Member\Middleware\FrontPermission; use Notadd\Foundation\Member\Middleware\AdminPermission; use Notadd\Foundation\Member\Commands\PermissionCommand; @@ -42,9 +41,8 @@ class MemberServiceProvider extends ServiceProvider public function registerMiddleware() { - $this->app['router']->aliasMiddleware('permission', Permission::class); - $this->app['router']->aliasMiddleware('permission.admin', AdminPermission::class); - $this->app['router']->aliasMiddleware('permission.front', FrontPermission::class); + $this->app['router']->middleware('permission', Permission::class); + $this->app['router']->middleware('admin-permission', AdminPermission::class); } public function registerCommands() @@ -56,7 +54,7 @@ class MemberServiceProvider extends ServiceProvider public function registerPermission() { - $this->app->singleton('permission', function ($app) { + $this->app->bind('permission', function ($app) { return new PermissionManager; }); } diff --git a/src/Member/Middleware/FrontPermission.php b/src/Member/Middleware/FrontPermission.php deleted file mode 100644 index 4abdd7c4cebaec1487a9f31003124a5f53e862f7..0000000000000000000000000000000000000000 --- a/src/Member/Middleware/FrontPermission.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @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 abe6ecdf13195f33f4edaa5a140113bfcbbcebc7..3f477f8790c0aba1e81a973def50413d55eb7d50 100644 --- a/src/Member/Permission.php +++ b/src/Member/Permission.php @@ -9,7 +9,6 @@ namespace Notadd\Foundation\Member; -use Illuminate\Support\Str; use Notadd\Foundation\Database\Model; /** @@ -26,15 +25,7 @@ use Notadd\Foundation\Database\Model; */ class Permission extends Model { - /** - * 前台的权限前缀 - */ - const FRONT_PREFIX = 'front.'; - - /** - * 后台的权限前缀 - */ - const ADMIN_PREFIX = 'admin.'; + const ADMIN_PREFIX = 'admin-'; protected $table = 'permissions'; @@ -50,15 +41,6 @@ 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(); @@ -74,24 +56,6 @@ 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 - ); - } - /** * 添加后台权限 * @@ -103,31 +67,14 @@ class Permission extends Model */ public static function addAdminPermission($name, $display_name = null, $description = null) { - 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); + return static::addPermission(static::ADMIN_PREFIX . $name, $display_name, $description); } /** * 查询后台权限 * * @param $query - * @param $nameMember + * @param $name * * @return mixed */ diff --git a/src/Module/Abstracts/Installer.php b/src/Module/Abstracts/Installer.php deleted file mode 100644 index b3ceda2c61cf84e7db4841779fb956f434b8a21b..0000000000000000000000000000000000000000 --- a/src/Module/Abstracts/Installer.php +++ /dev/null @@ -1,52 +0,0 @@ - - * @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 deleted file mode 100644 index b2afe598e8dfb50bf5a3b01c5a2c55d8eec97eb4..0000000000000000000000000000000000000000 --- a/src/Module/Abstracts/Module.php +++ /dev/null @@ -1,87 +0,0 @@ - - * @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 deleted file mode 100644 index a79714e889840531eaa4faf856c9ef729cae8dce..0000000000000000000000000000000000000000 --- a/src/Module/Abstracts/Uninstaller.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @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 472b9f1de25072c873e9d77c764d73b1897de2e9..603fde7cbcb31f216f18c00467a98dca1a534999 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->getIdentification(), + $module->getName(), collect($module->getAuthor())->first(), $module->getDescription(), $path, diff --git a/src/Module/Controllers/ModuleController.php b/src/Module/Controllers/ModuleController.php index fdf7c1b9f9ed8c82c5cd7955888e405ef1570d32..b7163a471f7a7cb891bbd78348881cbaf7aa5eb4 100644 --- a/src/Module/Controllers/ModuleController.php +++ b/src/Module/Controllers/ModuleController.php @@ -9,10 +9,7 @@ namespace Notadd\Foundation\Module\Controllers; use Notadd\Foundation\Module\Handlers\EnableHandler; -use Notadd\Foundation\Module\Handlers\InstallHandler; use Notadd\Foundation\Module\Handlers\ModuleHandler; -use Notadd\Foundation\Module\Handlers\UninstallHandler; -use Notadd\Foundation\Module\Handlers\UpdateHandler; /** * Class ModuleController. @@ -44,43 +41,4 @@ 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 deleted file mode 100644 index 115779db5a7f1bc75c223af48bc1c8b96da6bca8..0000000000000000000000000000000000000000 --- a/src/Module/Handlers/InstallHandler.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @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 3dac9771773fdeee138a1c1165b9e166eeb1f2f0..d96beac7ddf33a3ba3ab92fdbced522ffb7e41d0 100644 --- a/src/Module/Handlers/ModuleHandler.php +++ b/src/Module/Handlers/ModuleHandler.php @@ -60,7 +60,6 @@ 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 deleted file mode 100644 index accc81acd5e0b7d6b726964a38a2180fb7435e63..0000000000000000000000000000000000000000 --- a/src/Module/Handlers/UninstallHandler.php +++ /dev/null @@ -1,82 +0,0 @@ - - * @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 deleted file mode 100644 index e371e2888b8641cc2ec16ce78db612ff563e9a12..0000000000000000000000000000000000000000 --- a/src/Module/Handlers/UpdateHandler.php +++ /dev/null @@ -1,78 +0,0 @@ - - * @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 622c210e1f5adebac7864113a169680f0cd35b84..d8f40491705a80218d5f084c63582c12c7712177 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\RouteRegister as AbstractRouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; /** * Class RouteRegistrar. */ -class RouteRegister extends AbstractRouteRegister +class RouteRegister extends AbstractRouteRegistrar { /** * Handle Route Registrar. @@ -23,9 +23,6 @@ class RouteRegister extends AbstractRouteRegister { $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 20fb407d296d8246774f61c19bc2c0f724503ff9..11d9ed343e0e19b5d86b7b1d370582edfbf4a419 100644 --- a/src/Module/Module.php +++ b/src/Module/Module.php @@ -28,21 +28,11 @@ class Module */ protected $description; - /** - * @var string - */ - protected $directory; - /** * @var string */ protected $entry; - /** - * @var string - */ - protected $identification; - /** * @var bool */ @@ -63,11 +53,6 @@ class Module */ protected $stylesheet; - /** - * @var string - */ - protected $version; - /** * Module constructor. * @@ -75,7 +60,7 @@ class Module */ public function __construct($name = null) { - $this->identification = $name; + $this->name = $name; } /** @@ -98,16 +83,6 @@ class Module return $this->description; } - /** - * Directory of module. - * - * @return string - */ - public function getDirectory() - { - return $this->directory; - } - /** * Entry of module. * @@ -118,22 +93,12 @@ class Module return $this->entry; } - /** - * Identification of module. - * - * @return string - */ - public function getIdentification() - { - return $this->identification; - } - /** * Name of module. * * @return string */ - public function getName(): string + public function getName() { return $this->name; } @@ -158,16 +123,6 @@ class Module return $this->stylesheet; } - /** - * Version of module. - * - * @return string - */ - public function getVersion(): string - { - return $this->version; - } - /** * Enabled of module. * @@ -224,16 +179,6 @@ class Module $this->description = $description; } - /** - * Set module's directory. - * - * @param string $directory - */ - public function setDirectory($directory) - { - $this->directory = $directory; - } - /** * Set module's entry. * @@ -254,22 +199,12 @@ 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(string $name) + public function setName($name) { $this->name = $name; } @@ -293,14 +228,4 @@ 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 be53e49bf53bf39a5f6f13c8e36e1a76fa2084b6..2750fd8491f45d2e60cbb7eedc6f97b22de7fc51 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -68,24 +68,12 @@ class ModuleManager return $list; } $this->modules->each(function (Module $module) use ($list) { - $module->isEnabled() && $list->put($module->getIdentification(), $module); + $module->isEnabled() && $list->push($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. * @@ -98,38 +86,24 @@ 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)); - $identification = Arr::get($package, 'name'); + $name = Arr::get($package, 'name'); $type = Arr::get($package, 'type'); - if ($type == 'notadd-module' && $identification) { - $module = new Module($identification); + if ($type == 'notadd-module' && $name) { + $module = new Module($name); $module->setAuthor(Arr::get($package, 'authors')); $module->setDescription(Arr::get($package, 'description')); - $module->setDirectory($directory); - $status = $this->container->isInstalled() ? $this->container->make('setting')->get('module.' . $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'])); - method_exists($provider, 'version') && $module->setVersion(call_user_func([$provider, 'version'])); - $this->modules->put($identification, $module); + $status = $this->container->isInstalled() ? $this->container->make('setting')->get('module.' . $name . '.enabled', false) : false; + $module->setEnabled($status); + $this->modules->put($directory, $module); } } }); @@ -139,18 +113,6 @@ 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 420d9053ec35336d9c00faa43de6aacb215a31e7..e400400926b744b3e387357a4021c5218744f849 100644 --- a/src/Module/ModuleServiceProvider.php +++ b/src/Module/ModuleServiceProvider.php @@ -8,9 +8,7 @@ */ 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; @@ -22,35 +20,18 @@ 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() { - $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())) { + collect($this->app->make('module')->getModules())->each(function (Module $module, $path) { + if ($this->app->make('files')->isDirectory($path) && is_string($module->getEntry())) { $this->app->register($module->getEntry()); } }); + $this->app->make(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 4695fa612c79f5ed876020cbdb02a2d48eb153b5..4baac58c9c6a685134c559caabd84c362d804a42 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\RouteRegister as AbstractRouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; /** * Class RouteRegister. */ -class RouteRegister extends AbstractRouteRegister +class RouteRegister extends AbstractRouteRegistrar { /** * Handle Route Registrar. diff --git a/src/Passport/Abstracts/DataHandler.php b/src/Passport/Abstracts/DataHandler.php index c6dd020687b4c3ca54315fce20b83a1babe9765e..65827d56092d3766716c1d1fc01df4b90a6b2992 100644 --- a/src/Passport/Abstracts/DataHandler.php +++ b/src/Passport/Abstracts/DataHandler.php @@ -16,11 +16,6 @@ use Notadd\Foundation\Passport\Responses\ApiResponse; */ abstract class DataHandler extends Handler { - /** - * @var array - */ - protected $data = []; - /** * @var bool */ @@ -35,10 +30,11 @@ abstract class DataHandler extends Handler * Data for handler. * * @return array + * @throws \Exception */ public function data() { - return $this->data; + throw new Exception('Data is not setted!'); } /** @@ -70,26 +66,18 @@ 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, - ]); - } catch (Exception $exception) { - return $response->withParams([ - 'code' => $exception->getCode(), - 'message' => $exception->getMessage(), - 'trace' => $exception->getTrace(), - ]); - } + return $response->withParams([ + 'code' => $this->code(), + 'data' => $data, + 'message' => $messages, + ]); } } diff --git a/src/Passport/Abstracts/Handler.php b/src/Passport/Abstracts/Handler.php index 990dda1ee1a93ebbd0411ce931927f8cc6ceaa40..afe1fd9020dcb3937416f2cca460570ea40e6bbb 100644 --- a/src/Passport/Abstracts/Handler.php +++ b/src/Passport/Abstracts/Handler.php @@ -18,17 +18,6 @@ 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 */ @@ -39,11 +28,6 @@ abstract class Handler */ protected $log; - /** - * @var array - */ - protected $messages = []; - /** * @var \Illuminate\Http\Request */ @@ -71,65 +55,32 @@ abstract class Handler * Http code. * * @return int + * @throws \Exception */ - protected function code() + public function code() { - return $this->code; + throw new Exception('Code is not setted!'); } /** * Errors for handler. * * @return array + * @throws \Exception */ - protected function errors() + public function errors() { - return $this->errors; + throw new Exception('Error is not setted!'); } /** * Messages for handler. * * @return array + * @throws \Exception */ - protected function messages() - { - return $this->messages; - } - - /** - * @param int $code - * - * @return $this - */ - protected function withCode($code) + public function messages() { - $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; + throw new Exception('Message is not setted!'); } } diff --git a/src/Passport/Abstracts/SetHandler.php b/src/Passport/Abstracts/SetHandler.php index 3c4c4cea3e5e902fd00bff6b86c88e053c737fe8..80dacd2d2d7170f9eec17a6991268f0c2eb7c4ad 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 $this->code; + return 200; } /** @@ -56,26 +56,18 @@ 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, - ]); - } catch (Exception $exception) { - return $response->withParams([ - 'code' => $exception->getCode(), - 'message' => $exception->getMessage(), - 'trace' => $exception->getTrace(), - ]); - } + return $response->withParams([ + 'code' => $this->code(), + 'data' => $this->data(), + 'message' => $messages, + ]); } } diff --git a/src/Passport/Controllers/AccessTokenController.php b/src/Passport/Controllers/AccessTokenController.php index f92ada7b9c9a511412d814d2fde89b19033da14f..325c6b970805fbca2e1634fb12b5e469fba1c780 100644 --- a/src/Passport/Controllers/AccessTokenController.php +++ b/src/Passport/Controllers/AccessTokenController.php @@ -10,6 +10,7 @@ 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; @@ -92,8 +93,29 @@ class AccessTokenController extends Controller */ public function issueToken(ServerRequestInterface $request) { - return $this->withErrorHandling(function () use ($request) { + $response = $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 3843e5f92889b416cd8bab3d57234455252096a4..47e3f3229745640102ab24e8b55c332bfea723fd 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 () { - $authRequest = $this->getAuthRequestFromSession($this->request); + return $this->withErrorHandling(function () use ($request) { + $authRequest = $this->getAuthRequestFromSession($request); return $this->server->completeAuthorizationRequest($authRequest, new Psr7Response()); }); diff --git a/src/Passport/Controllers/ClientsController.php b/src/Passport/Controllers/ClientsController.php index a34fc77d5e8eae9638bc06804b58003e5e229471..7745d0b1cc6ecf9e5437b127611d6b3452285b11 100644 --- a/src/Passport/Controllers/ClientsController.php +++ b/src/Passport/Controllers/ClientsController.php @@ -83,11 +83,8 @@ 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'); } /** @@ -101,16 +98,13 @@ class ClientsController extends Controller public function update($clientId) { if (!$this->request->user()->clients->find($clientId)) { - return new Response('User not found!', 404); + return new Response('', 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/RouterRegister.php b/src/Passport/Listeners/RouterRegistrar.php similarity index 94% rename from src/Passport/Listeners/RouterRegister.php rename to src/Passport/Listeners/RouterRegistrar.php index e6dbefaf5b5b99f5b09aee257f9578d89420f254..53ce362a181f7da3cc31563206e7f84ae5b58dcf 100644 --- a/src/Passport/Listeners/RouterRegister.php +++ b/src/Passport/Listeners/RouterRegistrar.php @@ -14,12 +14,12 @@ use Laravel\Passport\ApiTokenCookieFactory; use Notadd\Foundation\Passport\Controllers\AccessTokenController; use Notadd\Foundation\Passport\Controllers\AuthorizationController; use Notadd\Foundation\Passport\Controllers\ClientsController; -use Notadd\Foundation\Routing\Abstracts\RouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar; /** * Class RouterRegistrar. */ -class RouterRegister extends RouteRegister +class RouterRegistrar extends RouteRegistrar { /** * Handle Route Registrar. diff --git a/src/Passport/PassportServiceProvider.php b/src/Passport/PassportServiceProvider.php index 55dbe492a337bd690f688f93b920a8f827c2d0f9..3c008cf3131e0391cb449a210569775b97566719 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\RouterRegister; +use Notadd\Foundation\Passport\Listeners\RouterRegistrar; /** * Class PassportServiceProvider. @@ -27,7 +27,7 @@ class PassportServiceProvider extends LaravelPassportServiceProvider */ public function boot() { - $this->app->make(Dispatcher::class)->subscribe(RouterRegister::class); + $this->app->make(Dispatcher::class)->subscribe(RouterRegistrar::class); $this->commands([ ClientCommand::class, InstallCommand::class, diff --git a/src/Passport/Responses/ApiResponse.php b/src/Passport/Responses/ApiResponse.php index ce86dcf930b0398b9f592d2a359be5dd06125dd2..9b6668d625167e5e7c1a10c382d0e22c04b6b855 100644 --- a/src/Passport/Responses/ApiResponse.php +++ b/src/Passport/Responses/ApiResponse.php @@ -33,9 +33,7 @@ class ApiResponse { is_null($response) && $response = new Response(); $params && $this->params = array_merge($this->params, $params); - $status = collect($this->params)->get('code', 200); - $status > 598 && $status = 500; - $response = $response->withStatus($status) + $response = $response->withStatus(200) ->withHeader('pragma', 'no-cache') ->withHeader('cache-control', 'no-store') ->withHeader('content-type', 'application/json; charset=UTF-8'); diff --git a/src/Translation/TranslationServiceProvider.php b/src/Passport/Traits/PassportHelpers.php similarity index 32% rename from src/Translation/TranslationServiceProvider.php rename to src/Passport/Traits/PassportHelpers.php index 2f45094a58fd75d3ec583f02ec08669a9033ac56..fc53ea2314fc008027382dfd3fd04d1d3373e233 100644 --- a/src/Translation/TranslationServiceProvider.php +++ b/src/Passport/Traits/PassportHelpers.php @@ -4,15 +4,14 @@ * * @author TwilRoad <269044570@qq.com> * @copyright (c) 2017, iBenchu.org - * @datetime 2017-03-01 15:27 + * @datetime 2017-01-08 20:07 */ -namespace Notadd\Foundation\Translation; - -use Illuminate\Translation\TranslationServiceProvider as IlluminateTranslationServiceProvider; +namespace Notadd\Foundation\Passport\Traits; /** - * Class TranslationServiceProvider. + * Class PassportHelpers. */ -class TranslationServiceProvider extends IlluminateTranslationServiceProvider +trait PassportHelpers { + } diff --git a/src/Routing/Abstracts/RouteRegister.php b/src/Routing/Abstracts/RouteRegistrar.php similarity index 95% rename from src/Routing/Abstracts/RouteRegister.php rename to src/Routing/Abstracts/RouteRegistrar.php index 463aac9629afd027f7df8dd1b2019e516465a3a8..6747e9a550f2e41996564696a9206b2a1b5d933f 100644 --- a/src/Routing/Abstracts/RouteRegister.php +++ b/src/Routing/Abstracts/RouteRegistrar.php @@ -17,7 +17,7 @@ use Notadd\Foundation\Routing\Events\RouteRegister as RouteRegisterEvent; /** * Class AbstractRouteRegister. */ -abstract class RouteRegister extends EventSubscriber +abstract class RouteRegistrar extends EventSubscriber { /** * @var \Illuminate\Routing\Router diff --git a/src/Routing/RoutingServiceProvider.php b/src/Routing/RoutingServiceProvider.php index 722838ca952406ab4120dd0dcb1b54c41c206808..da6dc857576c40e491225472e5c166eb7b7be393 100644 --- a/src/Routing/RoutingServiceProvider.php +++ b/src/Routing/RoutingServiceProvider.php @@ -20,7 +20,7 @@ class RoutingServiceProvider extends IlluminateRoutingServiceProvider */ protected function registerRedirector() { - $this->app->singleton('redirect', function ($app) { + $this->app['redirect'] = $this->app->share(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 f2849481f89315ca57438d47f0e26361289fa4b6..108c8b0818e3dffbef10662c4ba4f4a5b34e7452 100644 --- a/src/SearchEngine/Controllers/SeoController.php +++ b/src/SearchEngine/Controllers/SeoController.php @@ -10,12 +10,29 @@ 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/RouterRegister.php b/src/SearchEngine/Listeners/RouterRegistrar.php similarity index 81% rename from src/SearchEngine/Listeners/RouterRegister.php rename to src/SearchEngine/Listeners/RouterRegistrar.php index c9feb3381520791e4050104dedfc1a0cc1866c0b..56c14fadc5cc26ff226e726638fd91217b8bffe7 100644 --- a/src/SearchEngine/Listeners/RouterRegister.php +++ b/src/SearchEngine/Listeners/RouterRegistrar.php @@ -8,13 +8,13 @@ */ namespace Notadd\Foundation\SearchEngine\Listeners; -use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; use Notadd\Foundation\SearchEngine\Controllers\SeoController; /** * Class RouterRegistrar. */ -class RouterRegister extends AbstractRouteRegister +class RouterRegistrar extends AbstractRouteRegistrar { /** * Handle Route Registrar. diff --git a/src/SearchEngine/SearchEngineServiceProvider.php b/src/SearchEngine/SearchEngineServiceProvider.php index a763766a9b0c35cf3329e12aa7ec542d45e3db18..0cb808968a23d512eb2c7ae8a7ffb96c4cc70759 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\RouterRegister; +use Notadd\Foundation\SearchEngine\Listeners\RouterRegistrar; /** * 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(RouterRegister::class); + $this->app->make(Dispatcher::class)->subscribe(RouterRegistrar::class); } /** diff --git a/src/Setting/Controllers/SettingController.php b/src/Setting/Controllers/SettingController.php index 9937217a13cc7dbbb01e3d8b06a72eeabb4d0ec1..1eea83ba91c8ad07cd64e36c776876a1b1e84b93 100644 --- a/src/Setting/Controllers/SettingController.php +++ b/src/Setting/Controllers/SettingController.php @@ -9,6 +9,7 @@ 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; @@ -17,6 +18,24 @@ 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/RouteRegister.php b/src/Setting/Listeners/RouteRegistrar.php similarity index 83% rename from src/Setting/Listeners/RouteRegister.php rename to src/Setting/Listeners/RouteRegistrar.php index f687200f8cebcf03fdd305d6b0eb6fa4084f6e83..3af55b1f5e03a853c86bc4b97d12d4dd833ef187 100644 --- a/src/Setting/Listeners/RouteRegister.php +++ b/src/Setting/Listeners/RouteRegistrar.php @@ -8,13 +8,13 @@ */ namespace Notadd\Foundation\Setting\Listeners; -use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; use Notadd\Foundation\Setting\Controllers\SettingController; /** * Class RouteRegistrar. */ -class RouteRegister extends AbstractRouteRegister +class RouteRegistrar extends AbstractRouteRegistrar { /** * Handle Route Registrar. diff --git a/src/Setting/SettingServiceProvider.php b/src/Setting/SettingServiceProvider.php index ccc43781ea5f97a38c7b8b06221484f7d983ad8d..6d09554cf6b389bc3dc2ca7a00f90802abacba7d 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\RouteRegister; +use Notadd\Foundation\Setting\Listeners\RouteRegistrar; /** * 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(RouteRegister::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); } /** diff --git a/src/Sitemap/Listeners/RouteRegister.php b/src/Sitemap/Listeners/RouteRegistrar.php similarity index 75% rename from src/Sitemap/Listeners/RouteRegister.php rename to src/Sitemap/Listeners/RouteRegistrar.php index cc4d3122dd7fb4cfa65661b613fc72a2b42540b0..97d56ef9d0af000f2db58d130ee42c08c1a9f3db 100644 --- a/src/Sitemap/Listeners/RouteRegister.php +++ b/src/Sitemap/Listeners/RouteRegistrar.php @@ -8,13 +8,14 @@ */ namespace Notadd\Foundation\Sitemap\Listeners; -use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister; +use Notadd\Foundation\Routing\Abstracts\RouteRegistrar as AbstractRouteRegistrar; +use Notadd\Foundation\Setting\Controllers\SettingController; use Notadd\Foundation\Sitemap\Controllers\SitemapController; /** * Class RouteRegistrar. */ -class RouteRegister extends AbstractRouteRegister +class RouteRegistrar extends AbstractRouteRegistrar { /** * Handle Route Registrar. diff --git a/src/Sitemap/SitemapServiceProvider.php b/src/Sitemap/SitemapServiceProvider.php index 44f59330fffeec82e254a4d2f1a1a69d3675b6df..34dd56978bd72d4fa7dc4f42e0414bc808239f45 100644 --- a/src/Sitemap/SitemapServiceProvider.php +++ b/src/Sitemap/SitemapServiceProvider.php @@ -11,10 +11,9 @@ 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\RouteRegister; +use Notadd\Foundation\Sitemap\Listeners\RouteRegistrar; /** * Class SitemapServiceProvider. @@ -24,7 +23,7 @@ class SitemapServiceProvider extends ServiceProvider public function boot() { $this->loadViewsFrom(realpath(__DIR__ . '/../../resources/views/sitemap'), 'sitemap'); - $this->app->make(Dispatcher::class)->listen(RequestHandled::class, function () { + $this->app->make(Dispatcher::class)->listen('kernel.handled', function () { if ($this->app->isInstalled()) { $setting = $this->app->make(SettingsRepository::class); if ($setting->get('sitemap.recently', true)) { @@ -42,7 +41,7 @@ class SitemapServiceProvider extends ServiceProvider } }); $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class); - $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class); + $this->app->make(Dispatcher::class)->subscribe(RouteRegistrar::class); } public function register() diff --git a/src/Testing/Concerns/MocksApplicationServices.php b/src/Testing/Concerns/MocksApplicationServices.php index d70270803a3da30629defb523f85fcf099b101e0..6868af4d07fe7d62113d561f9c57f8e267b7ca3d 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->alias($observer, function () use ($observer) { + $this->app->bind($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 deleted file mode 100644 index 10ffa4c869bc8d4f6b7ee935201b4f0338d67935..0000000000000000000000000000000000000000 --- a/src/Translation/Events/LocaleUpdated.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @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/helpers.php b/src/helpers.php index 43f3f19b107d950b63d183d9cbee971544184b51..c7686c24fe3ed5baa0e5443a7ba2fd2741406f80 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -335,7 +335,6 @@ if (!function_exists('csrf_field')) { * Generate a CSRF token form field. * * @return \Illuminate\Support\HtmlString - * @throws \Illuminate\Contracts\Container\BindingResolutionException */ function csrf_field() { @@ -354,7 +353,7 @@ if (!function_exists('csrf_token')) { { $session = app('session'); if (isset($session)) { - return $session->token(); + return $session->getToken(); } throw new RuntimeException('Application session store not set.'); } @@ -500,7 +499,7 @@ if (!function_exists('event')) { */ function event(...$args) { - return app('events')->dispatch(...$args); + return app('events')->fire(...$args); } }