Guest User

Untitled

a guest
Jul 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2.  
  3. class Environment {
  4.     protected $_source;
  5.    
  6.     public final function __construct(array &$source = array()) {
  7.             if (empty($source)) {$source = $_SERVER;}
  8.         $this->_source = array();a
  9.         foreach( $source as $key => $value ){
  10.             $this->_source[ convertName($key) ] = &$source[$key];
  11.         }
  12.     }
  13.  
  14.     private function convertName( $key ){
  15.         $functionName = implode('', array_map(function ($in) {return ucfirst($in);}, explode('_',       strtolower($key))));
  16.         return $functionName;
  17.     }
  18.  
  19.     protected function _get($key) {
  20.         if (isset($this->_source[$key])) {return $this->_source[$key];} return NULL;
  21.     }
  22. }
  23.  
  24. $e = new Environment();
  25.  
  26. echo $e->HttpUserAgent;
Add Comment
Please, Sign In to add comment