/vendor/laravel/framework/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php

https://gitlab.com/phanthanh9787/crud-user · PHP · 566 lines · 312 code · 46 blank · 208 comment · 2 complexity · 716d8bb8af6933a99c1a162151339a65 MD5 · raw file

  1. <?php
  2. namespace Illuminate\Foundation\Providers;
  3. use Illuminate\Support\ServiceProvider;
  4. use Illuminate\Queue\Console\TableCommand;
  5. use Illuminate\Auth\Console\MakeAuthCommand;
  6. use Illuminate\Foundation\Console\UpCommand;
  7. use Illuminate\Foundation\Console\DownCommand;
  8. use Illuminate\Auth\Console\ClearResetsCommand;
  9. use Illuminate\Foundation\Console\ServeCommand;
  10. use Illuminate\Cache\Console\CacheTableCommand;
  11. use Illuminate\Queue\Console\FailedTableCommand;
  12. use Illuminate\Foundation\Console\TinkerCommand;
  13. use Illuminate\Foundation\Console\JobMakeCommand;
  14. use Illuminate\Foundation\Console\AppNameCommand;
  15. use Illuminate\Foundation\Console\OptimizeCommand;
  16. use Illuminate\Foundation\Console\TestMakeCommand;
  17. use Illuminate\Foundation\Console\RouteListCommand;
  18. use Illuminate\Foundation\Console\EventMakeCommand;
  19. use Illuminate\Foundation\Console\ModelMakeCommand;
  20. use Illuminate\Foundation\Console\ViewClearCommand;
  21. use Illuminate\Session\Console\SessionTableCommand;
  22. use Illuminate\Foundation\Console\PolicyMakeCommand;
  23. use Illuminate\Foundation\Console\RouteCacheCommand;
  24. use Illuminate\Foundation\Console\RouteClearCommand;
  25. use Illuminate\Routing\Console\ControllerMakeCommand;
  26. use Illuminate\Routing\Console\MiddlewareMakeCommand;
  27. use Illuminate\Foundation\Console\ConfigCacheCommand;
  28. use Illuminate\Foundation\Console\ConfigClearCommand;
  29. use Illuminate\Foundation\Console\ConsoleMakeCommand;
  30. use Illuminate\Foundation\Console\EnvironmentCommand;
  31. use Illuminate\Foundation\Console\KeyGenerateCommand;
  32. use Illuminate\Foundation\Console\RequestMakeCommand;
  33. use Illuminate\Foundation\Console\ListenerMakeCommand;
  34. use Illuminate\Foundation\Console\ProviderMakeCommand;
  35. use Illuminate\Foundation\Console\ClearCompiledCommand;
  36. use Illuminate\Foundation\Console\EventGenerateCommand;
  37. use Illuminate\Foundation\Console\VendorPublishCommand;
  38. use Illuminate\Database\Console\Seeds\SeederMakeCommand;
  39. class ArtisanServiceProvider extends ServiceProvider
  40. {
  41. /**
  42. * Indicates if loading of the provider is deferred.
  43. *
  44. * @var bool
  45. */
  46. protected $defer = true;
  47. /**
  48. * The commands to be registered.
  49. *
  50. * @var array
  51. */
  52. protected $commands = [
  53. 'ClearCompiled' => 'command.clear-compiled',
  54. 'ClearResets' => 'command.auth.resets.clear',
  55. 'ConfigCache' => 'command.config.cache',
  56. 'ConfigClear' => 'command.config.clear',
  57. 'Down' => 'command.down',
  58. 'Environment' => 'command.environment',
  59. 'KeyGenerate' => 'command.key.generate',
  60. 'Optimize' => 'command.optimize',
  61. 'RouteCache' => 'command.route.cache',
  62. 'RouteClear' => 'command.route.clear',
  63. 'RouteList' => 'command.route.list',
  64. 'Tinker' => 'command.tinker',
  65. 'Up' => 'command.up',
  66. 'ViewClear' => 'command.view.clear',
  67. ];
  68. /**
  69. * The commands to be registered.
  70. *
  71. * @var array
  72. */
  73. protected $devCommands = [
  74. 'AppName' => 'command.app.name',
  75. 'AuthMake' => 'command.auth.make',
  76. 'CacheTable' => 'command.cache.table',
  77. 'ConsoleMake' => 'command.console.make',
  78. 'ControllerMake' => 'command.controller.make',
  79. 'EventGenerate' => 'command.event.generate',
  80. 'EventMake' => 'command.event.make',
  81. 'JobMake' => 'command.job.make',
  82. 'ListenerMake' => 'command.listener.make',
  83. 'MiddlewareMake' => 'command.middleware.make',
  84. 'ModelMake' => 'command.model.make',
  85. 'PolicyMake' => 'command.policy.make',
  86. 'ProviderMake' => 'command.provider.make',
  87. 'QueueFailedTable' => 'command.queue.failed-table',
  88. 'QueueTable' => 'command.queue.table',
  89. 'RequestMake' => 'command.request.make',
  90. 'SeederMake' => 'command.seeder.make',
  91. 'SessionTable' => 'command.session.table',
  92. 'Serve' => 'command.serve',
  93. 'TestMake' => 'command.test.make',
  94. 'VendorPublish' => 'command.vendor.publish',
  95. ];
  96. /**
  97. * Register the service provider.
  98. *
  99. * @return void
  100. */
  101. public function register()
  102. {
  103. $this->registerCommands($this->commands);
  104. //if (! $this->app->environment('production')) {
  105. $this->registerCommands($this->devCommands);
  106. //}
  107. }
  108. /**
  109. * Register the given commands.
  110. *
  111. * @param array $commands
  112. * @return void
  113. */
  114. protected function registerCommands(array $commands)
  115. {
  116. foreach (array_keys($commands) as $command) {
  117. $method = "register{$command}Command";
  118. call_user_func_array([$this, $method], []);
  119. }
  120. $this->commands(array_values($commands));
  121. }
  122. /**
  123. * Register the command.
  124. *
  125. * @return void
  126. */
  127. protected function registerAppNameCommand()
  128. {
  129. $this->app->singleton('command.app.name', function ($app) {
  130. return new AppNameCommand($app['composer'], $app['files']);
  131. });
  132. }
  133. /**
  134. * Register the command.
  135. *
  136. * @return void
  137. */
  138. protected function registerAuthMakeCommand()
  139. {
  140. $this->app->singleton('command.auth.make', function ($app) {
  141. return new MakeAuthCommand;
  142. });
  143. }
  144. /**
  145. * Register the command.
  146. *
  147. * @return void
  148. */
  149. protected function registerCacheTableCommand()
  150. {
  151. $this->app->singleton('command.cache.table', function ($app) {
  152. return new CacheTableCommand($app['files'], $app['composer']);
  153. });
  154. }
  155. /**
  156. * Register the command.
  157. *
  158. * @return void
  159. */
  160. protected function registerClearCompiledCommand()
  161. {
  162. $this->app->singleton('command.clear-compiled', function () {
  163. return new ClearCompiledCommand;
  164. });
  165. }
  166. /**
  167. * Register the command.
  168. *
  169. * @return void
  170. */
  171. protected function registerClearResetsCommand()
  172. {
  173. $this->app->singleton('command.auth.resets.clear', function () {
  174. return new ClearResetsCommand;
  175. });
  176. }
  177. /**
  178. * Register the command.
  179. *
  180. * @return void
  181. */
  182. protected function registerConfigCacheCommand()
  183. {
  184. $this->app->singleton('command.config.cache', function ($app) {
  185. return new ConfigCacheCommand($app['files']);
  186. });
  187. }
  188. /**
  189. * Register the command.
  190. *
  191. * @return void
  192. */
  193. protected function registerConfigClearCommand()
  194. {
  195. $this->app->singleton('command.config.clear', function ($app) {
  196. return new ConfigClearCommand($app['files']);
  197. });
  198. }
  199. /**
  200. * Register the command.
  201. *
  202. * @return void
  203. */
  204. protected function registerConsoleMakeCommand()
  205. {
  206. $this->app->singleton('command.console.make', function ($app) {
  207. return new ConsoleMakeCommand($app['files']);
  208. });
  209. }
  210. /**
  211. * Register the command.
  212. *
  213. * @return void
  214. */
  215. protected function registerControllerMakeCommand()
  216. {
  217. $this->app->singleton('command.controller.make', function ($app) {
  218. return new ControllerMakeCommand($app['files']);
  219. });
  220. }
  221. /**
  222. * Register the command.
  223. *
  224. * @return void
  225. */
  226. protected function registerEventGenerateCommand()
  227. {
  228. $this->app->singleton('command.event.generate', function () {
  229. return new EventGenerateCommand;
  230. });
  231. }
  232. /**
  233. * Register the command.
  234. *
  235. * @return void
  236. */
  237. protected function registerEventMakeCommand()
  238. {
  239. $this->app->singleton('command.event.make', function ($app) {
  240. return new EventMakeCommand($app['files']);
  241. });
  242. }
  243. /**
  244. * Register the command.
  245. *
  246. * @return void
  247. */
  248. protected function registerDownCommand()
  249. {
  250. $this->app->singleton('command.down', function () {
  251. return new DownCommand;
  252. });
  253. }
  254. /**
  255. * Register the command.
  256. *
  257. * @return void
  258. */
  259. protected function registerEnvironmentCommand()
  260. {
  261. $this->app->singleton('command.environment', function () {
  262. return new EnvironmentCommand;
  263. });
  264. }
  265. /**
  266. * Register the command.
  267. *
  268. * @return void
  269. */
  270. protected function registerJobMakeCommand()
  271. {
  272. $this->app->singleton('command.job.make', function ($app) {
  273. return new JobMakeCommand($app['files']);
  274. });
  275. }
  276. /**
  277. * Register the command.
  278. *
  279. * @return void
  280. */
  281. protected function registerKeyGenerateCommand()
  282. {
  283. $this->app->singleton('command.key.generate', function () {
  284. return new KeyGenerateCommand;
  285. });
  286. }
  287. /**
  288. * Register the command.
  289. *
  290. * @return void
  291. */
  292. protected function registerListenerMakeCommand()
  293. {
  294. $this->app->singleton('command.listener.make', function ($app) {
  295. return new ListenerMakeCommand($app['files']);
  296. });
  297. }
  298. /**
  299. * Register the command.
  300. *
  301. * @return void
  302. */
  303. protected function registerMiddlewareMakeCommand()
  304. {
  305. $this->app->singleton('command.middleware.make', function ($app) {
  306. return new MiddlewareMakeCommand($app['files']);
  307. });
  308. }
  309. /**
  310. * Register the command.
  311. *
  312. * @return void
  313. */
  314. protected function registerModelMakeCommand()
  315. {
  316. $this->app->singleton('command.model.make', function ($app) {
  317. return new ModelMakeCommand($app['files']);
  318. });
  319. }
  320. /**
  321. * Register the command.
  322. *
  323. * @return void
  324. */
  325. protected function registerOptimizeCommand()
  326. {
  327. $this->app->singleton('command.optimize', function ($app) {
  328. return new OptimizeCommand($app['composer']);
  329. });
  330. }
  331. /**
  332. * Register the command.
  333. *
  334. * @return void
  335. */
  336. protected function registerProviderMakeCommand()
  337. {
  338. $this->app->singleton('command.provider.make', function ($app) {
  339. return new ProviderMakeCommand($app['files']);
  340. });
  341. }
  342. /**
  343. * Register the command.
  344. *
  345. * @return void
  346. */
  347. protected function registerQueueFailedTableCommand()
  348. {
  349. $this->app->singleton('command.queue.failed-table', function ($app) {
  350. return new FailedTableCommand($app['files'], $app['composer']);
  351. });
  352. }
  353. /**
  354. * Register the command.
  355. *
  356. * @return void
  357. */
  358. protected function registerQueueTableCommand()
  359. {
  360. $this->app->singleton('command.queue.table', function ($app) {
  361. return new TableCommand($app['files'], $app['composer']);
  362. });
  363. }
  364. /**
  365. * Register the command.
  366. *
  367. * @return void
  368. */
  369. protected function registerRequestMakeCommand()
  370. {
  371. $this->app->singleton('command.request.make', function ($app) {
  372. return new RequestMakeCommand($app['files']);
  373. });
  374. }
  375. /**
  376. * Register the command.
  377. *
  378. * @return void
  379. */
  380. protected function registerSeederMakeCommand()
  381. {
  382. $this->app->singleton('command.seeder.make', function ($app) {
  383. return new SeederMakeCommand($app['files'], $app['composer']);
  384. });
  385. }
  386. /**
  387. * Register the command.
  388. *
  389. * @return void
  390. */
  391. protected function registerSessionTableCommand()
  392. {
  393. $this->app->singleton('command.session.table', function ($app) {
  394. return new SessionTableCommand($app['files'], $app['composer']);
  395. });
  396. }
  397. /**
  398. * Register the command.
  399. *
  400. * @return void
  401. */
  402. protected function registerRouteCacheCommand()
  403. {
  404. $this->app->singleton('command.route.cache', function ($app) {
  405. return new RouteCacheCommand($app['files']);
  406. });
  407. }
  408. /**
  409. * Register the command.
  410. *
  411. * @return void
  412. */
  413. protected function registerRouteClearCommand()
  414. {
  415. $this->app->singleton('command.route.clear', function ($app) {
  416. return new RouteClearCommand($app['files']);
  417. });
  418. }
  419. /**
  420. * Register the command.
  421. *
  422. * @return void
  423. */
  424. protected function registerRouteListCommand()
  425. {
  426. $this->app->singleton('command.route.list', function ($app) {
  427. return new RouteListCommand($app['router']);
  428. });
  429. }
  430. /**
  431. * Register the command.
  432. *
  433. * @return void
  434. */
  435. protected function registerServeCommand()
  436. {
  437. $this->app->singleton('command.serve', function () {
  438. return new ServeCommand;
  439. });
  440. }
  441. /**
  442. * Register the command.
  443. *
  444. * @return void
  445. */
  446. protected function registerTestMakeCommand()
  447. {
  448. $this->app->singleton('command.test.make', function ($app) {
  449. return new TestMakeCommand($app['files']);
  450. });
  451. }
  452. /**
  453. * Register the command.
  454. *
  455. * @return void
  456. */
  457. protected function registerTinkerCommand()
  458. {
  459. $this->app->singleton('command.tinker', function () {
  460. return new TinkerCommand;
  461. });
  462. }
  463. /**
  464. * Register the command.
  465. *
  466. * @return void
  467. */
  468. protected function registerUpCommand()
  469. {
  470. $this->app->singleton('command.up', function () {
  471. return new UpCommand;
  472. });
  473. }
  474. /**
  475. * Register the command.
  476. *
  477. * @return void
  478. */
  479. protected function registerVendorPublishCommand()
  480. {
  481. $this->app->singleton('command.vendor.publish', function ($app) {
  482. return new VendorPublishCommand($app['files']);
  483. });
  484. }
  485. /**
  486. * Register the command.
  487. *
  488. * @return void
  489. */
  490. protected function registerViewClearCommand()
  491. {
  492. $this->app->singleton('command.view.clear', function ($app) {
  493. return new ViewClearCommand($app['files']);
  494. });
  495. }
  496. /**
  497. * Register the command.
  498. *
  499. * @return void
  500. */
  501. protected function registerPolicyMakeCommand()
  502. {
  503. $this->app->singleton('command.policy.make', function ($app) {
  504. return new PolicyMakeCommand($app['files']);
  505. });
  506. }
  507. /**
  508. * Get the services provided by the provider.
  509. *
  510. * @return array
  511. */
  512. public function provides()
  513. {
  514. if ($this->app->environment('production')) {
  515. return array_values($this->commands);
  516. } else {
  517. return array_merge(array_values($this->commands), array_values($this->devCommands));
  518. }
  519. }
  520. }