Advertisement
fruffl

Synch Props/apply Filters

Oct 12th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.26 KB | None | 0 0
  1. <?PHP
  2.     /**
  3.      * ILLI
  4.      *
  5.      * @category   ILLI_Core_Uri
  6.      * @package    ILLI
  7.      * @link       http://illi.be
  8.      * @license    http://l.illi.be
  9.      * @copyright  ILLI Conference
  10.      */
  11.     NAMESPACE ILLI\Core\Uri;
  12.     USE ILLI\Core\Virtual\Member\iField         AS iField;
  13.     USE ILLI\Core\Virtual\Member\tField         AS tField;
  14.  
  15.     /**
  16.      * ILLI Web Data URI
  17.      *
  18.      * @category   ILLI_Core_Uri
  19.      * @package    ILLI
  20.      * @subpackage Core\Uri
  21.      * @namespace  ILLI\Core\Uri
  22.      * @link       http://illi.be
  23.      * @license    http://l.illi.be
  24.      * @copyright  ILLI Conference
  25.      * @since      2.0.1
  26.      * @version    3.0.1
  27.      */
  28.     CLASS Query
  29.     {
  30.         USE tField
  31.         {
  32.             tField_template__get as PUBLIC __get;
  33.             tField_template__set as PUBLIC __set;
  34.         }
  35.        
  36.         public function __construct($__query)
  37.         {
  38.             $toArray = function($queryData)
  39.             {
  40.                 $new = [];
  41.                 if(is_string($queryData))
  42.                 {
  43.                     parse_str($queryData, $new);
  44.                 }
  45.                 else
  46.                 if(is_array($queryData))
  47.                 {
  48.                     $new = $queryData;
  49.                 }
  50.                
  51.                 kSort($new);
  52.                
  53.                 return $new;
  54.             };
  55.            
  56.             $toString   = function($string) use ($toArray)
  57.             {
  58.                 return http_build_query($toArray($string), '@IDX:', ini_get('arg_separator.output'), PHP_QUERY_RFC1738);
  59.             };
  60.            
  61.             $toEscape   = function($string) use ($toArray)
  62.             {
  63.                 return http_build_query($toArray($string), '@IDX:', ini_get('arg_separator.output'), PHP_QUERY_RFC3986);
  64.             };
  65.            
  66.             $this->tField_define
  67.             (
  68.                 'query', 'array',
  69.                 [
  70.                     iField::PROP_INIT       => $toArray($__query),
  71.                     iField::PROP_PRIVATE_SET    => FALSE,
  72.                     iField::PROP_PRIVATE_GET    => FALSE,
  73.                     iField::PROP_ON_SET     => function(array $data) use ($toArray)
  74.                     {
  75.                         $data[iField::CALLBACK_PROP_NEW] = $toArray($data[iField::CALLBACK_PROP_NEW]);
  76.                         return $data;
  77.                     },
  78.                     iField::PROP_SYNCH      =>
  79.                     [
  80.                         'string'        => $toString,
  81.                         'escaped'       => $toEscape,
  82.                     ]
  83.                 ],
  84.                 iField::DEBUG_CONTAINS
  85.                     | iField::DEBUG_ACCEPTED_TYPES
  86.                     | iField::DEBUG_INITIALIZED_AS
  87.             )->tField_define
  88.             (
  89.                 'string', 'string',
  90.                 [
  91.                     iField::PROP_INIT       => $toString($__query),
  92.                     iField::PROP_PRIVATE_SET    => FALSE,
  93.                     iField::PROP_PRIVATE_GET    => FALSE,
  94.                     iField::PROP_ON_SET     => function(array $data) use ($toString, $toArray)
  95.                     {
  96.                         $data[iField::CALLBACK_PROP_NEW] = $toString($data[iField::CALLBACK_PROP_NEW]);
  97.                         return $data;
  98.                     },
  99.                     iField::PROP_SYNCH      =>
  100.                     [
  101.                         'escaped'       => $toEscape,
  102.                         'query'         => $toArray,
  103.                     ]
  104.                 ],
  105.                 iField::DEBUG_CONTAINS
  106.                     | iField::DEBUG_ACCEPTED_TYPES
  107.                     | iField::DEBUG_INITIALIZED_AS
  108.             )->tField_define
  109.             (
  110.                 'escaped', 'string',
  111.                 [
  112.                     iField::PROP_INIT       => $toEscape($__query),
  113.                     iField::PROP_PRIVATE_SET    => FALSE,
  114.                     iField::PROP_PRIVATE_GET    => FALSE,
  115.                     iField::PROP_ON_SET     => function(array $data) use ($toEscape, $toArray)
  116.                     {
  117.                         $data[iField::CALLBACK_PROP_NEW] = $toEscape($data[iField::CALLBACK_PROP_NEW]);
  118.                         return $data;
  119.                     },
  120.                     iField::PROP_SYNCH      =>
  121.                     [
  122.                         'string'        => $toString,
  123.                         'query'         => $toArray,
  124.                     ]
  125.                 ],
  126.                 iField::DEBUG_CONTAINS
  127.                     | iField::DEBUG_ACCEPTED_TYPES
  128.                     | iField::DEBUG_INITIALIZED_AS
  129.             );
  130.         }
  131.     }
  132.  
  133.  
  134.     $u = new \ILLI\Core\Uri\Uri('ftp://bl@a:lksjjdls:k@jd@localhost:8888/gator/2/3/4/gatoZZZ?parameter1=testval&par2=val2#tab1');
  135.     var_dump($u->Query->string);
  136.     $u->Query->query = ['foo' => 'bar baz'];
  137.    
  138.     $u->Query->string = 'foo=bar&bar=baz bar';
  139.     var_dump($u->Query->string);
  140.     var_dump($u);
  141. ?>
  142. string(28) "par2=val2&parameter1=testval"
  143. string(19) "bar=baz+bar&foo=bar"
  144. object(ILLI\Core\Uri\Uri)#248 (4) {
  145.   ["__tField":protected]=>
  146.   array(1) {
  147.     ["Query"]=>
  148.     array(3) {
  149.       ["contains"]=>
  150.       &object(ILLI\Core\Uri\Query)#250 (4) {
  151.         ["__tField":protected]=>
  152.         array(3) {
  153.           ["query"]=>
  154.           array(3) {
  155.             ["contains"]=>
  156.             &array(2) {
  157.               ["bar"]=>
  158.               string(7) "baz bar"
  159.               ["foo"]=>
  160.               string(3) "bar"
  161.             }
  162.             ["init"]=>
  163.             &array(2) {
  164.               ["par2"]=>
  165.               string(4) "val2"
  166.               ["parameter1"]=>
  167.               string(7) "testval"
  168.             }
  169.             ["typeOf"]=>
  170.             &array(1) {
  171.               [0]=>
  172.               string(5) "array"
  173.             }
  174.           }
  175.           ["string"]=>
  176.           array(3) {
  177.             ["contains"]=>
  178.             &string(19) "bar=baz+bar&foo=bar"
  179.             ["init"]=>
  180.             &string(28) "par2=val2&parameter1=testval"
  181.             ["typeOf"]=>
  182.             &array(1) {
  183.               [0]=>
  184.               string(6) "string"
  185.             }
  186.           }
  187.           ["escaped"]=>
  188.           array(3) {
  189.             ["contains"]=>
  190.             &string(21) "bar=baz%20bar&foo=bar"
  191.             ["init"]=>
  192.             &string(28) "par2=val2&parameter1=testval"
  193.             ["typeOf"]=>
  194.             &array(1) {
  195.               [0]=>
  196.               string(6) "string"
  197.             }
  198.           }
  199.         }
  200.         ["__tField_LockRegistration":"ILLI\Core\Uri\Query":private]=>
  201.         bool(false)
  202.         ["__tField_LockAllFields":"ILLI\Core\Uri\Query":private]=>
  203.         bool(false)
  204.         ["__tField_Hash":"ILLI\Core\Uri\Query":private]=>
  205.         string(32) "000000000b1dab7b000000003636f1d0"
  206.       }
  207.       ["init"]=>
  208.       &object(ILLI\Core\Uri\Query)#250 (4) {
  209.         ["__tField":protected]=>
  210.         array(3) {
  211.           ["query"]=>
  212.           array(3) {
  213.             ["contains"]=>
  214.             &array(2) {
  215.               ["bar"]=>
  216.               string(7) "baz bar"
  217.               ["foo"]=>
  218.               string(3) "bar"
  219.             }
  220.             ["init"]=>
  221.             &array(2) {
  222.               ["par2"]=>
  223.               string(4) "val2"
  224.               ["parameter1"]=>
  225.               string(7) "testval"
  226.             }
  227.             ["typeOf"]=>
  228.             &array(1) {
  229.               [0]=>
  230.               string(5) "array"
  231.             }
  232.           }
  233.           ["string"]=>
  234.           array(3) {
  235.             ["contains"]=>
  236.             &string(19) "bar=baz+bar&foo=bar"
  237.             ["init"]=>
  238.             &string(28) "par2=val2&parameter1=testval"
  239.             ["typeOf"]=>
  240.             &array(1) {
  241.               [0]=>
  242.               string(6) "string"
  243.             }
  244.           }
  245.           ["escaped"]=>
  246.           array(3) {
  247.             ["contains"]=>
  248.             &string(21) "bar=baz%20bar&foo=bar"
  249.             ["init"]=>
  250.             &string(28) "par2=val2&parameter1=testval"
  251.             ["typeOf"]=>
  252.             &array(1) {
  253.               [0]=>
  254.               string(6) "string"
  255.             }
  256.           }
  257.         }
  258.         ["__tField_LockRegistration":"ILLI\Core\Uri\Query":private]=>
  259.         bool(false)
  260.         ["__tField_LockAllFields":"ILLI\Core\Uri\Query":private]=>
  261.         bool(false)
  262.         ["__tField_Hash":"ILLI\Core\Uri\Query":private]=>
  263.         string(32) "000000000b1dab7b000000003636f1d0"
  264.       }
  265.       ["typeOf"]=>
  266.       &array(1) {
  267.         [0]=>
  268.         string(20) "\ILLI\Core\Uri\Query"
  269.       }
  270.     }
  271.   }
  272.   ["__tField_LockRegistration":"ILLI\Core\Uri\Uri":private]=>
  273.   bool(false)
  274.   ["__tField_LockAllFields":"ILLI\Core\Uri\Uri":private]=>
  275.   bool(false)
  276.   ["__tField_Hash":"ILLI\Core\Uri\Uri":private]=>
  277.   string(32) "000000000b1dab79000000003636f1d0"
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement