Skip to content

Commit

Permalink
修改input
Browse files Browse the repository at this point in the history
  • Loading branch information
lhs168 committed Jan 9, 2018
1 parent 49e414e commit 591cf66
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 78 deletions.
107 changes: 32 additions & 75 deletions src/Fasim/Core/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public function raw() {
return $this->rawValue;
}

public function exists() {
return $this->rawValue === null;
}

public function trim() {
$value = '';
if ($this->rawValue !== null) {
Expand Down Expand Up @@ -55,81 +59,12 @@ public function __toString() {
}
}

class InputCollection implements \IteratorAggregate, \ArrayAccess, \Serializable {
private $_data = array();
private $_nullItem = null;
public function __construct($data) {
foreach ($data as $key => $val) {
$item = new InputItem($val);
$this->_data[$key] = $item;
}
$this->_nullItem = new InputItem(null);
}

public function getIterator() {
return new \ArrayIterator($this->_data);
}

public function offsetSet($offset, $value) {
if (is_null($offset)) {
$this->_data[] = $value;
} else {
$this->_data[$offset] = $value;
}
}

public function offsetExists($offset) {
return isset($this->_data[$offset]);
}

public function offsetUnset($offset) {
unset($this->_data[$offset]);
}

public function offsetGet($offset) {
return isset($this->_data[$offset]) ? $this->_data[$offset] : $this->_nullItem;
}

public function serialize() {
$serializes = [];
foreach ($data as $key => $val) {
$serializes[$key] = $val->raw();
}
return serialize($serializes);
}

public function unserialize($data) {
$unserializes = unserialize($data);
$this->_data = [];
foreach ($unserializes as $key => $val) {
$item = new InputItem($val);
$this->_data[$key] = $item;
}
}

public function __get($key) {
return $this->offsetGet($key);
}

}

/**
* @class Request
* 输入类
*/
class Input extends InputCollection {
/**
* get data
*
* @var array
*/
public $get = array();
/**
* post data
*
* @var array
*/
public $post = array();
class Input {

/**
* http referer
*
Expand Down Expand Up @@ -164,17 +99,39 @@ public function __construct() {
$this->sanitizeGlobals();

//todo:filter get and post data
$this->get = new InputCollection($_GET);
$this->post = new InputCollection($_POST);
$request = array_merge($_GET, $_POST);

parent::__construct($request);
}


public function isPost() {
return $_POST ? true : false;
}

public function get($index) {
$value = null;
if (isset($_GET[$index])) {
$value = $_GET[$index];
}
return new InputItem($value);
}

public function post($index) {
$value = null;
if (isset($_POST[$index])) {
$value = $_POST[$index];
}
return new InputItem($value);
}

public function request($index) {
$value = null;
if (isset($_POST[$index])) {
$value = $_POST[$index];
} else if (isset($_GET[$index])) {
$value = $_GET[$index];
}
return new InputItem($value);
}

/**
* Fetch an item from either the GET array or the POST
Expand Down
5 changes: 2 additions & 3 deletions src/Fasim/Widget/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace Fasim\Widget;

use Fasim\Facades\Config;
use Fasim\Facades\Request;
use Fasim\Facades\Input;
use Fasim\Library\Pager;

class Table {
Expand All @@ -17,8 +17,7 @@ class Table {
private $pager = null;

public function __construct() {
$page = Request::intval(('page'));

$page = Input::request('page')->intval();
$this->pager = new Pager();
$this->pager->pageSize = 20;
$this->pager->style = Pager::Bootstrap;
Expand Down

0 comments on commit 591cf66

Please sign in to comment.