Esempio n. 1
0
 protected function makeCompileFile($template, $compiledPath)
 {
     if ((ENVIRONMENT & PRODUCTION) > 0) {
         if (is_readable($compiledPath)) {
             return;
         }
     }
     $regex = '/<\\?(.)?\\s(.+)\\s\\?>/U';
     $template = Renderer_Sabel_Replacer::create()->execute($template);
     $template = preg_replace_callback($regex, '_sbl_tpl_pipe_to_func', $template);
     if (defined("URI_IGNORE")) {
         $images = "jpg|gif|bmp|tiff|png|swf|jpeg|css|js";
         $quote = '"|\'';
         $pat = "@(({$quote})/[\\w-_/.]*(\\.({$images}))({$quote}))@";
         $template = preg_replace($pat, '"<?= linkto($1) ?>"', $template);
     }
     $template = str_replace('<?=', '<? echo', $template);
     $template = preg_replace('/<\\?(?!xml|php)/', '<?php', $template);
     $template = str_replace('<?xml', '<<?php echo "?" ?>xml', $template);
     $fs = new Sabel_Util_FileSystem();
     if ($fs->isFile($compiledPath)) {
         $fs->remove($compiledPath);
     }
     $fs->mkfile($compiledPath)->write($template)->save();
 }
Esempio n. 2
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}");
 }
Esempio n. 3
0
 protected function _installAddon($name, $xml)
 {
     $doc = new Sabel_Xml_Document();
     $root = $doc->loadXML($xml);
     if ($error = $root->getChild("error")) {
         $this->error($error->getNodeValue());
         $this->error("install failed.");
         return;
     }
     $version = $root->getChild("version")->getNodeValue();
     $addonName = ucfirst($name);
     $className = $addonName . "_Addon";
     if (class_exists($className, true)) {
         eval('$v = ' . $className . '::VERSION;');
         if ($v === (double) $version) {
             $this->message("{$addonName}_{$version} already installed.");
             return;
         } elseif ((double) $version > $v) {
             $_v = strpos($v, ".") === false ? "{$v}.0" : $v;
             $this->message("upgrade " . $addonName . " from {$_v} to {$version}.");
         } else {
             $this->message("nothing to install.");
             return;
         }
     }
     $files = $root->getChildren("file");
     foreach ($files as $i => $file) {
         $path = $file->getChild("path")->getNodeValue();
         $path = str_replace(":", DS, $path);
         $source = $file->getChild("source")->getNodeValue();
         if (!$this->fs->isFile($path)) {
             $this->fs->mkfile($path)->write($source)->save();
         } else {
             $this->fs->getFile($path)->write($source)->save();
         }
         $this->success($path);
     }
     $this->success("install ok: {$addonName}_{$version}");
 }
Esempio n. 4
0
 protected function readOptions($args)
 {
     if (in_array("--overwrite", $args, true)) {
         $index = array_search("--overwrite", $args) + 1;
         for ($i = $index, $c = count($args); $i < $c; $i++) {
             if (substr($args[$i], 0, 2) === "--") {
                 break;
             }
             $path = $this->targetDir . DS . $args[$i];
             if (is_file($path)) {
                 unlink($path);
             } elseif (is_dir($path)) {
                 $fs = new Sabel_Util_FileSystem($path);
                 $fs->rmdir();
             }
         }
     }
     if (in_array("--ignore", $args, true)) {
         $index = array_search("--ignore", $args) + 1;
         for ($i = $index, $c = count($args); $i < $c; $i++) {
             if (substr($args[$i], 0, 2) === "--") {
                 break;
             }
             $this->ignore[$args[$i]] = 1;
         }
     }
     if (Sabel_Console::hasOption("l", $args)) {
         if (($lang = Sabel_Console::getOption("l", $args)) !== null) {
             $lang = strtolower($lang);
             if (is_dir($this->skeletonDir . DS . $lang)) {
                 $this->lang = $lang;
             }
         }
     }
 }
Esempio n. 5
0
 public function testCleanup()
 {
     $fs = new Sabel_Util_FileSystem($this->basedir);
     $fs->rmdir("test");
     $fs->rmdir("moved");
 }