/**
  *
  * @param $namespaceElement
  *
  * @return MApplicationNamespace
  */
 public static function parseFromXMLElement($namespaceElement, $name = null)
 {
     $namespaceName = $name;
     if (is_null($namespaceName)) {
         $namespaceName = S($namespaceElement['name']);
     }
     $namespace = new MApplicationNamespace($namespaceName);
     foreach ($namespaceElement as $element) {
         if ($element->getName() == "controller") {
             $namespace->addChildNode(MApplicationController::parseFromXMLElement($element));
         } else {
             if ($element->getName() == "namespace") {
                 $namespace->addChildNode(MApplicationNamespace::parseFromXMLElement($element));
             } else {
                 throw new MParseErrorException(null, null, Sf("Unknown element '%s'", $element->getName()));
             }
         }
     }
     return $namespace;
 }
Esempio n. 2
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;
 }