Commit a7e0cebe authored by Alex Ne's avatar Alex Ne

Input fix

parent 0384f319
<?php <?php
/** /**
* *
*/ */
class X_Input class X_Input {
{
protected $Value; protected $Value;
protected $Default = false; protected $Default = false;
function __construct() function __construct() {}
{ public function lower_string() {
return strtolower($this->string());
} }
public function lower_string() public function bool() {
{ if ( ! is_string($this->Value)) {
return strtolower($this->string()); return (bool) $this->Value;
} }
public function bool() switch (strtolower(trim($this->Value))) {
{
if (!is_string($this->Value)) return (bool) $this->Value;
switch ( strtolower( trim( $this->Value ) ) )
{
case 'true': case 'true':
case 'on': case 'on':
case 'yes': case 'yes':
...@@ -34,81 +29,75 @@ class X_Input ...@@ -34,81 +29,75 @@ class X_Input
} }
} }
public function str_replace($search, $replace) public function str_replace($search, $replace) {
{ return (is_string($this->Value)) ? str_replace($search, $replace, $this->Value) : "";
return (is_string($this->Value))?str_replace($search, $replace, $this->Value):""; }
public function explode($delimiter) {
return (is_string($this->Value)) ? explode($delimiter, $this->Value) : [];
} }
public function explode($delimiter) public function int() {
{ if ($this->Default === false) {
return (is_string($this->Value))?explode($delimiter, $this->Value):[]; $this->Default = 0;
} }
public function int()
{
if($this->Default === false) $this->Default = 0;
return intval($this->Value); return intval($this->Value);
} }
public function numeric() public function numeric() {
{
return (is_numeric($this->Value)) ? $this->Value : 0; return (is_numeric($this->Value)) ? $this->Value : 0;
} }
public function float() public function float() {
{
return floatval($this->Value); return floatval($this->Value);
} }
public function string() public function string() {
{
return strval($this->Value); return strval($this->Value);
} }
public function json_decode() public function json_decode() {
{ if ($this->Value == null) {
if($this->Value == null) return null; return null;
if($this->Value == false) return false; }
return json_decode($this->Value,true);
if ($this->Value == false) {
return false;
}
return json_decode($this->Value, true);
} }
public function RequestValue( $Name, $Default=false ) public function RequestValue($Name, $Default = false) {
{ return $this->Request($Name, $Default)->Value;
return $this->Request( $Name, $Default )->Value;
} }
public function Request( $Name, $Default=false ) public function Request($Name, $Default = false) {
{
return (new X_Input_RequestItem($Name, $Default)); return (new X_Input_RequestItem($Name, $Default));
} }
public function PostValue( $Name, $Default=false ) public function PostValue($Name, $Default = false) {
{ return $this->Post($Name, $Default)->Value;
return $this->Request( $Name, $Default )->Value;
} }
public function Post( $Name, $Default=false ) public function Post($Name, $Default = false) {
{
return (new X_Input_MethodPostItem($Name, $Default)); return (new X_Input_MethodPostItem($Name, $Default));
} }
public function GetValue( $Name, $Default=false ) public function GetValue($Name, $Default = false) {
{ return $this->Get($Name, $Default)->Value;
return $this->Get( $Name, $Default )->Value;
} }
public function Get( $Name, $Default=false ) public function Get($Name, $Default = false) {
{
return (new X_Input_MethodGetItem($Name, $Default)); return (new X_Input_MethodGetItem($Name, $Default));
} }
public function CookieValue( $Name, $Default=false ) public function CookieValue($Name, $Default = false) {
{ return $this->Cookie($Name, $Default)->Value;
return $this->Cookie( $Name, $Default )->Value;
} }
public function Cookie( $Name, $Default=false ) public function Cookie($Name, $Default = false) {
{
return (new X_Input_MethodCookieItem($Name, $Default)); return (new X_Input_MethodCookieItem($Name, $Default));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment