Ejemplo n.º 1
0
 /**
  * Class constructor
  *
  *
  * @param Zend_Controller_Request_Abstract $request
  * @param Zend_Controller_Response_Abstract $response
  * @param array $invokeArgs Any additional invocation arguments
  * @return void
  */
 public function __construct(\Zend_Controller_Request_Abstract $request, \Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
 {
     if ($request->isXmlHttpRequest()) {
         $response->setHeader('content-type', 'application/x-www-form-urlencoded; charset=iso-8859-1', true);
     }
     parent::__construct($request, $response, $invokeArgs);
 }
Ejemplo n.º 2
0
 /**
  * @param \Zend_Controller_Response_Abstract $response
  * @return \Zend\Http\Headers
  */
 protected function getHeadersFromResponse(\Zend_Controller_Response_Abstract $response)
 {
     $headers = new HttpHeaders();
     foreach ($response->getRawHeaders() as $header) {
         $headers->addHeaderLine($header);
     }
     foreach ($response->getHeaders() as $header) {
         $headers->addHeaderLine($header['name'], $header['value']);
     }
     return $headers;
 }
Ejemplo n.º 3
0
 /**
  * Format up the ZF1 response headers into Symfony\Component\BrowserKit\Response headers format.
  *
  * @param \Zend_Controller_Response_Abstract $response The ZF1 Response Object.
  * @return array the clean key/value headers
  */
 private function formatResponseHeaders(\Zend_Controller_Response_Abstract $response)
 {
     $headers = array();
     foreach ($response->getHeaders() as $header) {
         $name = $header['name'];
         if (array_key_exists($name, $headers)) {
             if ($header['replace']) {
                 $headers[$name] = $header['value'];
             }
         } else {
             $headers[$name] = $header['value'];
         }
     }
     return $headers;
 }
Ejemplo n.º 4
0
    /**
     * Retrieve rendered contents of a controller action
     *
     * If the action results in a forward or redirect, returns empty string.
     *
     * @param  string $action
     * @param  string $controller
     * @param  string $module Defaults to default module
     * @param  array $params
     * @return string
     */
    public function action($action, $controller, $module = null, array $params = array())
    {
        $this->resetObjects();
        if (null === $module) {
            $module = $this->defaultModule;
        }

        // clone the view object to prevent over-writing of view variables
        $viewRendererObj = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        Zend_Controller_Action_HelperBroker::addHelper(clone $viewRendererObj);

        $this->request->setParams($params)
                      ->setModuleName($module)
                      ->setControllerName($controller)
                      ->setActionName($action)
                      ->setDispatched(true);

        $this->dispatcher->dispatch($this->request, $this->response);

        // reset the viewRenderer object to it's original state
        Zend_Controller_Action_HelperBroker::addHelper($viewRendererObj);


        if (!$this->request->isDispatched()
            || $this->response->isRedirect())
        {
            // forwards and redirects render nothing
            return '';
        }

        $return = $this->response->getBody();
        $this->resetObjects();
        return $return;
    }
Ejemplo n.º 5
0
 public function run(Zend_Controller_Response_Abstract $response = null)
 {
     $args = array($this);
     $this->runCallback(self::CB_BEFORE_RUN, $args);
     if ($response === null) {
         $response = new Zend_Controller_Response_Http();
     }
     $this->response = $response;
     $action = $this->getCurrentAction();
     $this->request->setActionName($action);
     ob_start();
     $this->actionRun($action);
     if ($this->response->isRedirect() && $this->completeRequest->isXmlHttpRequest()) {
         $url = null;
         foreach ($response->getHeaders() as $header) {
             if ($header['name'] == 'Location') {
                 $url = $header['value'];
             }
         }
         $code = $response->getHttpResponseCode();
         // change request to ajax response
         $response->clearAllHeaders();
         $response->clearBody();
         $response->setHttpResponseCode(200);
         $response->setHeader("Content-Type", "application/json; charset=UTF-8", true);
         $response->setBody(Am_Controller::getJson(array('ngrid-redirect' => $url, 'status' => $code)));
         //throw new Am_Exception_Redirect($url);
     } else {
         $response->appendBody(ob_get_clean());
     }
     unset($this->response);
     return $response;
 }
Ejemplo n.º 6
0
 public function testDisplay()
 {
     $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 with FirePHP/1.6';
     $this->_response->expects($this->atLeastOnce())->method('sendHeaders');
     $this->_object->display();
     $actualHeaders = $this->_response->getHeaders();
     $this->assertNotEmpty($actualHeaders);
     $actualProtocol = false;
     $actualProfilerData = false;
     foreach ($actualHeaders as $oneHeader) {
         $headerName = $oneHeader['name'];
         $headerValue = $oneHeader['value'];
         if (!$actualProtocol && $headerName == 'X-Wf-Protocol-1') {
             $actualProtocol = $headerValue;
         }
         if (!$actualProfilerData && $headerName == 'X-Wf-1-1-1-1') {
             $actualProfilerData = $headerValue;
         }
     }
     $this->assertContains('Protocol/JsonStream', $actualProtocol);
     $this->assertContains('"Type":"TABLE","Label":"Code Profiler Title"', $actualProfilerData);
     $this->assertContains('[' . '["Timer Id","Time","Avg","Cnt","Emalloc","RealMem"],' . '["some_root_timer","0.080000","0.040000","2","51,000,000","50,000,000"],' . '[". some_nested_timer","0.080000","0.026667","3","42,000,000","40,000,000"],' . '[". . some_deeply_nested_timer","0.030000","0.010000","3","13,000,000","10,000,000"],' . '["one_more_root_timer","0.010000","0.010000","1","23,456,789","12,345,678"]]', $actualProfilerData);
 }
Ejemplo n.º 7
0
 /**
  * Set the neccessary headers for forcing the download dialog
  *
  * @param String $bytes The bytes that are to be downloaded
  * @param String $filename The filename of the downloaded file
  * @param Zend_Controller_Response_Abstract $response The response object
  * @return Void
  */
 protected function _setHeaders($bytes, $filename, Zend_Controller_Response_Abstract $response)
 {
     // fix for IE catching or PHP bug issue
     $response->setHeader('Pragma', 'public');
     // set expiration time
     $response->setHeader('Expires', '0');
     // browser must download file from server instead of cache
     $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
     // force download dialog
     $response->setHeader('Content-Type', 'application/octet-stream');
     // use the Content-Disposition header to supply a recommended filename and
     // force the browser to display the save dialog.
     $response->setHeader('Content-Disposition', 'attachment; filename="' . basename($filename) . '"');
     /*
     The Content-transfer-encoding header should be binary, since the file will be read
     directly from the disk and the raw bytes passed to the downloading computer.
     The Content-length header is useful to set for downloads. The browser will be able to
     show a progress meter as a file downloads. The content-length can be determined by
     filesize function returns the size of a file.
     */
     $response->setHeader('Content-Transfer-Encoding', 'binary');
     $response->setHeader('Content-Length', strlen($bytes));
 }
 /**
  * Test for Mage_Adminhtml_Catalog_ProductController::quickCreateAction
  */
 public function testQuickCreateActionWithDangerRequest()
 {
     $data = array('entity_id' => 234);
     $this->_request->expects($this->any())->method('getParam')->will($this->returnValue($data));
     $typeInstance = $this->getMockBuilder('Mage_Catalog_Model_Product_Type')->setMethods(array('getConfigurableAttributes', 'getEditableAttributes'))->getMock();
     $typeInstance->expects($this->any())->method('getEditableAttributes')->will($this->returnValue(array()));
     $typeInstance->expects($this->any())->method('getConfigurableAttributes')->will($this->returnValue(array()));
     $productMock = $this->getMockBuilder('Mage_Catalog_Model_Product')->setMethods(array('getIdFieldName', 'save', 'getSku', 'isConfigurable', 'setStoreId', 'load', 'setTypeId', 'setAttributeSetId', 'getAttributeSetId', 'getTypeInstance', 'getWebsiteIds'))->disableOriginalConstructor()->getMock();
     $productMock->expects($this->any())->method('getIdFieldName')->will($this->returnValue('entity_id'));
     $productMock->expects($this->any())->method('isConfigurable')->will($this->returnValue(true));
     $productMock->expects($this->any())->method('setStoreId')->will($this->returnSelf());
     $productMock->expects($this->any())->method('load')->will($this->returnSelf());
     $productMock->expects($this->any())->method('setTypeId')->will($this->returnSelf());
     $productMock->expects($this->any())->method('setAttributeSetId')->will($this->returnSelf());
     $productMock->expects($this->any())->method('getTypeInstance')->will($this->returnValue($typeInstance));
     $productMock->expects($this->never())->method('save');
     $this->_response->expects($this->once())->method('setBody')->with('{"attributes":[],"error":{"message":"Unable to create product"}}');
     $helper = $this->getMockBuilder('Mage_Core_Helper_Data')->setMethods(array('jsonEncode'))->getMock();
     $helper->expects($this->once())->method('jsonEncode')->with(array('attributes' => array(), 'error' => array('message' => 'Unable to create product', 'fields' => array('sku' => ''))))->will($this->returnValue('{"attributes":[],"error":{"message":"Unable to create product"}}'));
     $this->_objectManager->expects($this->any())->method('create')->with('Mage_Catalog_Model_Product', array(), true)->will($this->returnValue($productMock));
     $this->_objectManager->expects($this->any())->method('get')->with('Mage_Core_Helper_Data', array())->will($this->returnValue($helper));
     $this->_controller->quickCreateAction();
 }
Ejemplo n.º 9
0
 /**
  * Dispatch an HTTP request to a controller/action.
  *
  * @param Zend_Controller_Request_Abstract|null $request
  * @param Zend_Controller_Response_Abstract|null $response
  * @return void|Zend_Controller_Response_Abstract Returns response object if returnResponse() is true
  */
 public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
 {
     if (!$this->getParam('noErrorHandler') && !$this->_plugins->hasPlugin('Zend_Controller_Plugin_ErrorHandler')) {
         // Register with stack index of 100
         #require_once 'Zend/Controller/Plugin/ErrorHandler.php';
         $this->_plugins->registerPlugin(new Zend_Controller_Plugin_ErrorHandler(), 100);
     }
     if (!$this->getParam('noViewRenderer') && !Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) {
         #require_once 'Zend/Controller/Action/Helper/ViewRenderer.php';
         Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-80, new Zend_Controller_Action_Helper_ViewRenderer());
     }
     /**
      * Instantiate default request object (HTTP version) if none provided
      */
     if (null !== $request) {
         $this->setRequest($request);
     } elseif (null === $request && null === ($request = $this->getRequest())) {
         #require_once 'Zend/Controller/Request/Http.php';
         $request = new Zend_Controller_Request_Http();
         $this->setRequest($request);
     }
     /**
      * Set base URL of request object, if available
      */
     if (is_callable(array($this->_request, 'setBaseUrl'))) {
         if (null !== $this->_baseUrl) {
             $this->_request->setBaseUrl($this->_baseUrl);
         }
     }
     /**
      * Instantiate default response object (HTTP version) if none provided
      */
     if (null !== $response) {
         $this->setResponse($response);
     } elseif (null === $this->_response && null === ($this->_response = $this->getResponse())) {
         #require_once 'Zend/Controller/Response/Http.php';
         $response = new Zend_Controller_Response_Http();
         $this->setResponse($response);
     }
     /**
      * Register request and response objects with plugin broker
      */
     $this->_plugins->setRequest($this->_request)->setResponse($this->_response);
     /**
      * Initialize router
      */
     $router = $this->getRouter();
     $router->setParams($this->getParams());
     /**
      * Initialize dispatcher
      */
     $dispatcher = $this->getDispatcher();
     $dispatcher->setParams($this->getParams())->setResponse($this->_response);
     // Begin dispatch
     try {
         /**
          * Route request to controller/action, if a router is provided
          */
         /**
          * Notify plugins of router startup
          */
         $this->_plugins->routeStartup($this->_request);
         $router->route($this->_request);
         /**
          * Notify plugins of router completion
          */
         $this->_plugins->routeShutdown($this->_request);
         /**
          * Notify plugins of dispatch loop startup
          */
         $this->_plugins->dispatchLoopStartup($this->_request);
         /**
          *  Attempt to dispatch the controller/action. If the $this->_request
          *  indicates that it needs to be dispatched, move to the next
          *  action in the request.
          */
         do {
             $this->_request->setDispatched(true);
             /**
              * Notify plugins of dispatch startup
              */
             $this->_plugins->preDispatch($this->_request);
             /**
              * Skip requested action if preDispatch() has reset it
              */
             if (!$this->_request->isDispatched()) {
                 continue;
             }
             /**
              * Dispatch request
              */
             try {
                 $dispatcher->dispatch($this->_request, $this->_response);
             } catch (Exception $e) {
                 if ($this->throwExceptions()) {
                     throw $e;
                 }
                 $this->_response->setException($e);
             }
             /**
              * Notify plugins of dispatch completion
              */
             $this->_plugins->postDispatch($this->_request);
         } while (!$this->_request->isDispatched());
     } catch (Exception $e) {
         if ($this->throwExceptions()) {
             throw $e;
         }
         $this->_response->setException($e);
     }
     /**
      * Notify plugins of dispatch loop completion
      */
     try {
         $this->_plugins->dispatchLoopShutdown();
     } catch (Exception $e) {
         if ($this->throwExceptions()) {
             throw $e;
         }
         $this->_response->setException($e);
     }
     if ($this->returnResponse()) {
         return $this->_response;
     }
     $this->_response->sendResponse();
 }
Ejemplo n.º 10
0
 function __exception404(Zend_Controller_Response_Abstract $response)
 {
     $response->setHttpResponseCode(404)->setBody('HTTP/1.1 404 Not Found')->setRawHeader('HTTP/1.1 404 Not Found')->sendResponse();
 }
Ejemplo n.º 11
0
 /**
  * Processes the requestStack and merges their responses into $response.
  *
  * @param Zend_Controller_Front $front
  * @param Zend_Controller_Response_Abstract $response
  *
  */
 protected function _processRequestStack($front, Zend_Controller_Response_Abstract $response)
 {
     $stack =& $this->_requestStack;
     $config =& $this->_config;
     $i = count($stack) - 1;
     $responseStack = array();
     $front->returnResponse(true);
     do {
         $myResponse = new Zend_Controller_Response_Http();
         $nextRequest = array_pop($stack);
         $nextRequest->setParam($config['indexKey'], $i);
         $this->_resetHelper();
         $this->_resetPlugins();
         $this->_resetParams($nextRequest->getParams());
         $front->setRequest($nextRequest);
         $front->setResponse($myResponse);
         $responseStack[] = $front->dispatch($nextRequest, $myResponse);
     } while ($i--);
     $front->returnResponse(false);
     $bodies = array();
     for ($i = 0, $len = count($responseStack); $i < $len; $i++) {
         $bodies[] = $responseStack[$i]->getBody();
     }
     $body = implode(',', $bodies);
     $response->setBody('[' . $body . ']');
 }
Ejemplo n.º 12
0
 /**
  * Hook 4: Called in $this->setResponse.
  *
  * All resources have been loaded and the $request and $response object have been created.
  * Theoretically this event can be triggered multiple times, but this does
  * not happen in a standard Zend application.
  *
  * Not initialized is the $controller object and the routing has not yet been executed.
  *
  * Previous hook: requestChanged()
  * Initialized since: the $this->response object
  * Next hook: routeStartup()
  *
  * @return void
  */
 public function responseChanged(\Zend_Controller_Response_Abstract $response)
 {
     $response->setHeader('Expires', '', true);
 }
Ejemplo n.º 13
0
 /**
  *
  * @param Zend_Controller_Response_Abstract $response
  * @param string $location
  */
 protected function assertResponseLocationHeader($response, $location)
 {
     $locationActual = null;
     foreach ($response->getHeaders() as $header) {
         if ($header['name'] === 'Location') {
             $locationActual = $header['value'];
         }
     }
     $this->assertNotNull($locationActual);
     $this->assertEquals($location, $locationActual);
 }
Ejemplo n.º 14
0
 function __exception404(Zend_Controller_Response_Abstract $response)
 {
     try {
         $p = $this->di->pageTable->load($this->di->config->get('404_page'));
         $body = $p->render($this->di->view, $this->di->auth->getUserId() ? $this->di->auth->getUser() : null);
     } catch (Exception $e) {
         $body = 'HTTP/1.1 404 Not Found';
     }
     $response->setHttpResponseCode(404)->setBody($body)->setRawHeader('HTTP/1.1 404 Not Found')->sendResponse();
 }
Ejemplo n.º 15
0
 /**
  * @static
  * @param \Zend_Controller_Response_Abstract $response
  * @return bool
  */
 public static function isHtmlResponse(\Zend_Controller_Response_Abstract $response)
 {
     // check if response is html
     $headers = $response->getHeaders();
     foreach ($headers as $header) {
         if ($header["name"] == "Content-Type") {
             if (strpos($header["value"], "html") === false) {
                 return false;
             }
         }
     }
     return true;
 }
Ejemplo n.º 16
0
 /**
  * Is a Html Response
  *
  * Checks if it finds a Content-Type-header with the value text/html
  *
  * @param Zend_Controller_Response_Abstract $response
  * @return bool
  */
 public function isHtmlResponse(Zend_Controller_Response_Abstract $response)
 {
     foreach ($response->getHeaders() as $value) {
         if ('content-type' == trim(strtolower($value['name'])) && false !== strpos(strtolower($value['value']), 'text/html')) {
             return true;
         }
     }
     foreach ($response->getRawHeaders() as $value) {
         $regex = preg_quote('content-type: text/html', '/');
         if (preg_match('/' . $regex . '/i', $value)) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 17
0
 /**
  * Try to get response body from cache storage with predefined processors
  *
  * @param Zend_Controller_Response_Abstract $response
  * @return bool
  */
 public function processRequest(Zend_Controller_Response_Abstract $response)
 {
     if (empty($this->_requestProcessors)) {
         return false;
     }
     $content = false;
     foreach ($this->_requestProcessors as $processor) {
         $processor = $this->_getProcessor($processor);
         if ($processor) {
             $content = $processor->extractContent($content);
         }
     }
     if ($content) {
         $response->appendBody($content);
         return true;
     }
     return false;
 }
Ejemplo n.º 18
0
 /**
  * Renders the response
  *
  * @param  Zend_Controller_Response_Abstract $response - The response object
  * @return void
  */
 public function render(Zend_Controller_Response_Abstract $response)
 {
     $response->sendHeaders();
     if (self::$_environment != "cli" && Zend_Layout::getMvcInstance()->isEnabled()) {
         echo Zend_Layout::getMvcInstance()->render();
     } else {
         echo $response;
     }
 }
Ejemplo n.º 19
0
 /**
  *
  * @param unknown_type $header
  */
 private function setRawHeader($header)
 {
     $this->response->setRawHeader($header);
 }
Ejemplo n.º 20
0
    /**
     * Add footer text
     *
     * @param Zend_Controller_Response_Abstract $response
     */
    protected function addFooter($response)
    {
        $footer = <<<EOF
\t\t\t</div><br />

\t\t</div>
\t</body>
</html>
EOF;
        $response->appendBody($footer);
    }
Ejemplo n.º 21
0
 /**
  * Returns all exceptions that have been registered to the specified response
  * object.
  *
  * @param Zend_Controller_Response_Abstract $response The response object to check
  * for exceptions
  *
  * @return Array
  */
 public static function getCurrentExceptions(Zend_Controller_Response_Abstract $response)
 {
     // check for exceptions that have already been added to the
     // response
     $exceptions = $response->getException();
     return $exceptions;
 }
Ejemplo n.º 22
0
 /**
  * Retrieve response header
  *
  * @param  Zend_Controller_Response_Abstract $response
  * @param  string $header
  * @return string|null
  */
 protected function _getHeader(Zend_Controller_Response_Abstract $response, $header)
 {
     $headers = $response->sendHeaders();
     $header = strtolower($header);
     if (array_key_exists($header, $headers)) {
         return $headers[$header];
     }
     return null;
 }
Ejemplo n.º 23
0
 /**
  * Method build response headers
  * 
  * @param \Zend_Controller_Response_Abstract $response
  * @param array $headers
  * @return \Extlib\Controller\Action\Helper\File
  */
 protected function buildHeaders(\Zend_Controller_Response_Abstract $response, array $headers)
 {
     foreach ($headers as $header => $value) {
         if (!in_array($header, $this->defaultHeaders)) {
             $response->setHeader($header, $value);
         }
     }
     return $this;
 }