Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /**
- * ILLI
- *
- * @category ILLI_Core
- * @package ILLI
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\Core;
- USE ReflectionClass;
- /**
- * ILLI Enumeration Parser
- *
- * @category ILLI_Core
- * @package ILLI
- * @subpackage Core
- * @namespace ILLI\Core
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.1
- * @version 3.0.1
- */
- TRAIT tEnum
- {
- /**
- * defined constants in class
- *
- * CONST_NAME is defined by class
- *
- * @var array spl class => CONST_NAME => [ \ILLI\System\Bitwise | value ]
- * @static
- */
- private static $__tEnum_constants = [];
- /**
- * defined constants in class in variable format
- *
- * normalized CONST_NAME: MY_MATH_CONST -> $myMathConst
- *
- * @var array spl class => constName => [ \ILLI\System\Bitwise | value ]
- * @static
- */
- private static $__tEnum_variables = [];
- /**
- * dictionary: relation between value and CONST_NAME and $constName
- *
- * @var array spl class => value => array('const' => CONST_NAME, 'var' => constName)
- * @static
- */
- private static $__tEnum_dict = [];
- /**
- * callable stack
- *
- * CONST_NAME and $constName in lowercase, sorted by value for __callStatic
- *
- * @var array spl class => constname | const_name => [ \ILLI\System\Bitwise | value ]
- * @static
- */
- private static $__tEnum_callable = [];
- /**
- * Enumerable implements interface \ILLI\System\iProviderBitwise
- *
- * in that case all values will be converted to \ILLI\System\Bitwise
- *
- * @var bool
- */
- private static $__tEnum_isBitwise = [];
- /**
- * the current bit
- *
- * @var \ILLI\System\Bitwise
- */
- private $__tEnum_Flag = NULL;
- /**
- * name of the invoked Constant
- *
- * @var string
- * @see \ILLI\System\tEum\tEnum_invokeConstant
- */
- private $__tEnum_constantRequest = '';
- /**
- * name of the invoked variable
- *
- * @var string
- * @see \ILLI\System\tEum\tEnum_invokeConstant
- */
- private $__tEnum_variableRequest = '';
- /**
- * name of the invoke
- *
- * @var string
- * @see \ILLI\System\tEum\tEnum_invokeConstant
- */
- private $__tEnum_methodRequest = '';
- /**
- * the current bit flag as variable stock (reversed bitflag)
- *
- * @var array array(2 => 'myConst1', 4 => 'myConst2'); (6)
- */
- private $__tEnum_variablesHook = [];
- /**
- * the current bit flag as variable stock (reversed bitflag)
- *
- * @var array array(2 => 'MY_CONST_1', 4 => 'MY_CONST_2'); (6)
- */
- private $__tEnum_constantsHook = [];
- /**
- * the current bit flag as decimal stock (reversed bitflag)
- *
- * @var array array(2, 4); (6)
- */
- private $__tEnum_integerHook = [];
- /**
- * the current bit flag as bitmask
- *
- * @var array array(1, 1, 0); (6)
- */
- private $__tEnum_bitwiseHook = [];
- private function tEnum___register(Enum $ENUM)
- {
- $reflector = new ReflectionClass(get_called_class());
- self::$__tEnum_constants [get_called_class()] = $reflector->getConstants();
- self::$__tEnum_variables [get_called_class()] = [];
- self::$__tEnum_dict [get_called_class()] = [];
- self::$__tEnum_isBitwise [get_called_class()] = ($this instanceOf iProviderBitwise);
- if(FALSE === $reflector->isFinal())
- throw new \Exception('Enumeration '.get_called_class().' is not final.');
- if(FALSE === (bool) self::$__tEnum_constants)
- throw new \Exception('Enumeration '.get_called_class().' has no constants.');
- foreach(self::$__tEnum_constants[get_called_class()] as $const => $value)
- {
- // make constants as variable/function accessible; format: MY_CONST => $myConst
- $var = lcfirst(implode('', array_map('ucfirst', array_map('strtolower', explode('_', $const)))));
- self::$__tEnum_dict[get_called_class()][$value] = ['const' => $const, 'var' => $var];
- if(TRUE === self::$__tEnum_isBitwise[get_called_class()])
- {
- if(FALSE === is_integer($value))
- throw new \Exception('Value for Bitwise Flag must be of type integer. Type for '.$value.' is '.getType($value).'.');
- $value = new Bitwise($value);
- self::$__tEnum_constants[get_called_class()][$const] = $value;
- }
- self::$__tEnum_variables[get_called_class()][$var] = $value;
- }
- foreach(self::$__tEnum_constants[get_called_class()] as $avail => $value)
- self::$__tEnum_callable[get_called_class()][strtolower($avail)] = $value;
- foreach(self::$__tEnum_variables[get_called_class()] as $avail => $value)
- self::$__tEnum_callable[get_called_class()][strtolower($avail)] = $value;
- return $this;
- }
- private function tEnum___unregister()
- {
- unset(self::$__tEnum_constants [get_called_class()]);
- unset(self::$__tEnum_variables [get_called_class()]);
- unset(self::$__tEnum_dict [get_called_class()]);
- unset(self::$__tEnum_callable [get_called_class()]);
- unset(self::$__tEnum_isBitwise [get_called_class()]);
- return $this;
- }
- public function tEnum_getDefinedConstants()
- {
- return array_keys(self::$__tEnum_constants[get_called_class()]);
- }
- public function tEnum_getDefinedVariables()
- {
- return array_keys(self::$__tEnum_variables[get_called_class()]);
- }
- public function tEnum_getEnumeratedConstants()
- {
- return $this->__tEnum_constantsHook;
- }
- public function tEnum_getEnumeratedVariables()
- {
- return $this->__tEnum_variablesHook;
- }
- public function tEnum_getEnumeratedIntegers()
- {
- return $this->__tEnum_integerHook;
- }
- public function tEnum_getEnumeratedBitwise()
- {
- return $this->__tEnum_integerHook;
- }
- /**
- * invoke a constant as function
- *
- * <code>
- * <?PHP
- * $foo = MyEnumDef::myConst1();
- * ?>
- * </code>
- *
- */
- public function tEnum_invokeConstant($index)
- {
- $this->__tEnum_methodRequest = $index;
- $index = strtolower($index);
- if(FALSE === array_key_exists($index, self::$__tEnum_callable[get_called_class()]))
- throw new \Exception('Enumeration '.$index.' is not valid.');
- $this->__tEnum_Flag = self::$__tEnum_callable[get_called_class()][$index];
- $this->__tEnum_integerHook = self::$__tEnum_callable[get_called_class()][$index]->toStock();
- $this->__tEnum_bitwiseHook = self::$__tEnum_callable[get_called_class()][$index]->toArray();
- $this->__tEnum_variablesHook = [];
- $this->__tEnum_constantsHook = [];
- $summary = 0;
- foreach($this->__tEnum_integerHook as $dec)
- {
- $this->__tEnum_variablesHook[$dec] = self::$__tEnum_dict[get_called_class()][$dec]['var'];
- $this->__tEnum_constantsHook[$dec] = self::$__tEnum_dict[get_called_class()][$dec]['const'];
- $summary += $dec;
- }
- $this->__tEnum_variableRequest = self::$__tEnum_dict[get_called_class()][$summary]['var'];
- $this->__tEnum_constantRequest = self::$__tEnum_dict[get_called_class()][$summary]['const'];
- /*
- var_dump([
- '__tEnum_Flag' => $this->__tEnum_Flag,
- '__tEnum_integerHook' => $this->__tEnum_integerHook,
- '__tEnum_bitwiseHook' => $this->__tEnum_bitwiseHook,
- '__tEnum_variablesHook' => $this->__tEnum_variablesHook,
- '__tEnum_constantsHook' => $this->__tEnum_constantsHook,
- '__tEnum_constants' => self::$__tEnum_constants,
- '__tEnum_variables' => self::$__tEnum_variables,
- '__tEnum_callable' => self::$__tEnum_callable,
- '__tEnum_dict' => self::$__tEnum_dict,
- ]);
- */
- return $this;
- }
- }
- /**
- * ILLI
- *
- * @category ILLI_Core
- * @package ILLI
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\Core;
- /**
- * ILLI Enum
- *
- * <code>
- * <?PHP
- * FINAL CLASS eMyEnumeration EXTENDS Enum
- * {
- * const MONDAY = 1;
- * }
- * ?>
- * </code>
- *
- * @category ILLI_Core
- * @package ILLI
- * @subpackage Core
- * @namespace ILLI\Core
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.1
- * @version 3.0.1
- */
- ABSTRACT CLASS Enum EXTENDS Core IMPLEMENTS iStaticStorage
- {
- USE tStaticSplHashRegister
- {
- tSplHashRegister_register as private __splRegister;
- tSplHashRegister_unregister as private __splUnregister;
- tSplHashRegister_getCode as private splGetHashCode;
- tSplHashRegister_getInstances as private splGetInstances;
- tSplHashRegister_getSiblings as private splGetSiblingInstances;
- }
- USE tInstance
- {
- tInstance_unregister as private __instanceUnregister;
- tInstance_get as private __instanceGet;
- tInstance_register as private instanceRegister;
- tInstance_getName as private instanceGetName;
- tInstance_exists as private instanceExists;
- tInstance_getNames as private instanceGetNames;
- }
- USE tStaticStorage
- {
- tStorage___register as private __storageRegister;
- tStorage___unregister as private __storageUnregister;
- tStorage_get as private storageGet;
- tStorage_getIterator as public getIterator;
- tStorage_push as private storagePush;
- tStorage_pop as private storagePop;
- tStorage_peek as private storagePeek;
- }
- USE tEnum
- {
- tEnum___register as private __enumRegister;
- tEnum___unregister as private __enumUnregister;
- tEnum_invokeConstant as private __enumerate;
- tEnum_getDefinedConstants as public enumGetDefinedConstants;
- tEnum_getDefinedVariables as public enumGetDefinedVariables;
- tEnum_getEnumeratedConstants as public enumGetConstantsArray;
- tEnum_getEnumeratedVariables as public enumGetVariablesArray;
- tEnum_getEnumeratedIntegers as public enumGetIntegersArray;
- tEnum_getEnumeratedBitwise as public enumGetBitwiseArray;
- }
- public function __destruct()
- {
- $this->__splUnregister();
- $this->__instanceUnregister($this);
- $this->__storageUnregister();
- $this->__enumUnregister($this);
- }
- public static function instanceGet()
- {
- if(self::splGetHashCode() === NULL)
- self::__staticConstruct();
- return self::__instanceGet();
- }
- public static function __callStatic($index, $args)
- {
- if(self::splGetHashCode() === NULL)
- self::__staticConstruct();
- self::__instanceGet()->__enumerate($index);
- return self::__instanceGet();
- }
- private function __construct()
- {
- }
- private function __clone()
- {
- }
- private static function __staticConstruct()
- {
- self::__instanceGet()->__splRegister();
- self::__instanceGet()->__enumRegister(self::__instanceGet());
- //self::__instanceGet()->__storageRegister(new FacadeArrayList(new Collection));
- }
- public function __get($constant)
- {
- }
- }
- /**
- * ILLI
- *
- * @category ILLI_System
- * @package ILLI
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\System;
- /**
- * ILLI Uri Component Enumeration
- *
- * @category ILLI_System
- * @package ILLI
- * @subpackage System
- * @namespace ILLI\System
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.1
- * @version 3.0.1
- */
- FINAL CLASS eUriComponents EXTENDS \ILLI\Core\Enum IMPLEMENTS \ILLI\Core\iProviderBitwise
- {
- /**
- * @const int ILLI\System\Uri::$scheme
- */
- const SCHEME = 1;
- /**
- * @const int ILLI\System\Uri::$userInfo
- */
- const USER_INFO = 2;
- /**
- * @const int ILLI\System\Uri::$host
- */
- const HOST = 4;
- /**
- * @const int ILLI\System\Uri::$port
- */
- const PORT = 8;
- /**
- * @const int ILLI\System\Uri::$localPath
- */
- const LOCAL_PATH = 16;
- /**
- * @const int ILLI\System\Uri::$query
- */
- const QUERY = 32;
- /**
- * @const int ILLI\System\Uri::$fragment
- */
- const FRAGMENT = 64;
- /**
- * @const int ILLI\System\Uri::$port || default port || -1
- */
- const STRONG_PORT = 128;
- /**
- * @const int normalized ILLI\System\Uri::$host
- */
- const NORMALIZED_HOST = 256;
- /**
- * @const int ILLI\System\eUriComponent::SCHEME
- * | ILLI\System\eUriComponent::USER_INFO
- * | ILLI\System\eUriComponent::HOST
- * | ILLI\System\eUriComponent::PORT
- * | ILLI\System\eUriComponent::LOCAL_PATH
- * | ILLI\System\eUriComponent::QUERY
- */
- const ABSOLUTE_URL = 63;
- /**
- * @const int ILLI\System\eUriComponent::HOST
- * | ILLI\System\eUriComponent::STRONG_PORT
- */
- const HOST_AND_PORT = 132;
- /**
- * @const int ILLI\System\eUriComponent::USER_INFO
- * | ILLI\System\eUriComponent::HOST
- * | ILLI\System\eUriComponent::STRONG_PORT
- */
- const STRONG_AUTHORITY = 134;
- /**
- * @const int ILLI\System\eUriComponent::SCHEME
- * | ILLI\System\eUriComponent::HOST
- * | ILLI\System\eUriComponent::STRONG_PORT
- */
- const SCHEME_AND_SERVER = 133;
- /**
- * @const int ILLI\System\eUriComponent::SCHEME
- * | ILLI\System\eUriComponent::HOST
- * | ILLI\System\eUriComponent::PORT
- * | ILLI\System\eUriComponent::LOCAL_PATH
- * | ILLI\System\eUriComponent::QUERY
- */
- const HTTP_REQUEST_URL = 61;
- /**
- * @const int ILLI\System\eUriComponent::LOCAL_PATH
- * | ILLI\System\eUriComponent::QUERY
- */
- const PATH_AND_QUERY = 48;
- }
- /**
- * ILLI
- *
- * @category ILLI_System
- * @package ILLI
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\System;
- /**
- * ILLI Uri
- *
- * @category ILLI_System
- * @package ILLI
- * @subpackage System
- * @namespace ILLI\System
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.1
- * @version 3.0.1
- */
- CLASS Uri EXTENDS \ILLI\Core\Table IMPLEMENTS \ILLI\Core\iProviderArrayList
- {
- private $__UriComponents = NULL;
- const SCHEME_DELIMETER = '://';
- /**
- * Addressing files on local or network file systems
- *
- * Since this usually used for local files the host from RFC 1738 is often empty leading
- * to a starting triple /. RFC 3986 allows an absolute path with no host part.
- *
- * @const string rfc1738; rfc3986
- * @link http://tools.ietf.org/html/rfc1738
- * @link http://tools.ietf.org/html/rfc3986
- */
- const SCHEME_FILE = 'file';
- /**
- * File Transfer Protocol
- *
- * @const string rfc1738
- * @link http://tools.ietf.org/html/rfc1738
- */
- const SCHEME_FTP = 'ftp';
- /**
- * Gopher Protocol
- *
- * @const string rfc4266
- * @link http://tools.ietf.org/html/rfc4266
- */
- const SCHEME_GOPHER = 'gopher';
- /**
- * Hyper Text Transfer Protocol
- *
- * @const string rfc1738
- * @link http://tools.ietf.org/html/rfc1738
- */
- const SCHEME_HTTP = 'http';
- /**
- * Hyper Text Transfer Protocol SSL/TLS
- *
- * @const string rfc2817
- * @link http://tools.ietf.org/html/rfc2817
- */
- const SCHEME_HTTPS = 'https';
- /**
- * SMTP e-mail addresses and default content
- *
- * Headers are optional, but often include subject=; body=
- * can be used to pre-fill the body of the message.
- *
- * @const string rfc6068
- * @link http://tools.ietf.org/html/rfc6068
- */
- const SCHEME_MAILTO = 'mailto';
- public function __construct($uri = NULL)
- {
- $this->__UriComponents = eUriComponents::instanceGet();
- $default = [
- 'absolutePath' => '',
- 'absoluteUri' => '',
- 'authority' => '',
- 'dnsSafeHost' => '',
- 'fragment' => '',
- 'host' => '',
- 'hostNameType' => '',
- 'isAbsolute' => FALSE,
- 'isDefaultPort' => FALSE,
- 'isFile' => FALSE,
- 'isLoopBack' => FALSE,
- 'isUnc' => FALSE,
- 'isUserEscaped' => FALSE,
- 'localPath' => '',
- 'originalString' => '',
- 'pathAndQuery' => '',
- 'port' => '',
- 'query' => '',
- 'scheme' => '',
- 'segments' => [],
- 'userInfo' => new UserInfo
- ];
- parent::__construct($default);
- $self = $this;
- $this
- ->filterRegisterEventClosure(\ILLI\Core\eFilter::ARGUMENTS, 'ILLI\Core\Table::__set', function($data) use ($self)
- {
- $index = $data['index'];
- $value = $data['value'];
- switch($index):
- case 'scheme':
- $value = strtolower($value);
- break;
- case 'host':
- if(strpos($value, '/') !== false)
- {
- list($host, $self->absolutePath) = explode('/', $value, 2);
- $value = $host;
- }
- $value = strtolower($value);
- break;
- case 'absolutePath':
- $value = ($value[0] === '/') ? $value : '/'.$value;
- $value = str_replace('\\', '/', $value);
- $value = str_replace('//', '/', $value);
- break;
- case 'query':
- $value = (array) $value;
- break;
- endswitch;
- return ['index' => $index, 'value' => $value];
- });
- }
- public function __call($name, array $args = array())
- {
- $c = $this->__UriComponents;
- $c::$name();
- return $this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement