added key generation task.
This commit is contained in:
parent
70dd657e80
commit
20b4cf7bb8
|
@ -25,6 +25,16 @@
|
||||||
return new Tasks\Bundle\Bundler;
|
return new Tasks\Bundle\Bundler;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The key task is responsible for generating a secure, random
|
||||||
|
* key for use by the application when encrypting strings or
|
||||||
|
* setting the hash values on cookie signatures.
|
||||||
|
*/
|
||||||
|
IoC::singleton('task: key', function()
|
||||||
|
{
|
||||||
|
return new Tasks\Key;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The bundle repository is responsible for communicating with
|
* The bundle repository is responsible for communicating with
|
||||||
* the Laravel bundle sources to get information regarding any
|
* the Laravel bundle sources to get information regarding any
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?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!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -91,6 +91,7 @@
|
||||||
'Laravel\\CLI\\Tasks\\Migrate\\Migrator' => SYS_PATH.'cli/tasks/migrate/migrator'.EXT,
|
'Laravel\\CLI\\Tasks\\Migrate\\Migrator' => SYS_PATH.'cli/tasks/migrate/migrator'.EXT,
|
||||||
'Laravel\\CLI\\Tasks\\Migrate\\Resolver' => SYS_PATH.'cli/tasks/migrate/resolver'.EXT,
|
'Laravel\\CLI\\Tasks\\Migrate\\Resolver' => SYS_PATH.'cli/tasks/migrate/resolver'.EXT,
|
||||||
'Laravel\\CLI\\Tasks\\Migrate\\Database' => SYS_PATH.'cli/tasks/migrate/database'.EXT,
|
'Laravel\\CLI\\Tasks\\Migrate\\Database' => SYS_PATH.'cli/tasks/migrate/database'.EXT,
|
||||||
|
'Laravel\\CLI\\Tasks\\Key' => SYS_PATH.'cli/tasks/key'.EXT,
|
||||||
|
|
||||||
'Laravel\\Database\\Connection' => SYS_PATH.'database/connection'.EXT,
|
'Laravel\\Database\\Connection' => SYS_PATH.'database/connection'.EXT,
|
||||||
'Laravel\\Database\\Expression' => SYS_PATH.'database/expression'.EXT,
|
'Laravel\\Database\\Expression' => SYS_PATH.'database/expression'.EXT,
|
||||||
|
|
Loading…
Reference in New Issue