-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
230 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
@@ -46,7 +46,8 @@ class VarsServiceProvider implements ServiceProviderInterface | |
'cache_path', | ||
'cache_expire', | ||
'loaders', | ||
'replacements' | ||
'replacements', | ||
'merge_globals', | ||
); | ||
|
||
/** | ||
|
@@ -69,6 +70,22 @@ public function register(Application $app) | |
$app['vars'] = function ($app) { | ||
return new Vars($this->entity, $this->createOptions($app)); | ||
}; | ||
|
||
$app['vars.merge'] = $app->protect(function () use ($app) { | ||
static $initialized = false; | ||
if ($initialized) { | ||
return; | ||
} | ||
$initialized = true; | ||
|
||
foreach ($app['vars']->getGlobals() as $key => $value) { | ||
$app[$key] = $value; | ||
} | ||
|
||
foreach ($app['vars']->toDots(false) as $key => $value) { | ||
$app['vars.'.$key] = $value; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
|
@@ -90,6 +107,10 @@ private function createOptions($app) | |
$options = $this->createKeyedOptions($options, $app['vars.options']); | ||
} | ||
|
||
if (!isset($options['merge_globals']) || is_null($options['merge_globals'])) { | ||
$options['merge_globals'] = false; | ||
} | ||
|
||
if (isset($app['debug']) && $app['debug']) { | ||
$options['cache'] = false; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
* | ||
* @package m1/vars | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @author Miles Croxford <[email protected]> | ||
* @copyright Copyright (c) Miles Croxford <[email protected]> | ||
* @license http://github.com/m1/vars/blob/master/LICENSE | ||
|
@@ -25,7 +25,6 @@ | |
*/ | ||
trait TransformerTrait | ||
{ | ||
|
||
/** | ||
* Makes it so the content is available in getenv() | ||
*/ | ||
|
@@ -43,28 +42,34 @@ public function toEnv() | |
/** | ||
* Converts the array into a flat dot notation array | ||
* | ||
* @param bool $flatten_array Flatten arrays into none existent keys | ||
* | ||
* @return array The dot notation array | ||
*/ | ||
public function toDots() | ||
public function toDots($flatten_array = true) | ||
{ | ||
return (!is_null($this->content)) ? $this->dotTransformer($this->content) : $this->content; | ||
return (!is_null($this->content)) ? $this->dotTransformer($this->content, $flatten_array) : $this->content; | ||
} | ||
|
||
/** | ||
* Converts the array into a flat dot notation array | ||
* | ||
* @param array $content The content array | ||
* @param string $prefix The prefix for the key | ||
* @param array $content The content array | ||
* @param bool $flatten_array Flatten arrays into none existent keys | ||
* @param string $prefix The prefix for the key | ||
* | ||
* @return array The dot notation array | ||
*/ | ||
private function dotTransformer($content, $prefix = '') | ||
private function dotTransformer($content, $flatten_array, $prefix = '') | ||
{ | ||
$parsed = array(); | ||
|
||
foreach ($content as $arr_k => $arr_v) { | ||
if (is_array($arr_v)) { | ||
$parsed = array_merge($parsed, $this->dotTransformer($arr_v, $prefix.$arr_k.".")); | ||
if (!$flatten_array) { | ||
$parsed[$prefix.$arr_k] = $arr_v; | ||
} | ||
|
||
$parsed = array_merge($parsed, $this->dotTransformer($arr_v, $flatten_array, $prefix.$arr_k.".")); | ||
} else { | ||
$parsed[$prefix.$arr_k] = $arr_v; | ||
} | ||
|
Oops, something went wrong.