Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added superglobals to the full environment. Added the webapp environm…

…ent.
  • Loading branch information...
commit 2767e02febd2d96c50501e5bf75b69efe92e06e8 1 parent 41e9623
@dahlia dahlia authored
Showing with 39 additions and 1 deletion.
  1. +26 −1 Lisphp/Environment.php
  2. +13 −0 Lisphp/Test/EnvironmentTest.php
View
27 Lisphp/Environment.php
@@ -60,8 +60,33 @@ static function sandbox() {
static function full() {
$scope = new Lisphp_Scope(self::sandbox());
- $scope['use'] = new Lisphp_Runtime_Use;
+ $scope->let('use', new Lisphp_Runtime_Use);
+ $scope->let('*env*', $_ENV);
+ $scope->let('*server*', $_SERVER);
return $scope;
}
+
+ protected static $antimagicFunction = null;
+
+ protected static function antimagic($vars) {
+ if (!$f = self::$antimagicFunction) {
+ self::$antimagicFunction = create_function('$vars', '
+ return is_array($vars)
+ ? array_map(' . __CLASS__ . '::$antimagicFunction, $vars)
+ : stripslashes($vars);
+ ');
+ }
+ return $f($vars);
+ }
+
+ static function webapp() {
+ $scope = new Lisphp_Scope(self::sandbox());
+ $scope->let('*get*', self::antimagic($_GET));
+ $scope->let('*post*', self::antimagic($_POST));
+ $scope->let('*request*', self::antimagic($_REQUEST));
+ $scope->let('*files*', $_FILES);
+ $scope->let('*cookie*', self::antimagic($_COOKIE));
+ $scope->let('*session*', $_SESSION);
+ }
}
View
13 Lisphp/Test/EnvironmentTest.php
@@ -90,6 +90,19 @@ function testFull() {
$scope = Lisphp_Environment::full();
$this->testSandbox($scope);
$this->assertType('Lisphp_Runtime_Use', $scope['use']);
+ $this->assertEquals($_ENV, $scope['*env*']);
+ $this->assertEquals($_SERVER, $scope['*server*']);
+ }
+
+ function testWebapp() {
+ if (!isset($_GET, $_POST, $_REQUEST, $_FILES, $_COOKIE, $_SESSION)) {
+ $this->markTestSkipped(
+ 'Lisphp_Environment::webapp() is unavailable on CLI'
+ );
+ }
+ # TODO: *get*, *post*, *request*, antimagic.
+ $this->assertEquals($_SESSION, $scope['*session*']);
+ $this->assertEquals($_FILES, $scope['*files*']);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.