env() public method

Get environment variables.
public env ( string $key = null ) : mixed
$key string
return mixed Returns the environment key related to the `$key` argument. If `$key` is equal to null the result will be the entire environment array. If `$key` is set but not available, `null` will be returned.
Ejemplo n.º 1
0
 public function testConstructWithEnv()
 {
     $base = Libraries::get(true, 'resources') . '/tmp/tests';
     $this->skipIf(!is_readable($base), "Path `{$base}` is not readable.");
     chdir(Libraries::get(true, 'resources') . '/tmp');
     $request = new Request(array('env' => array('working' => '/some/other/path')));
     $expected = '/some/other/path';
     $result = $request->env('working');
     $this->assertEqual($expected, $result);
 }
Ejemplo n.º 2
0
 public function testConstructWithEnv()
 {
     chdir(LITHIUM_APP_PATH . '/resources/tmp');
     $request = new Request(array('env' => array('working' => '/some/other/path')));
     $expected = '/some/other/path';
     $result = $request->env('working');
     $this->assertEqual($expected, $result);
 }
Ejemplo n.º 3
0
 public function testConstructWithEnv()
 {
     $base = LITHIUM_APP_PATH . '/resources/tmp/tests';
     $this->skipIf(!is_readable($base), "{$base} is not writable.");
     chdir(LITHIUM_APP_PATH . '/resources/tmp');
     $request = new Request(array('env' => array('working' => '/some/other/path')));
     $expected = '/some/other/path';
     $result = $request->env('working');
     $this->assertEqual($expected, $result);
 }
Ejemplo n.º 4
0
 /**
  * Detects preferred locales from a console request by looking at certain
  * environment variables. The environment variables may be present or not
  * depending on your system. If multiple variables are present the following
  * hierarchy is used: `'LANGUAGE'`,  `'LC_ALL'`, `'LANG'`.
  *
  * The locales of the `'LC_ALL'` and the `'LANG'` are formatted according
  * to the posix standard: `language(_territory)(.encoding)(@modifier)`.
  * Locales having such a format are automatically canonicalized and transformed
  * into the `Locale` class' format.
  *
  * @link http://www.linux.com/archive/feature/53781
  * @param \lithium\console\Request $request
  * @return array Preferred locales in their canonical form (i.e. `'fr_CA'`).
  */
 protected static function _preferredConsole($request)
 {
     $regex = '(?P<locale>[\\w\\_]+)(\\.|@|$)+';
     $result = array();
     if ($value = $request->env('LANGUAGE')) {
         return explode(':', $value);
     }
     foreach (array('LC_ALL', 'LANG') as $variable) {
         $value = $request->env($variable);
         if (!$value || $value === 'C' || $value === 'POSIX') {
             continue;
         }
         if (preg_match("/{$regex}/", $value, $matches)) {
             return (array) $matches['locale'];
         }
     }
     return $result;
 }