Skip to content

Instantly share code, notes, and snippets.

@bangpound
Created December 31, 2013 18:08
Show Gist options
  • Save bangpound/8200333 to your computer and use it in GitHub Desktop.
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.
<?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