From 8adbaa714d37bb7214f29b12c52354900a1c6dc5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 11 May 2017 07:41:22 -0500 Subject: [PATCH] formatting --- .../Encryption/EncryptionServiceProvider.php | 25 +++++++++------ src/Illuminate/Foundation/helpers.php | 32 ------------------- src/Illuminate/Support/helpers.php | 32 +++++++++++++++++++ 3 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/Illuminate/Encryption/EncryptionServiceProvider.php b/src/Illuminate/Encryption/EncryptionServiceProvider.php index ad365becc4eb..cffab95290e5 100755 --- a/src/Illuminate/Encryption/EncryptionServiceProvider.php +++ b/src/Illuminate/Encryption/EncryptionServiceProvider.php @@ -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.' + )); + }); + } } diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index 2e46346a9afb..337682fa9097 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -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. diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index d34eb6478e85..fd4af31eb3f7 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -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.