**/ public function __construct($path) { $this->path = realpath($path).DIRECTORY_SEPARATOR; $this->manifest = new TemplateManifest($this->path); $this->notFound = array(); $this->deleted = false; $this->compiled = $this->manifest->isCompiled(); } public function isCompiled() { return (bool) $this->compiled; } public function isDeleted() { return $this->deleted; } public function getManifest() { return $this->manifest; } /** * Compiles all the templates * @param string base path where it will create a directory to store compiled templates. * @return void * @author Carlos Escribano **/ public function compileTo($dir) { if ($this->compiled) { throw new sfException("This is a compiled package. Nothing to do."); } if ($this->deleted) { throw new sfException("You can not compile a package that has been deleted."); } $dir = realpath($dir).DIRECTORY_SEPARATOR.$this->manifest->getDirectoryName().DIRECTORY_SEPARATOR; if (file_exists($dir)) { if (!$this->remove($dir)) { throw new sfException("I have not enough writing privileges to remove the '$dir' directory file tree."); } } mkdir($dir, 0777, true); foreach (sfFinder::type('file')->name('*.tpl')->in($this->path) as $tpl) { $php = $dir.preg_replace('/\.tpl$/', '.php', basename($tpl)); Temper::factory($tpl)->parse($php); } $this->manifest->setCompiled(true); file_put_contents($dir.TemplateManifest::FILENAME, $this->manifest->dump()); if (file_exists($scr = $this->path.TemplateManifest::SCREENSHOT)) { copy($scr, $dir.TemplateManifest::SCREENSHOT); } foreach (sfFinder::type('file')->name('*.css')->in($this->path) as $css) { copy($css, $dir.basename($css)); } return $dir; } public function moveTo($dir, $createDirectory = true) { $dir = realpath($dir).DIRECTORY_SEPARATOR; if ($createDirectory) { $dir .= $this->manifest->getDirectoryName(); } if ($res = rename($this->path, $dir)) { $this->path = $dir; } return $res; } /** * Delete this package * @return void * @author Carlos Escribano **/ public function delete() { if (!$this->deleted) { $this->deleted = true; return $this->remove($this->path); } else { return true; } } protected function remove($path) { if (!file_exists($path)) { return true; } if (!is_dir($path)) { return unlink($path); } foreach (scandir($path) as $item) { if ($item == '.' || $item == '..') { continue; } if (!$this->remove($path.DIRECTORY_SEPARATOR.$item)) { return false; } } return rmdir($path); } }