Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
Index: controller/AgaviController.class.php =================================================================== --- controller/AgaviController.class.php (revision 2101) +++ controller/AgaviController.class.php (working copy) @@ -70,6 +70,11 @@ protected $outputTypes = array(); /** + * @var array Ref to the request data object from the request. + */ + private $requestData = null; + + /** * Indicates whether or not a module has a specific action. * * @param string A module name. @@ -134,6 +139,7 @@ $container->initialize($this->context, $ecfi['parameters']); $container->setModuleName($moduleName); $container->setActionName($actionName); + $container->setRequestData($this->requestData); if($arguments !== null) { $container->setArguments($arguments); } @@ -479,6 +485,8 @@ */ public function startup() { + // grab a pointer to the request data + $this->requestData = $this->context->getRequest()->getRequestData(); } /** Index: controller/AgaviExecutionContainer.class.php =================================================================== --- controller/AgaviExecutionContainer.class.php (revision 2101) +++ controller/AgaviExecutionContainer.class.php (working copy) @@ -43,7 +43,7 @@ /** * @var AgaviRequestDataHolder A request data holder with request info. */ - protected $requestData = null; + private $requestData = null; /** * @var AgaviRequestDataHolder A request data holder with arguments. @@ -296,7 +296,8 @@ // run the execution filter, without a proper chain $controller->getFilter('execution')->execute(new AgaviFilterChain(), $this); } else { - $this->requestData = clone $request->getRequestData(); + // mmmh I smell awesomeness... clone the RD JIT, yay, that's the spirit + $this->requestData = clone $this->requestData; if($this->arguments !== null) { $this->requestData->merge($this->arguments); @@ -400,12 +401,25 @@ * @author David Zülke <dz@bitxtender.com> * @since 0.11.0 */ - public function getRequestData() + public final function getRequestData() { return $this->requestData; } /** + * Set this container's request data holder instance. + * + * @param AgaviRequestDataHolder The request data holder. + * + * @author David Zülke <dz@bitxtender.com> + * @since 0.11.0 + */ + public final function setRequestData(AgaviRequestDataHolder $rd) + { + $this->requestData = $rd; + } + + /** * Get this container's request data holder instance for additional arguments. * * @return AgaviRequestDataHolder The additional arguments. Index: controller/AgaviSoapController.class.php =================================================================== --- controller/AgaviSoapController.class.php (revision 2101) +++ controller/AgaviSoapController.class.php (working copy) @@ -99,6 +99,8 @@ */ public function startup() { + parent::startup(); + // user-supplied "wsdl" and "options" parameters $wsdl = $this->getParameter('wsdl'); if(!$wsdl) { Index: request/AgaviXmlrpcepiphpRequest.class.php =================================================================== --- request/AgaviXmlrpcepiphpRequest.class.php (revision 2101) +++ request/AgaviXmlrpcepiphpRequest.class.php (working copy) @@ -54,20 +54,19 @@ } $rdhc = $this->getParameter('request_data_holder_class'); - $this->requestData = new $rdhc(array( - constant("$rdhc::SOURCE_PARAMETERS") => array(), + $rd = new $rdhc(array( + constant("$rdhc::SOURCE_PARAMETERS") => (array)$decoded, )); - - $this->requestData->setParameters((array)$decoded); - $split = explode(':', $this->invokedMethod); if(count($split) == 2) { - $this->requestData->setParameter($this->getParameter('module_accessor'), $split[0]); - $this->requestData->setParameter($this->getParameter('action_accessor'), $split[1]); + $rd->setParameter($this->getParameter('module_accessor'), $split[0]); + $rd->setParameter($this->getParameter('action_accessor'), $split[1]); } else { - $this->requestData->setParameter($this->getParameter('action_accessor'), $this->invokedMethod); + $rd->setParameter($this->getParameter('action_accessor'), $this->invokedMethod); } + + $this->setRequestData($rd); } } Index: request/AgaviWebRequest.class.php =================================================================== --- request/AgaviWebRequest.class.php (revision 2101) +++ request/AgaviWebRequest.class.php (working copy) @@ -378,12 +378,12 @@ } $rdhc = $this->getParameter('request_data_holder_class'); - $this->requestData = new $rdhc(array( + $this->setRequestData(new $rdhc(array( constant("$rdhc::SOURCE_PARAMETERS") => array_merge($_GET, $_POST), constant("$rdhc::SOURCE_COOKIES") => $_COOKIE, constant("$rdhc::SOURCE_FILES") => $_FILES, constant("$rdhc::SOURCE_HEADERS") => $headers, - )); + ))); } /** Index: request/AgaviRequest.class.php =================================================================== --- request/AgaviRequest.class.php (revision 2101) +++ request/AgaviRequest.class.php (working copy) @@ -54,13 +54,12 @@ /** * @var AgaviRequestDataHolder The request data holder instance. */ - protected $requestData = null; + private $requestData = null; /** - * @var bool A boolean value indicating whether or not the request is - * locked. + * @var string The key used to lock the request, or null if no lock set */ - private $locked = false; + private $key = null; /** * Retrieve the current application context. @@ -173,21 +172,34 @@ } /** + * Set the data holder instance of this request. + * + * @param AgaviRequestDataHolder The request data holder. + * + * @author David Zülke <dz@bitxtender.com> + * @author Dominik del Bondio <ddb@bitxtender.com> + * @since 0.11.0 + */ + final protected function setRequestData(AgaviRequestDataHolder $rd) + { + if(!$this->isLocked()) { + $this->requestData = $rd; + } + } + + /** * Get the data holder instance of this request. * * @return AgaviRequestDataHolder The request data holder. * + * @author David Zülke <dz@bitxtender.com> * @author Dominik del Bondio <ddb@bitxtender.com> * @since 0.11.0 */ - public function getRequestData() + final public function getRequestData() { - if($this->locked) { - if($this->getParameter('request_lock_barf', true)) { - throw new AgaviException("Access to request data is locked during Action and View execution, please use the local request data holder passed to your Action's or View's execute*() method to access request data.\nYou may disable the throwing of this exception by setting the 'request_lock_barf' parameter to false. Sorry for the name of that one, 'throw_exception_when_trying_to_access_request_data_while_request_is_locked' is just a little too long."); - } else { - return new AgaviRequestDataHolder(); - } + if($this->isLocked()) { + throw new AgaviException("Access to request data is locked during Action and View execution, please use the local request data holder passed to your Action's or View's execute*() method to access request data."); } return $this->requestData; } @@ -222,7 +234,7 @@ */ public final function isLocked() { - return $this->locked; + return $this->key !== null; } /** @@ -239,13 +251,12 @@ */ public final function toggleLock($key = null) { - static $keys = array(); - if(!$this->locked && $key === null) { + if(!$this->isLocked() && $key === null) { $this->locked = true; - return $this->keys[$this->context->getName()] = uniqid(); - } elseif($this->locked) { - if(isset($this->keys[$this->context->getName()]) && $this->keys[$this->context->getName()] == $key) { - $this->locked = false; + return $this->key = uniqid(); + } elseif($this->isLocked()) { + if($this->key === $key) { + $this->key = null; return true; } return false; Index: request/AgaviSoapRequest.class.php =================================================================== --- request/AgaviSoapRequest.class.php (revision 2101) +++ request/AgaviSoapRequest.class.php (working copy) @@ -62,10 +62,10 @@ parent::initialize($context, $parameters); $rdhc = $this->getParameter('request_data_holder_class'); - $this->requestData = new $rdhc(array( + $this->setRequestData(new $rdhc(array( constant("$rdhc::SOURCE_PARAMETERS") => array(), constant("$rdhc::SOURCE_HEADERS") => array(), - )); + ))); $this->setMethod($this->getParameter('default_method', 'read')); }
This paste will be private.
From the Design Piracy series on my blog: