/**
  * Dispatches a request.
  *
  * This will determine which module and action to use by request parameters specified by the user.
  */
 public function dispatch()
 {
     try {
         if (sfConfig::get('sf_logging_enabled')) {
             $this->getContext()->getLogger()->info('{sfController} dispatch request');
         }
         // reinitialize filters (needed for unit and functional tests)
         sfFilter::$filterCalled = array();
         // determine our module and action
         $request = $this->getContext()->getRequest();
         $moduleName = $request->getParameter('module');
         $actionName = $request->getParameter('action');
         // make the first request
         $this->forward($moduleName, $actionName);
     } catch (sfException $e) {
         if (sfConfig::get('sf_test')) {
             throw $e;
         }
         $e->printStackTrace();
     } catch (Exception $e) {
         if (sfConfig::get('sf_test')) {
             throw $e;
         }
         try {
             // wrap non symfony exceptions
             $sfException = new sfException();
             $sfException->printStackTrace($e);
         } catch (Exception $e) {
             header('HTTP/1.0 500 Internal Server Error');
         }
     }
 }
  /**
   * Forwards to the 404 action.
   */
  public function printStackTrace()
  {
    $exception = null === $this->wrappedException ? $this : $this->wrappedException;

    if (sfConfig::get('sf_debug'))
    {
      $response = sfContext::getInstance()->getResponse();
      if (null === $response)
      {
        $response = new sfWebResponse(sfContext::getInstance()->getEventDispatcher());
        sfContext::getInstance()->setResponse($response);
      }

      $response->setStatusCode(404);

      return parent::printStackTrace();
    }
    else
    {
      // log all exceptions in php log
      if (!sfConfig::get('sf_test'))
      {
        error_log($this->getMessage());
      }

      sfContext::getInstance()->getController()->forward(sfConfig::get('sf_error_404_module'), sfConfig::get('sf_error_404_action'));
    }
  }
 /**
  * Forwards to the error action.
  */
 public function printStackTrace()
 {
     $exception = is_null($this->wrappedException) ? $this : $this->wrappedException;
     if (sfConfig::get('sf_debug')) {
         $response = sfContext::getInstance()->getResponse();
         if (is_null($response)) {
             $response = new sfWebResponse(sfContext::getInstance()->getEventDispatcher());
             sfContext::getInstance()->setResponse($response);
         }
         $response->setStatusCode($this->httpStatusCode);
         return sfException::printStackTrace();
         // skip sfError404Exception::printStackTrace()
     } else {
         // log all exceptions in php log
         if (!sfConfig::get('sf_test')) {
             error_log($this->getMessage());
         }
         if ($this->getMessage()) {
             sfContext::getInstance()->getRequest()->setParameter('error_message', $this->getMessage());
         }
         $module = sfConfig::get('sf_error_' . $this->httpStatusCode . '_module', sfConfig::get('sf_error_404_module', 'default'));
         $action = sfConfig::get('sf_error_' . $this->httpStatusCode . '_action', sfConfig::get('sf_error_404_action', 'error'));
         sfContext::getInstance()->getController()->forward($module, $action);
     }
 }
 /**
  * Dispatches a request.
  *
  * @param string A module name
  * @param string An action name
  * @param array  An associative array of parameters to be set
  */
 public function dispatch($moduleName, $actionName, $parameters = array())
 {
     try {
         // set parameters
         $this->getContext()->getRequest()->getParameterHolder()->add($parameters);
         // make the first request
         $this->forward($moduleName, $actionName);
     } catch (sfException $e) {
         $e->printStackTrace();
     } catch (Exception $e) {
         // wrap non symfony exceptions
         $sfException = new sfException();
         $sfException->printStackTrace($e);
     }
 }
Esempio n. 5
0
 public function dispatch()
 {
     try {
         if (sfConfig::get('sf_logging_enabled')) {
             $this->getContext()->getLogger()->info('{sfController} dispatch request');
         }
         sfFilter::$filterCalled = array();
         $request = $this->getContext()->getRequest();
         $moduleName = $request->getParameter('module');
         $actionName = $request->getParameter('action');
         $this->forward($moduleName, $actionName);
     } catch (sfException $e) {
         if (sfConfig::get('sf_test')) {
             throw $e;
         }
         $e->printStackTrace();
     } catch (Exception $e) {
         if (sfConfig::get('sf_test')) {
             throw $e;
         }
         try {
             $sfException = new sfException($e->getMessage());
             $sfException->printStackTrace($e);
         } catch (Exception $e) {
             header('HTTP/1.0 500 Internal Server Error');
         }
     }
 }
Esempio n. 6
0
    error_reporting(sfConfig::get('sf_error_reporting'));
    // create bootstrap file for next time
    if (!sfConfig::get('sf_in_bootstrap') && !$sf_debug && !sfConfig::get('sf_test')) {
        $configCache->checkConfig($sf_app_config_dir_name . '/bootstrap_compile.yml');
    }
    // required core classes for the framework
    // create a temp var to avoid substitution during compilation
    if (!$sf_debug && !sfConfig::get('sf_test')) {
        $core_classes = $sf_app_config_dir_name . '/core_compile.yml';
        $configCache->import($core_classes, false);
    }
    $configCache->import($sf_app_config_dir_name . '/php.yml', false);
    $configCache->import($sf_app_config_dir_name . '/routing.yml', false);
    // include all config.php from plugins
    sfLoader::loadPluginConfig();
    // compress output
    ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : '');
} catch (sfException $e) {
    $e->printStackTrace();
} catch (Exception $e) {
    if (sfConfig::get('sf_test')) {
        throw $e;
    }
    try {
        // wrap non symfony exceptions
        $sfException = new sfException();
        $sfException->printStackTrace($e);
    } catch (Exception $e) {
        header('HTTP/1.0 500 Internal Server Error');
    }
}
Esempio n. 7
0
 public function call($uri, $method = 'get', $parameters = array(), $changeStack = true)
 {
     $uri = $this->fixUri($uri);
     // add uri to the stack
     if ($changeStack) {
         $this->stack = array_slice($this->stack, 0, $this->stackPosition + 1);
         $this->stack[] = array('uri' => $uri, 'method' => $method, 'parameters' => $parameters);
         $this->stackPosition = count($this->stack) - 1;
     }
     list($path, $query_string) = false !== ($pos = strpos($uri, '?')) ? array(substr($uri, 0, $pos), substr($uri, $pos + 1)) : array($uri, '');
     $query_string = html_entity_decode($query_string);
     // remove anchor
     $path = preg_replace('/#.*/', '', $path);
     // removes all fields from previous request
     $this->fields = array();
     // prepare the request object
     $_SERVER = $this->defaultServerArray;
     $_SERVER['HTTP_HOST'] = $this->hostname ? $this->hostname : sfConfig::get('sf_app') . '-' . sfConfig::get('sf_environment');
     $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
     $_SERVER['SERVER_PORT'] = 80;
     $_SERVER['HTTP_USER_AGENT'] = 'PHP5/CLI';
     $_SERVER['REMOTE_ADDR'] = $this->remote ? $this->remote : '127.0.0.1';
     $_SERVER['REQUEST_METHOD'] = strtoupper($method);
     $_SERVER['PATH_INFO'] = $path;
     $_SERVER['REQUEST_URI'] = '/index.php' . $uri;
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $_SERVER['SCRIPT_FILENAME'] = '/index.php';
     $_SERVER['QUERY_STRING'] = $query_string;
     foreach ($this->vars as $key => $value) {
         $_SERVER[strtoupper($key)] = $value;
     }
     // request parameters
     $_GET = $_POST = array();
     if (strtoupper($method) == 'POST') {
         $_POST = $parameters;
     }
     if (strtoupper($method) == 'GET') {
         $_GET = $parameters;
     }
     parse_str($query_string, $qs);
     if (is_array($qs)) {
         $_GET = array_merge($qs, $_GET);
     }
     // restore cookies
     $_COOKIE = array();
     foreach ($this->cookieJar as $name => $cookie) {
         $_COOKIE[$name] = $cookie['value'];
     }
     // recycle our context object
     sfContext::removeInstance();
     $this->context = sfContext::getInstance();
     // launch request via controller
     $controller = $this->context->getController();
     $request = $this->context->getRequest();
     $response = $this->context->getResponse();
     // we register a fake rendering filter
     sfConfig::set('sf_rendering_filter', array('sfFakeRenderingFilter', null));
     $this->currentException = null;
     // dispatch our request
     ob_start();
     try {
         $controller->dispatch();
     } catch (sfException $e) {
         $this->currentException = $e;
         $e->printStackTrace();
     } catch (Exception $e) {
         $this->currentException = $e;
         $sfException = new sfException();
         $sfException->printStackTrace($e);
     }
     $retval = ob_get_clean();
     if ($this->currentException instanceof sfStopException) {
         $this->currentException = null;
     }
     // append retval to the response content
     $response->setContent($retval);
     // manually shutdown user to save current session data
     $this->context->getUser()->shutdown();
     $this->context->getStorage()->shutdown();
     // save cookies
     $this->cookieJar = array();
     foreach ($response->getCookies() as $name => $cookie) {
         // FIXME: deal with expire, path, secure, ...
         $this->cookieJar[$name] = $cookie;
     }
     // for HTML/XML content, create a DOM and sfDomCssSelector objects for the response content
     if (preg_match('/(x|ht)ml/i', $response->getContentType())) {
         $this->dom = new DomDocument('1.0', sfConfig::get('sf_charset'));
         $this->dom->validateOnParse = true;
         @$this->dom->loadHTML($response->getContent());
         $this->domCssSelector = new sfDomCssSelector($this->dom);
     }
     return $this;
 }