| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php namespace Laravel\CLI\Tasks;
- use Laravel\Str;
- use Laravel\File;
- class Key extends Task {
- /**
- * The path to the application config.
- *
- * @var string
- */
- protected $path;
- /**
- * Create a new instance of the Key task.
- *
- * @return void
- */
- public function __construct()
- {
- $this->path = APP_PATH.'config/application'.EXT;
- }
- /**
- * Generate a random key for the application.
- *
- * @param array $arguments
- * @return void
- */
- public function generate($arguments = array())
- {
- // By default the Crypter class uses AES-256 encryption which uses
- // a 32 byte input vector, so that is the length of string we will
- // generate for the application token unless another length is
- // specified through the CLI.
- $key = Str::random(array_get($arguments, 0, 32));
- $config = str_replace("'key' => '',", "'key' => '{$key}',", File::get($this->path), $count);
- File::put($this->path, $config);
- if ($count > 0)
- {
- echo "Configuration updated with secure key!";
- }
- else
- {
- echo "An application key already exists!";
- }
- }
- }
|