Input and Output variables - Require PHP 5.3.0
Features :- Input sources (types) : GET, POST, COOKIE, FILES, SERVER, REQUEST, ENV, SESSION, local variables - Output format : HTML, URL, RAW, Base64, ISSET, SET - Format a input variable for an output format - Cached variables for performance - Exception or not if variable don't exist (configuration) - Charset can be specified - Types and format can be extended - Change values in superglobal arrays
Usage :$Input = In::getInstance(); echo $Input->G->RAW->id; // display $_GET['id'] without change echo $Input->P->HTML->foo; // display $_POST['foo'] for a HTML usage (htmlentities) echo $Input->C->B64->login; // display $_COOKIE['login'] in base64 encoding echo $Input->F->RAW->fileName; // display $FILES['fileName']; without change echo $Input->G->ISSET->id; // display TRUE if $_GET['id'] exists, FALSE otherwise echo $Input->G->SET->id = 'foo'; // change value of $_GET['id'] et reset caches in instance echo $Input->HTML($localVariable); // display $localVariable for a HTML usage (htmlentities)
Extend type or format :- Create a child class which extend In - Register type / format in register() method like predefined type/format in In - Implement convert() method for new formats in child class
Configuration :In::setThrowException(FALSE); // Return NULL instead of throwing exception if a variable don't exists. In::setCharset('...'); // Set a charset for htmlentities
Warning to the behavior with In cache :$Input = In::getInstance(); echo $Input->G->RAW->id; // display $_GET['id'] $_GET['id'] = 'new value'; echo $Input->G->RAW->id; // display the OLD value of $_GET['id'] because id is now in cache ! echo $Input->G->HTML->id; // display the NEW value of $_GET['id'] because id has been never asked for HTML format ! $_GET['machin'] = 'valeur'; echo $Input->G->RAW->machin; // display $_GET['machin'] because value has neven been asked, so it's not in cache. If we use $Input->G->SET->id = 'new value'; instead, this behavior vanish and all works as expected.
History2.0 (25/11/2017)The class became linked to SALT framework : Use of SALT Converters, better performance Use of SALT I18n translation Remove SQL format1.8 (03/03/2017)Remove array format feature : Allow this class to process array and scalar values on different ways is error prone. We can use RAW for retrieve unformated array values, and a loop for formatting each values.1.7 (15/08/2016)Translate in english1.6 (31/07/2016)Complete rewrite / simplification Removing magic_quotes support (deprecated in 5.3, removed in 5.4) Exception thrown for bad usage. setThrowException(FALSE) disable exceptions only for undefined variables. Add REQUEST, ENV, SESSION types Add SET format1.5 (10/07/2016)Add SERVER type Change URL implementation for using rawurlencode instead of urlencode1.4 (12/03/2011)Complete rewrite. Removing internal classes. New feature : register new type & format New format : URL & Base641.3 (15/02/2009)Bug fix : magic_quotes_gpc1.2New feature : Charset for htmlentities HTML format : use of ENT_QUOTES1.1 (29/12/2007)New feature : format local variables
author | Richaud Julien "Fladnag" |
---|---|
version | 1.8 |
package | salt\utils |
B64() :
magic | |
---|---|
method | value formatted with base64_encode() |
HTML() :
magic | |
---|---|
method | HTML value formatted with htmlentities(), ENT_QUOTES, and charset |
RAW() :
magic | |
---|---|
method | value without change |
URL() :
magic | |
---|---|
method | value formatted with rawurlencode() |
__call(string $method, array<mixed,mixed> $args)
string
the method/format
array<mixed,mixed>
\Exception |
static::_SALT_EX_UNDEFINED_FORMAT |
---|
__get(string $var) : mixed
string
Property name
\Exception |
static::_SALT_EX_UNDEFINED_VARIABLE if property don't exists, or NULL if exceptions disabled |
---|
mixed
value__set(string $var, mixed $value)
If the call is from self::setCache(), it's an internal call and we set the value without check.
If the call is from ->$type->SET-> , it's an external call and we set the value in $type array and we doing a cache reset
If the call is from another format ->$type->$format-> we throw an exception.
string
Property name to set
mixed
value
\Exception |
self::_SALT_EX_BAD_SETTER |
---|
getCharset() : string
string
charsetgetInstance() : static
static
instance of class (1 singleton by child class)haveToThrowException() : boolean
boolean
return TRUE if we have to thrown an exception if variable undefined.setCharset(string $charset)
setThrowException(boolean $throwException = TRUE
)
boolean
FALSE to not thrown exception if variable undefined.
register()
The method to override to register new type/format
Don't forget to call parent::register()
registerFormat(string $name, \salt\Converter $converter)
string
Name of format
\salt\Converter
Converter class
registerType(string $name, string $source)
string
Name of type
string
Name of superglobal array, without $ (for example "_GET" for "$_GET")
__construct(\salt\In $parent= NULL
, string $name= NULL
)
If $parent is provided, the return object depends on parent type.
If $parent is an _SALT_INSTANCE_BASE instance, will construct an _SALT_INSTANCE_TYPE instance
If $parent is an _SALT_INSTANCE_TYPE instance, will construct an _SALT_INSTANCE_FORMAT instance
\salt\In
Parent instance if we are in a delegation chain
string
Name of type or format
invalidCache(string $var)
string
Name of variable to remove from caches
setCache(string $var, mixed $value)
string
Name of property
mixed
New value
throwException(string $message, integer $type, boolean $force = FALSE
)
string
Exception message
integer
code, see self::_SALTEX*
boolean
(optional, FALSE) TRUE if we have to throw an internal exception and ignore configuration
\Exception |
self::_SALT_EX_* |
---|
$_saltCharset : string
NULL
$_saltInstances : array<mixed,\salt\In>
array()
$_saltRegistry : array<mixed,mixed[]>
array(self::_SALT_INSTANCE_TYPE => array(), self::_SALT_INSTANCE_FORMAT => array())
$_saltThrowException : boolean
TRUE
$_saltCacheSetter : boolean
FALSE
$_saltName : string
NULL
$_saltParent : \salt\In
NULL
$_saltType : integer
self::_SALT_INSTANCE_BASE
_SALT_EX_BAD_SETTER = 4
_SALT_EX_UNDEFINED_FORMAT = 2
_SALT_EX_UNDEFINED_TYPE = 3
_SALT_EX_UNDEFINED_VARIABLE = 1
_SALT_INSTANCE_BASE = -1
_SALT_INSTANCE_FORMAT = 1
_SALT_INSTANCE_TYPE = 0