Advertisement
fruffl

Response Class

Oct 13th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.61 KB | None | 0 0
  1. <?PHP
  2.     /**
  3.      * ILLI
  4.      *
  5.      * @category   ILLI_Core_Web
  6.      * @package    ILLI
  7.      * @link       http://illi.be
  8.      * @license    http://l.illi.be
  9.      * @copyright  ILLI Conference
  10.      */
  11.     NAMESPACE ILLI\Core\Web;
  12.     USE ILLI\Core\Virtual\Member\iField             AS iField;
  13.     USE ILLI\Core\Virtual\Member\tField             AS tField;
  14.     USE ILLI\Core\Web\Data\Response\Headers         AS Headers;
  15.     USE \ILLI\Core\Web\Data\Response\RedirectAfterPost  AS RedirectAfterPost;
  16.  
  17.     /**
  18.      * ILLI Web Response
  19.      *
  20.      * @category   ILLI_Core_Web
  21.      * @package    ILLI
  22.      * @subpackage Core\Web
  23.      * @namespace  ILLI\Core\Web
  24.      * @link       http://illi.be
  25.      * @license    http://l.illi.be
  26.      * @copyright  ILLI Conference
  27.      * @since      2.0.1
  28.      * @version    3.0.1
  29.      */
  30.     CLASS Response EXTENDS aWeb
  31.     {
  32.         USE tField
  33.         {
  34.             tField_template__get as PUBLIC __get;
  35.             tField_template__set as PUBLIC __set;
  36.         }
  37.        
  38.         public function __construct(array $agents = [])
  39.         {
  40.             $this->tField_define
  41.             (
  42.                 'Headers', 'ILLI\Core\Web\Data\Response\Headers',
  43.                 [
  44.                     iField::PROP_INIT       => new Headers,
  45.                     iField::PROP_PRIVATE_SET    => FALSE,
  46.                     iField::PROP_PRIVATE_GET    => FALSE,
  47.                     iField::PROP_ON_GET     => function(array $data)
  48.                     {
  49.                         $header = $data[iField::CALLBACK_PROP_CONTAINS];
  50.                        
  51.                         $header->offsetSet('Content-Type', $this->tField_get('contentType'));
  52.                        
  53.                         if(FALSE === $this->tField_get('isCacheEnabled'))
  54.                         {
  55.                             $header->offsetSet('Pragma', 'no-cache');
  56.                             $header->offsetSet('Expires', '1');
  57.                             $header->offsetSet('Cache-Control',
  58.                             [
  59.                                         'no-store, no-cache, must-revalidate',
  60.                                         'post-check=0, pre-check=0'
  61.                                     ]);
  62.                         }
  63.                        
  64.                         if(TRUE === $this->tField_get('isRedirect'))
  65.                         {
  66.                             $header->offsetSet('Location', $this->tField_get('Redirect')->Uri->originalString);
  67.                         }
  68.                        
  69.                         $data[iField::CALLBACK_PROP_CONTAINS] = $header;
  70.                         return $data;
  71.                     }
  72.                 ],
  73.                 iField::DEBUG_CONTAINS
  74.             )
  75.             ->tField_define
  76.             (
  77.                 'httpVersion', 'float',
  78.                 [
  79.                     iField::PROP_INIT       => 1.1,
  80.                     iField::PROP_PRIVATE_SET    => TRUE,
  81.                     iField::PROP_PRIVATE_GET    => TRUE,
  82.                     iField::PROP_ON_SET     => function(array $data)
  83.                     {
  84.                         $version = $data[iField::CALLBACK_PROP_NEW];
  85.                         if($version !== 1.1
  86.                         && $version !== 1.0)
  87.                             throw new \Exception('HTTP version '.$version.' not recognized.');
  88.                            
  89.                         return $data;
  90.                     }
  91.                 ],
  92.                 iField::DEBUG_CONTAINS
  93.             )
  94.             ->tField_define
  95.             (
  96.                 'contentType', 'string',
  97.                 [
  98.                     iField::PROP_INIT       => 'text/html',
  99.                     iField::PROP_PRIVATE_SET    => FALSE,
  100.                     iField::PROP_PRIVATE_GET    => FALSE,
  101.                     iField::PROP_ON_SET     => function(array $data)
  102.                     {
  103.                         $value = $data[iField::CALLBACK_PROP_NEW];
  104.                                 $this->tField_get('Headers')->offsetSet('Content-Type', $value);
  105.                            
  106.                         return $data;
  107.                     }
  108.                 ],
  109.                 iField::DEBUG_CONTAINS
  110.             )
  111.             ->tField_define
  112.             (
  113.                 'isCacheEnabled', 'boolean',
  114.                 [
  115.                     iField::PROP_INIT       => TRUE,
  116.                     iField::PROP_PRIVATE_SET    => FALSE,
  117.                     iField::PROP_PRIVATE_GET    => FALSE
  118.                 ],
  119.                 iField::DEBUG_CONTAINS
  120.             )
  121.             ->tField_define
  122.             (
  123.                 'isRedirect', 'boolean',
  124.                 [
  125.                     iField::PROP_INIT       => FALSE,
  126.                     iField::PROP_PRIVATE_SET    => FALSE,
  127.                     iField::PROP_PRIVATE_GET    => FALSE
  128.                 ],
  129.                 iField::DEBUG_CONTAINS
  130.             )
  131.             ->tField_define
  132.             (
  133.                 'Redirect', '\ILLI\Core\Web\Data\Response\Redirect',
  134.                 [
  135.                     iField::PROP_INIT       => NULL,
  136.                     iField::PROP_PRIVATE_SET    => FALSE,
  137.                     iField::PROP_PRIVATE_GET    => FALSE,
  138.                     iField::PROP_SYNCH      =>
  139.                     [
  140.                         'isRedirect'        => function(Redirect $__Redirect)
  141.                         {
  142.                             return TRUE;
  143.                         },
  144.                     ]
  145.                 ],
  146.                 iField::DEBUG_CONTAINS
  147.             )
  148.             ->tField_define
  149.             (
  150.                 'RedirectAfterPost', '\ILLI\Core\Web\Data\Response\RedirectAfterPost',
  151.                 [
  152.                     iField::PROP_INIT       => NULL,
  153.                     iField::PROP_PRIVATE_SET    => FALSE,
  154.                     iField::PROP_PRIVATE_GET    => FALSE,
  155.                     iField::PROP_SYNCH      =>
  156.                     [
  157.                         'Redirect'      => function(RedirectAfterPost $__RedirectAfterPost)
  158.                         {
  159.                             return $__RedirectAfterPost;
  160.                         },
  161.                         'isCacheEnabled'    => function(RedirectAfterPost $__RedirectAfterPost)
  162.                         {
  163.                             return FALSE;
  164.                         },
  165.                         'isRedirect'        => function(RedirectAfterPost $__RedirectAfterPost)
  166.                         {
  167.                             return TRUE;
  168.                         }
  169.                     ]
  170.                 ],
  171.                 iField::DEBUG_CONTAINS
  172.             );
  173.         }
  174.     }
  175.  
  176.  
  177. ?>
  178.  
  179. object(ILLI\Core\Web\Response)#15 (4) {
  180.   ["__tField":protected]=>
  181.   array(7) {
  182.     ["Headers"]=>
  183.     array(1) {
  184.       ["contains"]=>
  185.       &object(ILLI\Core\Web\Data\Response\Headers)#24 (7) {
  186.         ["__flag":protected]=>
  187.         int(34)
  188.         ["__data":protected]=>
  189.         array(5) {
  190.           ["Content-Type"]=>
  191.           string(9) "text/html"
  192.           ["Pragma"]=>
  193.           string(8) "no-cache"
  194.           ["Expires"]=>
  195.           string(1) "1"
  196.           ["Cache-Control"]=>
  197.           array(2) {
  198.             [0]=>
  199.             string(35) "no-store, no-cache, must-revalidate"
  200.             [1]=>
  201.             string(25) "post-check=0, pre-check=0"
  202.           }
  203.           ["Location"]=>
  204.           string(16) "http://localhost"
  205.         }
  206.         ["__tCollectionField_flag":"ILLI\Core\Data\FieldCollection":private]=>
  207.         int(34)
  208.         ["__tField":protected]=>
  209.         array(0) {
  210.         }
  211.         ["__tField_LockRegistration":"ILLI\Core\Data\FieldCollection":private]=>
  212.         bool(false)
  213.         ["__tField_LockAllFields":"ILLI\Core\Data\FieldCollection":private]=>
  214.         bool(false)
  215.         ["__tField_Hash":"ILLI\Core\Data\FieldCollection":private]=>
  216.         string(32) "0000000068284284000000003f42da20"
  217.       }
  218.     }
  219.     ["httpVersion"]=>
  220.     array(1) {
  221.       ["contains"]=>
  222.       &float(1.1)
  223.     }
  224.     ["contentType"]=>
  225.     array(1) {
  226.       ["contains"]=>
  227.       &string(9) "text/html"
  228.     }
  229.     ["isCacheEnabled"]=>
  230.     array(1) {
  231.       ["contains"]=>
  232.       &bool(false)
  233.     }
  234.     ["isRedirect"]=>
  235.     array(1) {
  236.       ["contains"]=>
  237.       &bool(true)
  238.     }
  239.     ["Redirect"]=>
  240.     array(1) {
  241.       ["contains"]=>
  242.       &object(ILLI\Core\Web\Data\Response\RedirectAfterPost)#46 (4) {
  243.         ["__tField":protected]=>
  244.         array(3) {
  245.           ["Uri"]=>
  246.           array(1) {
  247.             ["contains"]=>
  248.             &object(ILLI\Core\Uri\Uri)#49 (4) {
  249.               ["__tField":protected]=>
  250.               array(4) {
  251.                 ["originalString"]=>
  252.                 array(1) {
  253.                   ["contains"]=>
  254.                   &string(16) "http://localhost"
  255.                 }
  256.                 ["Query"]=>
  257.                 array(1) {
  258.                   ["contains"]=>
  259.                   &object(ILLI\Core\Uri\Query)#53 (4) {
  260.                     ["__tField":protected]=>
  261.                     array(3) {
  262.                       ["query"]=>
  263.                       array(1) {
  264.                         ["contains"]=>
  265.                         &array(0) {
  266.                         }
  267.                       }
  268.                       ["string"]=>
  269.                       array(1) {
  270.                         ["contains"]=>
  271.                         &string(0) ""
  272.                       }
  273.                       ["escaped"]=>
  274.                       array(1) {
  275.                         ["contains"]=>
  276.                         &string(0) ""
  277.                       }
  278.                     }
  279.                     ["__tField_LockRegistration":"ILLI\Core\Uri\Query":private]=>
  280.                     bool(false)
  281.                     ["__tField_LockAllFields":"ILLI\Core\Uri\Query":private]=>
  282.                     bool(false)
  283.                     ["__tField_Hash":"ILLI\Core\Uri\Query":private]=>
  284.                     string(32) "00000000682842a9000000003f42da20"
  285.                   }
  286.                 }
  287.                 ["Authority"]=>
  288.                 array(1) {
  289.                   ["contains"]=>
  290.                   &object(ILLI\Core\Uri\Authority)#66 (4) {
  291.                     ["__tField":protected]=>
  292.                     array(3) {
  293.                       ["username"]=>
  294.                       array(1) {
  295.                         ["contains"]=>
  296.                         &string(0) ""
  297.                       }
  298.                       ["password"]=>
  299.                       array(1) {
  300.                         ["contains"]=>
  301.                         &string(0) ""
  302.                       }
  303.                       ["passport"]=>
  304.                       array(1) {
  305.                         ["contains"]=>
  306.                         &string(1) "1"
  307.                       }
  308.                     }
  309.                     ["__tField_LockRegistration":"ILLI\Core\Uri\Authority":private]=>
  310.                     bool(false)
  311.                     ["__tField_LockAllFields":"ILLI\Core\Uri\Authority":private]=>
  312.                     bool(false)
  313.                     ["__tField_Hash":"ILLI\Core\Uri\Authority":private]=>
  314.                     string(32) "00000000682842de000000003f42da20"
  315.                   }
  316.                 }
  317.                 ["Path"]=>
  318.                 array(1) {
  319.                   ["contains"]=>
  320.                   &object(ILLI\Core\Uri\Path)#80 (4) {
  321.                     ["__tField":protected]=>
  322.                     array(4) {
  323.                       ["absolutePath"]=>
  324.                       array(1) {
  325.                         ["contains"]=>
  326.                         &string(0) ""
  327.                       }
  328.                       ["dirName"]=>
  329.                       array(1) {
  330.                         ["contains"]=>
  331.                         &string(0) ""
  332.                       }
  333.                       ["baseName"]=>
  334.                       array(1) {
  335.                         ["contains"]=>
  336.                         &string(0) ""
  337.                       }
  338.                       ["extension"]=>
  339.                       array(1) {
  340.                         ["contains"]=>
  341.                         &string(0) ""
  342.                       }
  343.                     }
  344.                     ["__tField_LockRegistration":"ILLI\Core\Uri\Path":private]=>
  345.                     bool(false)
  346.                     ["__tField_LockAllFields":"ILLI\Core\Uri\Path":private]=>
  347.                     bool(false)
  348.                     ["__tField_Hash":"ILLI\Core\Uri\Path":private]=>
  349.                     string(32) "00000000682842cc000000003f42da20"
  350.                   }
  351.                 }
  352.               }
  353.               ["__tField_LockRegistration":"ILLI\Core\Uri\Uri":private]=>
  354.               bool(false)
  355.               ["__tField_LockAllFields":"ILLI\Core\Uri\Uri":private]=>
  356.               bool(false)
  357.               ["__tField_Hash":"ILLI\Core\Uri\Uri":private]=>
  358.               string(32) "00000000682842ad000000003f42da20"
  359.             }
  360.           }
  361.           ["statusCode"]=>
  362.           array(1) {
  363.             ["contains"]=>
  364.             &int(303)
  365.           }
  366.           ["statusText"]=>
  367.           array(1) {
  368.             ["contains"]=>
  369.             &string(9) "See Other"
  370.           }
  371.         }
  372.         ["__tField_LockRegistration":"ILLI\Core\Web\Data\Response\Redirect":private]=>
  373.         bool(false)
  374.         ["__tField_LockAllFields":"ILLI\Core\Web\Data\Response\Redirect":private]=>
  375.         bool(false)
  376.         ["__tField_Hash":"ILLI\Core\Web\Data\Response\Redirect":private]=>
  377.         string(32) "00000000682842b2000000003f42da20"
  378.       }
  379.     }
  380.     ["RedirectAfterPost"]=>
  381.     array(1) {
  382.       ["contains"]=>
  383.       &object(ILLI\Core\Web\Data\Response\RedirectAfterPost)#46 (4) {
  384.         ["__tField":protected]=>
  385.         array(3) {
  386.           ["Uri"]=>
  387.           array(1) {
  388.             ["contains"]=>
  389.             &object(ILLI\Core\Uri\Uri)#49 (4) {
  390.               ["__tField":protected]=>
  391.               array(4) {
  392.                 ["originalString"]=>
  393.                 array(1) {
  394.                   ["contains"]=>
  395.                   &string(16) "http://localhost"
  396.                 }
  397.                 ["Query"]=>
  398.                 array(1) {
  399.                   ["contains"]=>
  400.                   &object(ILLI\Core\Uri\Query)#53 (4) {
  401.                     ["__tField":protected]=>
  402.                     array(3) {
  403.                       ["query"]=>
  404.                       array(1) {
  405.                         ["contains"]=>
  406.                         &array(0) {
  407.                         }
  408.                       }
  409.                       ["string"]=>
  410.                       array(1) {
  411.                         ["contains"]=>
  412.                         &string(0) ""
  413.                       }
  414.                       ["escaped"]=>
  415.                       array(1) {
  416.                         ["contains"]=>
  417.                         &string(0) ""
  418.                       }
  419.                     }
  420.                     ["__tField_LockRegistration":"ILLI\Core\Uri\Query":private]=>
  421.                     bool(false)
  422.                     ["__tField_LockAllFields":"ILLI\Core\Uri\Query":private]=>
  423.                     bool(false)
  424.                     ["__tField_Hash":"ILLI\Core\Uri\Query":private]=>
  425.                     string(32) "00000000682842a9000000003f42da20"
  426.                   }
  427.                 }
  428.                 ["Authority"]=>
  429.                 array(1) {
  430.                   ["contains"]=>
  431.                   &object(ILLI\Core\Uri\Authority)#66 (4) {
  432.                     ["__tField":protected]=>
  433.                     array(3) {
  434.                       ["username"]=>
  435.                       array(1) {
  436.                         ["contains"]=>
  437.                         &string(0) ""
  438.                       }
  439.                       ["password"]=>
  440.                       array(1) {
  441.                         ["contains"]=>
  442.                         &string(0) ""
  443.                       }
  444.                       ["passport"]=>
  445.                       array(1) {
  446.                         ["contains"]=>
  447.                         &string(1) "1"
  448.                       }
  449.                     }
  450.                     ["__tField_LockRegistration":"ILLI\Core\Uri\Authority":private]=>
  451.                     bool(false)
  452.                     ["__tField_LockAllFields":"ILLI\Core\Uri\Authority":private]=>
  453.                     bool(false)
  454.                     ["__tField_Hash":"ILLI\Core\Uri\Authority":private]=>
  455.                     string(32) "00000000682842de000000003f42da20"
  456.                   }
  457.                 }
  458.                 ["Path"]=>
  459.                 array(1) {
  460.                   ["contains"]=>
  461.                   &object(ILLI\Core\Uri\Path)#80 (4) {
  462.                     ["__tField":protected]=>
  463.                     array(4) {
  464.                       ["absolutePath"]=>
  465.                       array(1) {
  466.                         ["contains"]=>
  467.                         &string(0) ""
  468.                       }
  469.                       ["dirName"]=>
  470.                       array(1) {
  471.                         ["contains"]=>
  472.                         &string(0) ""
  473.                       }
  474.                       ["baseName"]=>
  475.                       array(1) {
  476.                         ["contains"]=>
  477.                         &string(0) ""
  478.                       }
  479.                       ["extension"]=>
  480.                       array(1) {
  481.                         ["contains"]=>
  482.                         &string(0) ""
  483.                       }
  484.                     }
  485.                     ["__tField_LockRegistration":"ILLI\Core\Uri\Path":private]=>
  486.                     bool(false)
  487.                     ["__tField_LockAllFields":"ILLI\Core\Uri\Path":private]=>
  488.                     bool(false)
  489.                     ["__tField_Hash":"ILLI\Core\Uri\Path":private]=>
  490.                     string(32) "00000000682842cc000000003f42da20"
  491.                   }
  492.                 }
  493.               }
  494.               ["__tField_LockRegistration":"ILLI\Core\Uri\Uri":private]=>
  495.               bool(false)
  496.               ["__tField_LockAllFields":"ILLI\Core\Uri\Uri":private]=>
  497.               bool(false)
  498.               ["__tField_Hash":"ILLI\Core\Uri\Uri":private]=>
  499.               string(32) "00000000682842ad000000003f42da20"
  500.             }
  501.           }
  502.           ["statusCode"]=>
  503.           array(1) {
  504.             ["contains"]=>
  505.             &int(303)
  506.           }
  507.           ["statusText"]=>
  508.           array(1) {
  509.             ["contains"]=>
  510.             &string(9) "See Other"
  511.           }
  512.         }
  513.         ["__tField_LockRegistration":"ILLI\Core\Web\Data\Response\Redirect":private]=>
  514.         bool(false)
  515.         ["__tField_LockAllFields":"ILLI\Core\Web\Data\Response\Redirect":private]=>
  516.         bool(false)
  517.         ["__tField_Hash":"ILLI\Core\Web\Data\Response\Redirect":private]=>
  518.         string(32) "00000000682842b2000000003f42da20"
  519.       }
  520.     }
  521.   }
  522.   ["__tField_LockRegistration":"ILLI\Core\Web\Response":private]=>
  523.   bool(false)
  524.   ["__tField_LockAllFields":"ILLI\Core\Web\Response":private]=>
  525.   bool(false)
  526.   ["__tField_Hash":"ILLI\Core\Web\Response":private]=>
  527.   string(32) "0000000068284293000000003f42da20"
  528. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement