Beispiel #1
0
 public static function load($xmlfile)
 {
     if (is_file($xmlfile)) {
         $dom = new \DOMDocument();
         libxml_use_internal_errors(true);
         $dom->load($xmlfile);
         if ($dom->schemaValidate(__DIR__ . "/../Resources/xsd/star.xsd")) {
             $root = $dom->documentElement;
             //  Preliminary path modifications
             foreach ($root->getElementsByTagName("include") as $include) {
                 $include->nodeValue = FileUtils::resolveRelativePath(FileUtils::getFileParent($xmlfile), $include->nodeValue);
             }
             //  Reading attributes
             $actions = array();
             foreach (XMLUtils::getChildrenByName($root, "action") as $child) {
                 $actions[] = AbstractAction::parse($child);
             }
             $subsites = array();
             foreach (XMLUtils::getChildrenByName($root, "subsite") as $child) {
                 $subsites[] = Subsite::parse($child);
             }
             $targets = array();
             foreach (XMLUtils::getChildrenByName($root, "target") as $child) {
                 $targets[] = Target::parse($child);
             }
             return new Site($subsites, $targets, $actions);
         } else {
             //$errors = libxml_get_errors();
             throw new \Exception("Document validation failed for '" . $xmlfile . "'");
         }
     } else {
         throw new \Exception("Not a file '" . $xmlfile . "'");
     }
 }
Beispiel #2
0
 public static function parse(\DOMNode $node)
 {
     if ($node->nodeName == self::getNodeName()) {
         $errors = array();
         foreach (XMLUtils::getChildrenByName($node, Error::getNodeName()) as $child) {
             $errors[] = Error::parse($child);
         }
         return new ErrorList($errors);
     }
     throw new \Exception("Unexpected node '" . $node->nodeName . "', expected '" . self::getNodeName() . "'");
 }
Beispiel #3
0
 public static function parse(\DOMNode $node)
 {
     if ($node->nodeName == self::getNodeName()) {
         $actions = new ActionList();
         foreach (XMLUtils::getChildrenByName($node, AbstractAction::getNodeName()) as $action) {
             $actions->add(AbstractAction::parse($action));
         }
         return new Target(XMLUtils::getAttributeByName($node, "name")->nodeValue, Uri::fromString(XMLUtils::getChildByName($node, "uri")->nodeValue), $actions, AbstractView::parse(XMLUtils::getChildByName($node, AbstractView::getNodeName())));
     }
     throw new \Exception("Unexpected node '" . $node->nodeName . "', expected '" . self::getNodeName() . "'");
 }
Beispiel #4
0
 public static function parse(\DOMNode $node)
 {
     if ($node->nodeName == self::getNodeName()) {
         $mime = XMLUtils::getAttributeByName($node, "mime") != null ? XMLUtils::getAttributeByName($node, "mime")->value : null;
         $code = XMLUtils::getAttributeByName($node, "code") != null ? XMLUtils::getAttributeByName($node, "code")->value : null;
         switch ($type = XMLUtils::getAttributeByName($node, "type")->value) {
             case "file":
                 if (is_file($file = FileUtils::getAbsolutePath($node->nodeValue, Star::instance()->getRootDirectory()))) {
                     switch ($extension = FileUtils::getExtension($file)) {
                         case "html":
                             return new HTMLFileView($file, $mime, $code);
                         case "php":
                             return new PHPFileView($file, $mime, $code);
                             /*
                             case "twig":
                             	return new TwigFileView($file, $mime, $code);
                             */
                         /*
                         case "twig":
                         	return new TwigFileView($file, $mime, $code);
                         */
                         default:
                             throw new \Exception("Unhandled file type '" . $extension . "' for file '" . $file . "'");
                     }
                 }
                 throw new \Exception("No such file '" . $file . "'");
                 /*
                 case "class":
                 	if(ClassLoader::getInstance()->classInstanceOf($node->nodeValue, "AbstractView")){
                 		return ClassLoader::getInstance()->newInstance($node->nodeValue);
                 	}
                 	throw new Exception("Class '" . $node->nodeValue . "' must be a subclass of '" . ClassLoader::getInstance()->getClassByName('AbstractView') . "'");
                 */
             /*
             case "class":
             	if(ClassLoader::getInstance()->classInstanceOf($node->nodeValue, "AbstractView")){
             		return ClassLoader::getInstance()->newInstance($node->nodeValue);
             	}
             	throw new Exception("Class '" . $node->nodeValue . "' must be a subclass of '" . ClassLoader::getInstance()->getClassByName('AbstractView') . "'");
             */
             default:
                 throw new \Exception("Unhandled type '" . $type . "', expecting type in 'file' or 'class'");
         }
     }
     throw new \Exception("Unexpected node '" . $node->nodeName . "', expected '" . self::getNodeName() . "'");
 }
Beispiel #5
0
 public static function parse(\DOMNode $node)
 {
     if ($node->nodeName == self::getNodeName()) {
         $path = XMLUtils::getChildByName($node, "path");
         $requirements = array();
         if (($require = XMLUtils::getAttributeByName($node, "require")) != null) {
             foreach (explode(",", $require->nodeValue) as $requirement) {
                 $requirements[] = trim($requirement);
             }
         }
         try {
             $reflection = new \ReflectionClass($path->nodeValue);
             $instance = $reflection->newInstance(XMLUtils::getAttributeByName($node, "name")->nodeValue, $requirements);
             if ($instance instanceof AbstractAction) {
                 return $instance;
             }
             throw new \Exception("The class '" . $path->nodeValue . "' must be a subclass of AbstractAction");
         } catch (\ReflectionException $re) {
             throw new \Exception("No class found for '" . $path->nodeValue . "'");
         }
     }
     throw new \Exception("Unexpected node '" . $node->nodeName . "', expected '" . self::getNodeName() . "'");
 }