Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
03f72872
Unverified
Commit
03f72872
authored
Sep 28, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set the application key ourself, based of laravel command
parent
e34427b9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
3 deletions
+72
-3
SetAppKey.php
Modules/Core/Console/Installers/Scripts/SetAppKey.php
+72
-3
No files found.
Modules/Core/Console/Installers/Scripts/SetAppKey.php
View file @
03f72872
...
@@ -3,10 +3,13 @@
...
@@ -3,10 +3,13 @@
namespace
Modules\Core\Console\Installers\Scripts
;
namespace
Modules\Core\Console\Installers\Scripts
;
use
Illuminate\Console\Command
;
use
Illuminate\Console\Command
;
use
Illuminate\Encryption\Encrypter
;
use
Illuminate\Console\ConfirmableTrait
;
use
Modules\Core\Console\Installers\SetupScript
;
use
Modules\Core\Console\Installers\SetupScript
;
class
SetAppKey
implements
SetupScript
class
SetAppKey
implements
SetupScript
{
{
use
ConfirmableTrait
;
/**
/**
* Fire the install script
* Fire the install script
* @param Command $command
* @param Command $command
...
@@ -14,11 +17,77 @@ class SetAppKey implements SetupScript
...
@@ -14,11 +17,77 @@ class SetAppKey implements SetupScript
*/
*/
public
function
fire
(
Command
$command
)
public
function
fire
(
Command
$command
)
{
{
if
(
$command
->
option
(
'verbose'
))
{
$key
=
$this
->
generateRandomKey
();
$command
->
call
(
'key:generate'
);
// Next, we will replace the application key in the environment file so it is
// automatically setup for this developer. This key gets generated using a
// secure random byte generator and is later base64 encoded for storage.
if
(
!
$this
->
setKeyInEnvironmentFile
(
$key
))
{
return
;
return
;
}
}
$command
->
callSilent
(
'key:generate'
);
config
()
->
set
(
'app.key'
,
$key
);
if
(
$command
->
option
(
'verbose'
))
{
$command
->
info
(
"Application key [
$key
] set successfully."
);
}
}
/**
* Generate a random key for the application.
*
* @return string
*/
protected
function
generateRandomKey
()
{
return
'base64:'
.
base64_encode
(
Encrypter
::
generateKey
(
config
(
'app.cipher'
))
);
}
/**
* Set the application key in the environment file.
*
* @param string $key
* @return bool
*/
protected
function
setKeyInEnvironmentFile
(
$key
)
{
$currentKey
=
config
(
'app.key'
);
if
(
strlen
(
$currentKey
)
!==
0
&&
(
!
$this
->
confirmToProceed
()))
{
return
false
;
}
$this
->
writeNewEnvironmentFileWith
(
$key
);
return
true
;
}
/**
* Write a new environment file with the given key.
*
* @param string $key
* @return void
*/
protected
function
writeNewEnvironmentFileWith
(
$key
)
{
file_put_contents
(
app
()
->
environmentFilePath
(),
preg_replace
(
$this
->
keyReplacementPattern
(),
'APP_KEY='
.
$key
,
file_get_contents
(
app
()
->
environmentFilePath
())
));
}
/**
* Get a regex pattern that will match env APP_KEY with any random key.
*
* @return string
*/
protected
function
keyReplacementPattern
()
{
$escaped
=
preg_quote
(
'='
.
config
(
'app.key'
),
'/'
);
return
"/^APP_KEY
{
$escaped
}
/m"
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment