| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Handler.php - Jaxon Request Handler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * This class processes an incoming jaxon request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @package jaxon-core | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @author Jared White | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @author J. Max Wilson | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @author Joseph Woolley | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @author Steffen Konerow | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @author Thierry Feuzeu <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @copyright Copyright (c) 2008-2010 by Joseph Woolley, Steffen Konerow, Jared White  & J. Max Wilson | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @copyright 2016 Thierry Feuzeu <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @link https://github.com/jaxon-php/jaxon-core | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | namespace Jaxon\Request\Handler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Jaxon\Jaxon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Jaxon\Plugin\Manager as PluginManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Jaxon\Response\Manager as ResponseManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Jaxon\Request\Plugin\FileUpload; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | class Handler | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     use \Jaxon\Features\Config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * The plugin manager. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @var PluginManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     private $xPluginManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * The response manager. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @var ResponseManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     private $xResponseManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * The arguments handler. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @var \Jaxon\Request\Handler\Argument | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     private $xArgumentManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * The callbacks to run while processing the request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @var \Jaxon\Request\Handler\Callback | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     private $xCallbackManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * The request plugin that is able to process the current request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @var \Jaxon\Plugin\Request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     private $xTargetRequestPlugin = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * The file upload request plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @var FileUpload | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     private $xUploadRequestPlugin = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * The constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @param PluginManager         $xPluginManager | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @param ResponseManager       $xResponseManager | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @param FileUpload            $xUploadRequestPlugin | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     public function __construct(PluginManager $xPluginManager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         ResponseManager $xResponseManager, FileUpload $xUploadRequestPlugin) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $this->xPluginManager = $xPluginManager; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $this->xResponseManager = $xResponseManager; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $this->xUploadRequestPlugin = $xUploadRequestPlugin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $this->xArgumentManager = new Argument(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $this->xCallbackManager = new Callback(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * Return the method that was used to send the arguments from the client | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * The method is one of: Argument::METHOD_UNKNOWN, Argument::METHOD_GET, Argument::METHOD_POST. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @return integer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     public function getRequestMethod() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         return $this->xArgumentManager->getRequestMethod(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * Return true if the current request method is GET | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     public function requestMethodIsGet() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         return ($this->xArgumentManager->getRequestMethod() == Argument::METHOD_GET); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * Return the array of arguments that were extracted and parsed from the GET or POST data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     public function processArguments() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         return $this->xArgumentManager->process(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * Get the callback handler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * @return Callback | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     public function getCallbackManager() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         return $this->xCallbackManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     /** | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * This is the pre-request processing callback passed to the Jaxon library. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      * @param  boolean  &$bEndRequest if set to true, the request processing is interrupted. | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |      * @return Jaxon\Response\Response  the Jaxon response | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 142 |  |  |      */ | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 143 |  | View Code Duplication |     public function onBefore(&$bEndRequest) | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |         // Call the user defined callback | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |         if(($xCallback = $this->xCallbackManager->before())) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |         { | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |             call_user_func_array($xCallback, [$this->xTargetRequestPlugin->getTarget(), &$bEndRequest]); | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     /** | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * This is the post-request processing callback passed to the Jaxon library. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      * @return Jaxon\Response\Response  the Jaxon response | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 157 |  | View Code Duplication |     public function onAfter($bEndRequest) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         if(($xCallback = $this->xCallbackManager->after())) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             call_user_func_array($xCallback, [$this->xTargetRequestPlugin->getTarget(), $bEndRequest]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     /** | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      * This callback is called whenever an invalid request is processed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * @return Jaxon\Response\Response  the Jaxon response | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     public function onInvalid($sMessage) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |         if(($xCallback = $this->xCallbackManager->invalid())) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |             call_user_func_array($xCallback, [$sMessage]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     /** | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * This callback is called whenever an invalid request is processed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * @return Jaxon\Response\Response  the Jaxon response | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |     public function onError(Exception $xException) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         if(($xCallback = $this->xCallbackManager->error())) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |             call_user_func_array($xCallback, [$xException]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |             throw $xException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |      * Check if the current request can be processed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |      * Calls each of the request plugins and determines if the current request can be processed by one of them. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     public function canProcessRequest() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         // Return true if the request plugin was already found | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         if(($this->xTargetRequestPlugin)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         // Find a plugin to process the request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         foreach($this->xPluginManager->getRequestPlugins() as $xPlugin) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |             if($xPlugin->getName() != Jaxon::FILE_UPLOAD && $xPlugin->canProcessRequest()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |                 $this->xTargetRequestPlugin = $xPlugin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |                 return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         // If no other plugin than the upload plugin can process the request, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |         // then it is a HTTP (not ajax) upload request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         $this->xUploadRequestPlugin->noRequestPluginFound(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         return $this->xUploadRequestPlugin->canProcessRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |      * Process the current request and handle errors and exceptions. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |     private function _processRequest() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         try | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |             // Process uploaded files | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |             $this->xUploadRequestPlugin->processRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |             // Process the request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |             if(($this->xTargetRequestPlugin)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |                 $this->xTargetRequestPlugin->processRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |         catch(Exception $e) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |             // An exception was thrown while processing the request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |             // The request missed the corresponding handler function, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |             // or an error occurred while attempting to execute the handler. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |             $this->xResponseManager->error($e->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |             if($e instanceof \Jaxon\Exception\Error) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |                 $this->onInvalid($e->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |             else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |                 $this->onError($e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |      * Clean output buffers. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     private function _cleanOutputBuffers() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |         $er = error_reporting(0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         while(ob_get_level() > 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |             ob_end_clean(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |         error_reporting($er); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |      * Process the current request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |      * Calls each of the request plugins to request that they process the current request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |      * If any plugin processes the request, it will return true. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |     public function processRequest() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |         // Check if there is a plugin to process this request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |         if(!$this->canProcessRequest()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |         $bEndRequest = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |         // Handle before processing event | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |         if(($this->xTargetRequestPlugin)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |             $this->onBefore($bEndRequest); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |         if(!$bEndRequest) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |             $this->_processRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |         // Clean the processing buffer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |         if(($this->getOption('core.process.clean'))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |             $this->_cleanOutputBuffers(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |         if(($this->xTargetRequestPlugin)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |             // Handle after processing event | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |             $this->onAfter($bEndRequest); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |         // If the called function returned no response, take the the global response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |         if(!$this->xResponseManager->getResponse()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |             $this->xResponseManager->append(jaxon()->getResponse()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |         $this->xResponseManager->printDebug(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 327 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 328 |  |  |  |