Exemplo n.º 1
0
 /**
  * 
  *
  * @return MString
  */
 public function responseString()
 {
     return MHTTPResponse::responseStringForCode($this->code());
 }
Exemplo n.º 2
0
/**
 * Sends a MHTTPResponse object to the client
 *
 * This funciton is used to send a HTTP response back to the client,
 * the response is represented by an instance of the MHTTPResponse
 * class
 *
 * @see MHTTPResponse
 *
 * @param MHTTPResponse $response The HTTP response to send back to the client
 *
 * @return void
 */
function MSendResponse(MHTTPResponse $response)
{
    $body = $response->body();
    header(sprintf("HTTP/1.1 %d %s", $response->code(), $response->responseString()));
    if ($response->headers()->count() > 0) {
        foreach ($response->headers()->allKeys()->toArray() as $header) {
            header(sprintf("%s: %s", $header, $response->headers()->objectForKey($header)));
        }
    }
    if ($body) {
        echo $body;
    }
}
Exemplo n.º 3
0
 /**
  * Creates a new MApplication instance with the specified delegate class
  * If no delegate class is specified the system looks for the 'manifest.xml'
  * file inside the 'resources' folder and parses it
  *
  * @param MString $delegateClass A string containing the fully qualified class
  * name for this application's delegate, or null.
  *
  * @return MApplication The MApplication instance which has just been created
  */
 public function __construct(MString $delegateClass = null)
 {
     parent::__construct();
     $this->_delegate = null;
     $this->_errorViewControllerClass = null;
     $this->_defaultNamespace = null;
     $this->_rootViewController = null;
     $this->_commandName = null;
     $this->_commandLineArguments = null;
     if (!$this->isRoutingEnabled()) {
         $this->enableRouting();
         $redirect = new MHTTPResponse(MHTTPResponse::RESPONSE_FOUND);
         $redirect->addHeader(S("Location"), MHTTPRequest()->url());
         MDie($redirect);
     }
     if ($delegateClass) {
         $this->_delegate = MObject::newInstanceOfClass($delegateClass);
     } else {
         if (MFile::fileExists("resources/manifest.xml")) {
             $xmlManifest = simplexml_load_file("resources/manifest.xml");
             $this->_delegate = MObject::newInstanceOfClassWithParameters(S($xmlManifest['delegate']), A($this));
             $this->_errorViewControllerClass = S($xmlManifest['errorClass']);
             try {
                 $this->_defaultNamespace = MApplicationNamespace::parseFromXMLElement($xmlManifest, S("application"));
             } catch (Exception $e) {
                 throw new MParseErrorException(S("resources/manifest.xml"), null, null, $e);
             }
         } else {
             $this->_delegate = new MApplicationDelegate($this);
         }
     }
     MApplication::$_application = $this;
 }
 /**
  * 
  *
  * @return MHTTPViewControllerResponse
  */
 public function __construct(MViewController $viewController = null)
 {
     parent::__construct();
     $this->viewController = $viewController;
 }