├── LICENSE ├── composer.json └── src ├── Console └── Commands │ ├── AppInstall.php │ ├── AppReset.php │ └── AppUpdate.php ├── CoreServiceProvider.php └── Subscribers └── CommandSubscriber.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2017 Graham Campbell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "graham-campbell/core", 3 | "description": "Core Provides Some Extra Functionality For Laravel 5", 4 | "keywords": ["laravel", "framework", "base", "starter", "core", "Core", "Laravel Core", "Laravel-Core", "Graham Campbell", "GrahamCampbell"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Graham Campbell", 9 | "email": "graham@alt-three.com" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=5.5.9", 14 | "illuminate/console": "5.1.*|5.2.*|5.3.*|5.4.*", 15 | "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*", 16 | "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*" 17 | }, 18 | "require-dev": { 19 | "graham-campbell/testbench": "^3.1", 20 | "mockery/mockery": "^0.9.4", 21 | "phpunit/phpunit": "^4.8|^5.0" 22 | }, 23 | "autoload": { 24 | "psr-4": { 25 | "GrahamCampbell\\Core\\": "src/" 26 | } 27 | }, 28 | "autoload-dev": { 29 | "psr-4": { 30 | "GrahamCampbell\\Tests\\Core\\": "tests/" 31 | } 32 | }, 33 | "config": { 34 | "preferred-install": "dist" 35 | }, 36 | "extra": { 37 | "branch-alias": { 38 | "dev-master": "5.3-dev" 39 | } 40 | }, 41 | "minimum-stability": "dev", 42 | "prefer-stable": true 43 | } 44 | -------------------------------------------------------------------------------- /src/Console/Commands/AppInstall.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace GrahamCampbell\Core\Console\Commands; 13 | 14 | use Illuminate\Console\Command; 15 | use Illuminate\Contracts\Events\Dispatcher; 16 | 17 | /** 18 | * This is the app install command class. 19 | * 20 | * @author Graham Campbell 21 | */ 22 | class AppInstall extends Command 23 | { 24 | /** 25 | * The command name. 26 | * 27 | * @var string 28 | */ 29 | protected $name = 'app:install'; 30 | 31 | /** 32 | * The command description. 33 | * 34 | * @var string 35 | */ 36 | protected $description = 'Installs the application'; 37 | 38 | /** 39 | * The events instance. 40 | * 41 | * @var \Illuminate\Contracts\Events\Dispatcher 42 | */ 43 | protected $events; 44 | 45 | /** 46 | * Create a new instance. 47 | * 48 | * @param \Illuminate\Contracts\Events\Dispatcher $events 49 | * 50 | * @return void 51 | */ 52 | public function __construct(Dispatcher $events) 53 | { 54 | $this->events = $events; 55 | 56 | parent::__construct(); 57 | } 58 | 59 | /** 60 | * Execute the console command. 61 | * 62 | * @return void 63 | */ 64 | public function handle() 65 | { 66 | $this->events->fire('command.installing', $this); 67 | $this->events->fire('command.generatekey', $this); 68 | $this->events->fire('command.cacheconfig', $this); 69 | $this->events->fire('command.cacheroutes', $this); 70 | $this->events->fire('command.publishvendors', $this); 71 | $this->events->fire('command.runmigrations', $this); 72 | $this->events->fire('command.runseeding', $this); 73 | $this->events->fire('command.updatecache', $this); 74 | $this->events->fire('command.linkstorage', $this); 75 | $this->events->fire('command.extrastuff', $this); 76 | $this->events->fire('command.installed', $this); 77 | } 78 | 79 | /** 80 | * Get the events instance. 81 | * 82 | * @return \Illuminate\Contracts\Events\Dispatcher 83 | */ 84 | public function getEvents() 85 | { 86 | return $this->events; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Console/Commands/AppReset.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace GrahamCampbell\Core\Console\Commands; 13 | 14 | use Illuminate\Console\Command; 15 | use Illuminate\Contracts\Events\Dispatcher; 16 | 17 | /** 18 | * This is the app reset command class. 19 | * 20 | * @author Graham Campbell 21 | */ 22 | class AppReset extends Command 23 | { 24 | /** 25 | * The command name. 26 | * 27 | * @var string 28 | */ 29 | protected $name = 'app:reset'; 30 | 31 | /** 32 | * The command description. 33 | * 34 | * @var string 35 | */ 36 | protected $description = 'Resets and installs the application'; 37 | 38 | /** 39 | * The events instance. 40 | * 41 | * @var \Illuminate\Contracts\Events\Dispatcher 42 | */ 43 | protected $events; 44 | 45 | /** 46 | * Create a new instance. 47 | * 48 | * @param \Illuminate\Contracts\Events\Dispatcher $events 49 | * 50 | * @return void 51 | */ 52 | public function __construct(Dispatcher $events) 53 | { 54 | $this->events = $events; 55 | 56 | parent::__construct(); 57 | } 58 | 59 | /** 60 | * Execute the console command. 61 | * 62 | * @return void 63 | */ 64 | public function handle() 65 | { 66 | $this->events->fire('command.resetting', $this); 67 | $this->events->fire('command.generatekey', $this); 68 | $this->events->fire('command.cacheconfig', $this); 69 | $this->events->fire('command.cacheroutes', $this); 70 | $this->events->fire('command.publishvendors', $this); 71 | $this->events->fire('command.resetmigrations', $this); 72 | $this->events->fire('command.runmigrations', $this); 73 | $this->events->fire('command.runseeding', $this); 74 | $this->events->fire('command.updatecache', $this); 75 | $this->events->fire('command.extrastuff', $this); 76 | $this->events->fire('command.reset', $this); 77 | } 78 | 79 | /** 80 | * Get the events instance. 81 | * 82 | * @return \Illuminate\Contracts\Events\Dispatcher 83 | */ 84 | public function getEvents() 85 | { 86 | return $this->events; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Console/Commands/AppUpdate.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace GrahamCampbell\Core\Console\Commands; 13 | 14 | use Illuminate\Console\Command; 15 | use Illuminate\Contracts\Events\Dispatcher; 16 | 17 | /** 18 | * This is the app update command class. 19 | * 20 | * @author Graham Campbell 21 | */ 22 | class AppUpdate extends Command 23 | { 24 | /** 25 | * The command name. 26 | * 27 | * @var string 28 | */ 29 | protected $name = 'app:update'; 30 | 31 | /** 32 | * The command description. 33 | * 34 | * @var string 35 | */ 36 | protected $description = 'Updates the application'; 37 | 38 | /** 39 | * The events instance. 40 | * 41 | * @var \Illuminate\Contracts\Events\Dispatcher 42 | */ 43 | protected $events; 44 | 45 | /** 46 | * Create a new instance. 47 | * 48 | * @param \Illuminate\Contracts\Events\Dispatcher $events 49 | * 50 | * @return void 51 | */ 52 | public function __construct(Dispatcher $events) 53 | { 54 | $this->events = $events; 55 | 56 | parent::__construct(); 57 | } 58 | 59 | /** 60 | * Execute the console command. 61 | * 62 | * @return void 63 | */ 64 | public function handle() 65 | { 66 | $this->events->fire('command.updating', $this); 67 | $this->events->fire('command.cacheconfig', $this); 68 | $this->events->fire('command.cacheroutes', $this); 69 | $this->events->fire('command.publishvendors', $this); 70 | $this->events->fire('command.runmigrations', $this); 71 | $this->events->fire('command.updatecache', $this); 72 | $this->events->fire('command.extrastuff', $this); 73 | $this->events->fire('command.updated', $this); 74 | } 75 | 76 | /** 77 | * Get the events instance. 78 | * 79 | * @return \Illuminate\Contracts\Events\Dispatcher 80 | */ 81 | public function getEvents() 82 | { 83 | return $this->events; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/CoreServiceProvider.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace GrahamCampbell\Core; 13 | 14 | use GrahamCampbell\Core\Console\Commands\AppInstall; 15 | use GrahamCampbell\Core\Console\Commands\AppReset; 16 | use GrahamCampbell\Core\Console\Commands\AppUpdate; 17 | use GrahamCampbell\Core\Subscribers\CommandSubscriber; 18 | use Illuminate\Contracts\Container\Container; 19 | use Illuminate\Support\ServiceProvider; 20 | 21 | /** 22 | * This is the core service provider class. 23 | * 24 | * @author Graham Campbell 25 | */ 26 | class CoreServiceProvider extends ServiceProvider 27 | { 28 | /** 29 | * Boot the service provider. 30 | * 31 | * @return void 32 | */ 33 | public function boot() 34 | { 35 | $this->commands('command.appupdate', 'command.appinstall', 'command.appreset'); 36 | 37 | $this->setupListeners(); 38 | } 39 | 40 | /** 41 | * Setup the listeners. 42 | * 43 | * @return void 44 | */ 45 | protected function setupListeners() 46 | { 47 | $subscriber = $this->app->make(CommandSubscriber::class); 48 | 49 | $this->app->events->subscribe($subscriber); 50 | } 51 | 52 | /** 53 | * Register the service provider. 54 | * 55 | * @return void 56 | */ 57 | public function register() 58 | { 59 | $this->registerUpdateCommand(); 60 | $this->registerInstallCommand(); 61 | $this->registerResetCommand(); 62 | $this->registerCommandSubscriber(); 63 | } 64 | 65 | /** 66 | * Register the updated command class. 67 | * 68 | * @return void 69 | */ 70 | protected function registerUpdateCommand() 71 | { 72 | $this->app->singleton('command.appupdate', function (Container $app) { 73 | $events = $app['events']; 74 | 75 | return new AppUpdate($events); 76 | }); 77 | } 78 | 79 | /** 80 | * Register the install command class. 81 | * 82 | * @return void 83 | */ 84 | protected function registerInstallCommand() 85 | { 86 | $this->app->singleton('command.appinstall', function (Container $app) { 87 | $events = $app['events']; 88 | 89 | return new AppInstall($events); 90 | }); 91 | } 92 | 93 | /** 94 | * Register the reset command class. 95 | * 96 | * @return void 97 | */ 98 | protected function registerResetCommand() 99 | { 100 | $this->app->singleton('command.appreset', function (Container $app) { 101 | $events = $app['events']; 102 | 103 | return new AppReset($events); 104 | }); 105 | } 106 | 107 | /** 108 | * Register the command subscriber class. 109 | * 110 | * @return void 111 | */ 112 | protected function registerCommandSubscriber() 113 | { 114 | $this->app->singleton(CommandSubscriber::class, function () { 115 | return new CommandSubscriber(); 116 | }); 117 | } 118 | 119 | /** 120 | * Get the services provided by the provider. 121 | * 122 | * @return string[] 123 | */ 124 | public function provides() 125 | { 126 | return [ 127 | 'command.appupdate', 128 | 'command.appinstall', 129 | 'command.appreset', 130 | ]; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/Subscribers/CommandSubscriber.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace GrahamCampbell\Core\Subscribers; 13 | 14 | use Illuminate\Console\Command; 15 | use Illuminate\Contracts\Events\Dispatcher; 16 | 17 | /** 18 | * This is the command subscriber class. 19 | * 20 | * @author Graham Campbell 21 | */ 22 | class CommandSubscriber 23 | { 24 | /** 25 | * Register the listeners for the subscriber. 26 | * 27 | * @param \Illuminate\Contracts\Events\Dispatcher $events 28 | * 29 | * @return void 30 | */ 31 | public function subscribe(Dispatcher $events) 32 | { 33 | $events->listen('command.generatekey', __CLASS__.'@onGenerateKey'); 34 | $events->listen('command.cacheconfig', __CLASS__.'@onCacheConfig'); 35 | $events->listen('command.cacheroutes', __CLASS__.'@onCacheRoutes'); 36 | $events->listen('command.publishvendors', __CLASS__.'@onPublishVendors'); 37 | $events->listen('command.resetmigrations', __CLASS__.'@onResetMigrations'); 38 | $events->listen('command.runmigrations', __CLASS__.'@onRunMigrations'); 39 | $events->listen('command.runseeding', __CLASS__.'@onRunSeeding'); 40 | $events->listen('command.linkstorage', __CLASS__.'@onLinkStorage'); 41 | $events->listen('command.updatecache', __CLASS__.'@onUpdateCache'); 42 | } 43 | 44 | /** 45 | * Handle a command.generatekey event. 46 | * 47 | * @param \Illuminate\Console\Command $command 48 | * 49 | * @return void 50 | */ 51 | public function onGenerateKey(Command $command) 52 | { 53 | $command->call('key:generate'); 54 | } 55 | 56 | /** 57 | * Handle a command.cacheconfig event. 58 | * 59 | * @param \Illuminate\Console\Command $command 60 | * 61 | * @return void 62 | */ 63 | public function onCacheConfig(Command $command) 64 | { 65 | $command->call('config:cache'); 66 | } 67 | 68 | /** 69 | * Handle a command.cacheroutes event. 70 | * 71 | * @param \Illuminate\Console\Command $command 72 | * 73 | * @return void 74 | */ 75 | public function onCacheRoutes(Command $command) 76 | { 77 | $command->call('route:cache'); 78 | } 79 | 80 | /** 81 | * Handle a command.publishvendors event. 82 | * 83 | * @param \Illuminate\Console\Command $command 84 | * 85 | * @return void 86 | */ 87 | public function onPublishVendors(Command $command) 88 | { 89 | $command->call('vendor:publish'); 90 | } 91 | 92 | /** 93 | * Handle a command.resetmigrations event. 94 | * 95 | * @param \Illuminate\Console\Command $command 96 | * 97 | * @return void 98 | */ 99 | public function onResetMigrations(Command $command) 100 | { 101 | $command->call('migrate:reset', ['--force' => true]); 102 | } 103 | 104 | /** 105 | * Handle a command.runmigrations event. 106 | * 107 | * @param \Illuminate\Console\Command $command 108 | * 109 | * @return void 110 | */ 111 | public function onRunMigrations(Command $command) 112 | { 113 | $command->call('migrate', ['--force' => true]); 114 | } 115 | 116 | /** 117 | * Handle a command.runseeding event. 118 | * 119 | * @param \Illuminate\Console\Command $command 120 | * 121 | * @return void 122 | */ 123 | public function onRunSeeding(Command $command) 124 | { 125 | $command->call('db:seed', ['--force' => true]); 126 | } 127 | 128 | /** 129 | * Handle a command.linkstorage event. 130 | * 131 | * @param \Illuminate\Console\Command $command 132 | * 133 | * @return void 134 | */ 135 | public function onLinkStorage(Command $command) 136 | { 137 | if ($command->getApplication()->has('storage:link')) { 138 | $command->call('storage:link'); 139 | } 140 | } 141 | 142 | /** 143 | * Handle a command.updatecache event. 144 | * 145 | * @param \Illuminate\Console\Command $command 146 | * 147 | * @return void 148 | */ 149 | public function onUpdateCache(Command $command) 150 | { 151 | $command->line('Clearing cache...'); 152 | $command->call('cache:clear'); 153 | $command->info('Cache cleared!'); 154 | } 155 | } 156 | --------------------------------------------------------------------------------