123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php namespace Maze\Http;
- class Input
- {
- /**
- * term
- *
- * @var array
- */
- static public $request = array();
- /**
- * term
- *
- * @var array
- */
- static protected $term;
- /**
- * init
- *
- * @return array
- */
- static public function init()
- {
- global $argc,$argv; #$argc 和 $argv 不是全局变量,要在这里面再赋值一次 :(
- #如果参数大于 ,就说明有参数
- if($argc > 1)
- {
- #分析并保存Term数据
- $term = array();
- $key = '';
- #第一位是程序名称,不用分析
- for($i=1; $i<$argc; $i++)
- {
- #以“-”开头,说明是变量,保存Key值
- if(substr($argv[$i],0,1) == '-' || substr($argv[$i],0,1) == '^')
- {
- #上一个Key还未失效,就赋值为空
- if($key != '')
- {
- $term[$key] = $key;
- }
- $key = substr($argv[$i],1);
- continue;
- }
- #有Key设置为key,否则设置此变量为Key
- if($key != '')
- {
- $term[$key] = $argv[$i];
- $key = '';
- }
- else
- {
- $term[$argv[$i]] = $argv[$i];
- }
- }
- self::$request = $term;
- self::$request['maze_shell'] = 1;
- }
- else
- {
- self::$request = array_merge($_GET, $_POST, $_FILES);
- }
- return true;
- }
- /**
- * get
- * @param string $name
- *
- * @return array
- */
- static public function get($name = false, $default = '')
- {
- if(!$name) return self::$request;
- if($default && $default == '-u')
- {
- $array = array('update_', 'set_', 'add_');
- foreach($array as $k => $v)
- {
- if(isset(self::$request[$v . $name]))
- {
- return self::$request[$v . $name];
- }
- }
- return false;
- }
-
- if(isset(self::$request[$name]) && self::$request[$name])
- {
- $default = self::$request[$name];
- }
- return $default;
- }
- /**
- * prefix 获取包含有该前缀的值
- * @param string $name
- *
- * @return array
- */
- static public function prefix($name)
- {
- $key = 'prefix_' . $name;
- if(isset(self::$request[$key]))
- {
- return self::$request[$key];
- }
- self::$request[$key] = array();
- foreach(self::$request as $k => $v)
- {
- if(strpos($k, $name) === 0)
- {
- self::$request[$key][$k] = $v;
- }
- }
- return self::$request[$key];
- }
- /**
- * set
- * @param string $name
- *
- * @return array
- */
- static public function set($name, $value = '', $prefix = false)
- {
- if($name == 'all')
- {
- self::$request = array_merge(self::$request, $value);
- }
- else
- {
- self::$request[$name] = $value;
- }
-
- if($prefix)
- {
- $prefix = 'prefix_' . $prefix;
- if(isset(self::$request[$prefix]))
- {
- self::$request[$prefix][$name] = $value;
- }
- }
- return $value;
- }
- }
|