Created
December 31, 2013 18:08
-
-
Save bangpound/8200333 to your computer and use it in GitHub Desktop.
Silex application concept which uses the PHP $GLOBALS array as the service container.
This file contains hidden or 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
<?php | |
use Silex\Application; | |
class GlobalsApplication extends Application | |
{ | |
public function __construct(array $values = array()) | |
{ | |
// Set up the Silex services. | |
parent::__construct($values); | |
// Set aside Silex services and substitute a reference to the PHP globals array. | |
$values = $this->values; | |
$this->values = &$GLOBALS + $values; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function keys() | |
{ | |
// This helps prevent recursion errors. | |
return array_diff(parent::keys(), ['GLOBALS', 'app']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment