예제 #1
0
 /**
  * Runs the WebApplication
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The request instance
  *
  * @return string The web applications content
  */
 public function run(HttpServletRequestInterface $servletRequest)
 {
     try {
         // register the Magento autoloader as FIRST autoloader
         spl_autoload_register(array(new \Varien_Autoload(), 'autoload'), true, true);
         // Varien_Profiler::enable();
         if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
             \Mage::setIsDeveloperMode(true);
         }
         ini_set('display_errors', 1);
         umask(0);
         // store or website code
         $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
         // run store or run website
         $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
         // set headers sent to false and start output caching
         appserver_set_headers_sent(false);
         ob_start();
         // reset and run Magento
         \Mage::reset();
         \Mage::register('ServletRequest', $servletRequest);
         \Mage::run();
         // write the session back after the request
         session_write_close();
         // We need to init the session anew, so PHP session handling will work like it would in a clean environment
         appserver_session_init();
         // grab the contents generated by Magento
         $content = ob_get_clean();
     } catch (\Exception $e) {
         error_log($content = $e->__toString());
     }
     // return the content
     return $content;
 }
 /**
  * Runs the WebApplication
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The request instance
  *
  * @return string The web applications content
  */
 public function run(HttpServletRequestInterface $servletRequest)
 {
     try {
         // cleanup mage registry
         foreach ($this->registryCleanKeys as $registryCleanKey) {
             \Mage::unregister($registryCleanKey);
         }
         error_log("Successfully reset Magento");
         // set headers sent to false and start output caching
         appserver_set_headers_sent(false);
         ob_start();
         // reset and run Magento
         $appRequest = new \Mage_Core_Controller_Request_Http();
         $appResponse = new \Mage_Core_Controller_Response_Http();
         $appRequest->setRequestUri();
         error_log("Set request URI: " . $_SERVER['REQUEST_URI']);
         $this->app->setRequest($appRequest);
         $this->app->setResponse($appResponse);
         // store or website code
         $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
         // run store or run website
         $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
         $this->app->run(array('scope_code' => $mageRunCode, 'scope_type' => $mageRunType, 'options' => array()));
         // write the session back after the request
         session_write_close();
         // We need to init the session anew, so PHP session handling will work like it would in a clean environment
         appserver_session_init();
         // grab the contents generated by Magento
         $content = ob_get_clean();
     } catch (\Exception $e) {
         error_log($content = $e->__toString());
     }
     // return the content
     return $content;
 }
예제 #3
0
 /**
  * Runs the process
  *
  * @return void
  */
 public function run()
 {
     // register shutdown handler
     register_shutdown_function(array(&$this, "shutdown"));
     // init globals to local var
     $globals = $this->globals;
     // set globals
     $_SERVER = $globals['server'];
     $_ENV = $globals['env'];
     $_REQUEST = $globals['request'];
     $_POST = $globals['post'];
     $_GET = $globals['get'];
     $_COOKIE = $globals['cookie'];
     $_FILES = $globals['files'];
     // check if http war post data is set
     if (isset($globals['httpRawPostData'])) {
         // set raw post data to be available in php://input stream and $HTTP_RAW_POST_DATA var
         appserver_set_raw_post_data($globals['httpRawPostData']);
     }
     // register uploaded files for thread process context internal hashmap
     foreach ($this->uploadedFiles as $uploadedFile) {
         appserver_register_file_upload($uploadedFile);
     }
     // change dir to be in real php process context
     chdir(dirname($this->scriptFilename));
     // reset headers sent
     appserver_set_headers_sent(false);
     try {
         // start output buffering
         ob_start();
         // require script filename
         require $this->scriptFilename;
     } catch (\Exception $e) {
         // process uncaught exceptions
         // todo: refactor this if pthreads can manage set_exception_handler.
         $this->lastError = array('message' => $e->getMessage(), 'type' => E_ERROR, 'file' => $e->getFile(), 'line' => $e->getLine());
     }
 }
예제 #4
0
 /**
  * Runs the process
  *
  * @param int $flags Flags how to start the process
  *
  * @return void
  */
 public function start($flags)
 {
     // init globals to local var
     $globals = $this->globals;
     // start output buffering
     ob_start();
     // set globals
     $_SERVER = $globals['server'];
     $_REQUEST = $globals['request'];
     $_POST = $globals['post'];
     $_GET = $globals['get'];
     $_COOKIE = $globals['cookie'];
     $_FILES = $globals['files'];
     // get current working dir for reset after processing
     $oldCwd = getcwd();
     // change dir to be in real php process context
     chdir(dirname($this->scriptFilename));
     // reset headers sent
     appserver_set_headers_sent(false);
     // require script filename
     require $this->scriptFilename;
     // change dir to old cwd
     chdir($oldCwd);
 }
 /**
  * Runs the WebApplication
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The request instance
  *
  * @return string The web applications content
  */
 public function run(HttpServletRequestInterface $servletRequest)
 {
     try {
         // register the Magento autoloader as FIRST autoloader
         spl_autoload_register(array(new \Varien_Autoload(), 'autoload'), true, true);
         // Varien_Profiler::enable();
         if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
             \Mage::setIsDeveloperMode(true);
         }
         ini_set('display_errors', 1);
         umask(0);
         // store or website code
         $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
         // run store or run website
         $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
         // set headers sent to false and start output caching
         appserver_set_headers_sent(false);
         ob_start();
         // reset and run Magento
         \Mage::reset();
         \Mage::register(MageStandardSessionServlet::SERVLET_REQUEST, $servletRequest);
         \Mage::run();
         /*
         // load the session and persist the data from $_SESSION
         $session = $servletRequest->getSession();
         
         foreach ($_SESSION as $namespace => $data) {
             if ($namespace !== 'identifier') {
                 error_log("Now add data for session {$session->getId()} and namespace: ". PHP_EOL . var_export($dat));
                 $session->putData($namespace, $data);
             }
         }
         */
         // grab the contents generated by Magento
         $content = ob_get_clean();
     } catch (\Exception $e) {
         error_log($content = $e->__toString());
     }
     // return the content
     return $content;
 }