Пример #1
0
 public function __construct($config = array())
 {
     $this->config = $config;
     if (!defined("RUN_BASE")) {
         throw new Sabel_Exception_Runtime("RUN_BASE can't be undefined");
     }
     $preferencesDir = RUN_BASE . DS . "data" . DS . "preferences";
     if (isset($this->config["file"])) {
         $file = $this->config["file"];
         if (strpos($file, ".") === false) {
             $file .= ".xml";
         }
         if (isset($config["absolute"])) {
             $this->filepath = $file;
         } else {
             $this->filepath = $preferencesDir . DS . $file;
         }
     }
     if ($this->filepath === null) {
         $this->filepath = $preferencesDir . DS . "default.xml";
     }
     if (dirname($this->filepath) !== "." && !is_dir(dirname($this->filepath))) {
         if (!mkdir(dirname($this->filepath), 0755)) {
             throw new Sabel_Exception_Runtime("can't make directory " . dirname($this->filepath) . " check configuration");
         }
     }
     if (!is_readable($this->filepath)) {
         if (!touch($this->filepath, 0644)) {
             throw new Sabel_Exception_Runtime("can't create " . $this->filepath . " check configuration");
         }
         file_put_contents($this->filepath, '<?xml version="1.0" encoding="utf-8"?><preferences/>');
     }
     $this->document = Sabel_Xml_Document::create();
     $this->rootNode = $this->document->load("XML", $this->filepath);
 }
Пример #2
0
 protected static function load($contents, $xmlConfig)
 {
     $document = Sabel_Xml_Document::create($xmlConfig);
     $element = $document->loadXML($contents);
     if ($element === null) {
         $message = __METHOD__ . "() invalid xml.";
         throw new Sabel_Exception_Runtime($message);
     }
     switch (strtolower($element->tagName)) {
         case "rdf:rdf":
             return new Sabel_Rss_Reader_Rdf($element);
         case "rss":
             return new Sabel_Rss_Reader_Rss($element);
             break;
         case "feed":
             if ($element->getAttribute("version") === "0.3") {
                 return new Sabel_Rss_Reader_Atom03($element);
             } else {
                 return new Sabel_Rss_Reader_Atom10($element);
             }
             break;
         default:
             $message = __METHOD__ . "() unknown feed format.";
             throw new Sabel_Exception_Runtime($message);
     }
 }
Пример #3
0
 public function __construct(array $info)
 {
     $this->info = $info;
     $arg = array();
     if (array_isset("xmlVersion", $info)) {
         $arg["version"] = $info["xmlVersion"];
     }
     if (array_isset("encoding", $info)) {
         $arg["encoding"] = $info["encoding"];
     }
     $this->document = Sabel_Xml_Document::create($arg);
 }
Пример #4
0
 protected function _installAddon($name, $response)
 {
     if (substr($response, 0, 5) === "HEAD:") {
         return $this->installAddon($name, trim(substr($response, 5)));
     }
     $addon = Sabel_Xml_Document::create()->loadXML($response);
     if ($addon->tagName !== "addon") {
         $this->error("addon '{$name}' not found.");
         exit;
     }
     $name = $addon->at("name");
     $version = $addon->at("version");
     $files = $this->getAddonsFiles($addon);
     if (!isset($files["Addon.php"])) {
         $message = __METHOD__ . "() invalid addon. Addon.php not exists.";
     }
     $addonClass = ucfirst($name) . "_Addon";
     if (class_exists($addonClass, true)) {
         $v = constant($addonClass . "::VERSION");
         if ($v === (double) $version) {
             $this->message("{$name}_{$version} already installed.");
             return;
         } elseif ((double) $version > $v) {
             $_v = strpos($v, ".") === false ? "{$v}.0" : $v;
             $this->message("upgrade {$name} from {$_v} => {$version}.");
         } else {
             $this->message("nothing to install.");
             return;
         }
     }
     $fs = new Sabel_Util_FileSystem(RUN_BASE);
     foreach ($files as $path => $file) {
         $path = str_replace("/", DS, $path);
         if ($file["backup"] && $fs->isFile($path)) {
             $oldFile = $path . ".old";
             $fs->getFile($path)->copyTo(RUN_BASE . DS . $oldFile);
             $this->message("{$path} saved as {$oldFile}");
         }
         if (!$fs->isFile($path)) {
             $fs->mkfile($path)->write($file["source"])->save();
         } else {
             $fs->getFile($path)->write($file["source"])->save();
         }
         $this->success($path);
     }
     $this->success("install ok: {$name}_{$version}");
 }
Пример #5
0
 public function testGetAllChildren()
 {
     $xml = Sabel_Xml_Document::create();
     $nodes = $this->loadXML($xml, "ns");
     $foo = $nodes->getChild("foo:foo");
     $children = $foo->getChildren();
     $this->assertEquals(4, $children->length);
     $this->assertEquals("foo:fooitem1", $children->item(0)->tagName);
     $this->assertEquals("defitem", $children->item(1)->tagName);
     $this->assertEquals("bar:baritem1", $children->item(2)->tagName);
     $this->assertEquals("baz", $children->item(3)->tagName);
 }