Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 11, 2017
1 parent 8f1a966 commit 8adbaa7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 41 deletions.
25 changes: 16 additions & 9 deletions src/Illuminate/Encryption/EncryptionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@ public function register()
$this->app->singleton('encrypter', function ($app) {
$config = $app->make('config')->get('app');

$key = $config['key'];

if (is_null($key) || $key === '') {
throw new RuntimeException(
'The application encryption key is missing. Run php artisan key:generate to generate it.'
);
}

// If the key starts with "base64:", we will need to decode the key before handing
// it off to the encrypter. Keys may be base-64 encoded for presentation and we
// want to make sure to convert them back to the raw bytes before encrypting.
if (Str::startsWith($key, 'base64:')) {
if (Str::startsWith($key = $this->key($config), 'base64:')) {
$key = base64_decode(substr($key, 7));
}

return new Encrypter($key, $config['cipher']);
});
}

/**
* Extract the encryption key from the given configuration.
*
* @param array $config
* @return string
*/
protected function key(array $config)
{
return tap($config['key'], function ($key) {
throw_if(empty($key), new RuntimeException(
'No application encryption key has been specified.'
));
});
}

This comment has been minimized.

Copy link
@vlakoff

vlakoff Sep 2, 2017

Contributor

Wow. So much voodoo added to this file in this commit. Does anyone really think it's clearer?

}
32 changes: 0 additions & 32 deletions src/Illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,38 +827,6 @@ function storage_path($path = '')
}
}

if (! function_exists('throw_if')) {
/**
* Throw the given exception if the given boolean is true.
*
* @param bool $boolean
* @param \Throwable $exception
* @return void
*/
function throw_if($boolean, $exception)
{
if ($boolean) {
throw $exception;
}
}
}

if (! function_exists('throw_unless')) {
/**
* Throw the given exception unless the given boolean is true.
*
* @param bool $boolean
* @param \Throwable $exception
* @return void
*/
function throw_unless($boolean, $exception)
{
if (! $boolean) {
throw $exception;
}
}
}

if (! function_exists('trans')) {
/**
* Translate the given message.
Expand Down
32 changes: 32 additions & 0 deletions src/Illuminate/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,38 @@ function tap($value, $callback = null)
}
}

if (! function_exists('throw_if')) {
/**
* Throw the given exception if the given boolean is true.
*
* @param bool $boolean
* @param \Throwable $exception
* @return void
*/
function throw_if($boolean, $exception)
{
if ($boolean) {
throw $exception;
}
}
}

if (! function_exists('throw_unless')) {
/**
* Throw the given exception unless the given boolean is true.
*
* @param bool $boolean
* @param \Throwable $exception
* @return void
*/
function throw_unless($boolean, $exception)
{
if (! $boolean) {
throw $exception;
}
}
}

if (! function_exists('title_case')) {
/**
* Convert a value to title case.
Expand Down

0 comments on commit 8adbaa7

Please sign in to comment.