SessionTableCommand.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Illuminate\Session\Console;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Composer;
  5. use Illuminate\Filesystem\Filesystem;
  6. class SessionTableCommand extends Command
  7. {
  8. /**
  9. * The console command name.
  10. *
  11. * @var string
  12. */
  13. protected $name = 'session:table';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Create a migration for the session database table';
  20. /**
  21. * The filesystem instance.
  22. *
  23. * @var \Illuminate\Filesystem\Filesystem
  24. */
  25. protected $files;
  26. /**
  27. * @var \Illuminate\Support\Composer
  28. */
  29. protected $composer;
  30. /**
  31. * Create a new session table command instance.
  32. *
  33. * @param \Illuminate\Filesystem\Filesystem $files
  34. * @param \Illuminate\Support\Composer $composer
  35. * @return void
  36. */
  37. public function __construct(Filesystem $files, Composer $composer)
  38. {
  39. parent::__construct();
  40. $this->files = $files;
  41. $this->composer = $composer;
  42. }
  43. /**
  44. * Execute the console command.
  45. *
  46. * @return void
  47. */
  48. public function handle()
  49. {
  50. $fullPath = $this->createBaseMigration();
  51. $this->files->put($fullPath, $this->files->get(__DIR__.'/stubs/database.stub'));
  52. $this->info('Migration created successfully!');
  53. $this->composer->dumpAutoloads();
  54. }
  55. /**
  56. * Create a base migration file for the session.
  57. *
  58. * @return string
  59. */
  60. protected function createBaseMigration()
  61. {
  62. $name = 'create_sessions_table';
  63. $path = $this->laravel->databasePath().'/migrations';
  64. return $this->laravel['migration.creator']->create($name, $path);
  65. }
  66. }