Allow overriding of PlSession::fillSession()
[platal.git] / classes / env.php
index 0e84462..abfea48 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -67,14 +67,26 @@ class Env
 
     public static function i($key, $default = 0)
     {
-        $i = Env::_get($key, $default);
-        return is_numeric($i) ? intval($i) : $default;
+        $i = to_integer(Env::_get($key, $default));
+        return $i === false ? $default : $i;
     }
 
     public static function l(array $keys)
     {
         return array_map(array('Env', 'v'), $keys);
     }
+
+    public static function set($key, $value)
+    {
+        $_REQUEST[$key] =& $value;
+    }
+
+    public static function bootstrap($key, $value)
+    {
+        if (!Env::has($key)) {
+            Env::set($key, $value);
+        }
+    }
 }
 
 class Post
@@ -125,14 +137,26 @@ class Post
 
     public static function i($key, $default = 0)
     {
-        $i = Post::_get($key, $default);
-        return is_numeric($i) ? intval($i) : $default;
+        $i = to_integer(Post::_get($key, $default));
+        return $i === false ? $default : $i;
     }
 
      public static function l(array $keys)
     {
         return array_map(array('Post', 'v'), $keys);
     }
+
+    public static function set($key, $value)
+    {
+        $_POST[$key] =& $value;
+    }
+
+    public static function bootstrap($key, $value)
+    {
+        if (!Post::has($key)) {
+            Post::set($key, $value);
+        }
+    }
 }
 
 class Get
@@ -183,14 +207,26 @@ class Get
 
     public static function i($key, $default = 0)
     {
-        $i = Get::_get($key, $default);
-        return is_numeric($i) ? intval($i) : $default;
+        $i = to_integer(Get::_get($key, $default));
+        return $i === false ? $default : $i;
     }
 
     public static function l(array $keys)
     {
         return array_map(array('Get', 'v'), $keys);
     }
+
+    public static function set($key, $value)
+    {
+        $_GET[$key] =& $value;
+    }
+
+    public static function bootstrap($key, $value)
+    {
+        if (!Get::has($key)) {
+            Get::set($key, $value);
+        }
+    }
 }
 
 class Cookie
@@ -258,8 +294,8 @@ class Cookie
 
     public static function i($key, $default = 0)
     {
-        $i = Cookie::_get($key, $default);
-        return is_numeric($i) ? intval($i) : $default;
+        $i = to_integer(Cookie::_get($key, $default));
+        return $i === false ? $default : $i;
     }
 
     public static function l(array $keys)