/** * @param string $directory */ public function __construct($directory) { Nette\Utils\SafeStream::register(); $directory = rtrim($directory, DIRECTORY_SEPARATOR); FileSystem::createDir($directory); $this->directory = $directory; }
/** * @return array */ private function getPresenters() { @SafeStream::register(); //intentionally @ (prevents multiple registration warning) $tree = array(); foreach (Finder::findFiles('*Presenter.php')->from(APP_DIR) as $path => $file) { $data = $this->processPresenter($file); if ($data === FALSE) { continue; } list($module, $presenter, $actions) = $data; $tree[$module][$presenter] = $actions; } foreach (Finder::findFiles('*.latte', '*.phtml')->from(APP_DIR) as $path => $file) { $data = $this->processTemplate($file); if ($data === FALSE) { continue; } list($module, $presenter, $action) = $data; if (!isset($tree[$module][$presenter])) { $tree[$module][$presenter] = array(); } if (array_search($action, $tree[$module][$presenter]) === FALSE) { $tree[$module][$presenter][] = $action; } } $tree = $this->removeSystemPresenters($tree); return $tree; }
/** * @param NULL|string $targetDir * @param NULL|AssetManager $assetManager * @param NULL|IEnvironment $globEnv * @param NULL|string $tempFile * @throws Exceptions\WriterException */ public function __construct($targetDir = NULL, AssetManager $assetManager = NULL, IEnvironment $globEnv = NULL, $tempFile = NULL) { if ($targetDir !== NULL) { $this->setTargetDir($targetDir); } $this->manager = $assetManager; $this->globalEnvironment = $globEnv; $this->setTempFile($tempFile); // Register safe:// stream if not registered if (!in_array('safe', stream_get_wrappers())) { SafeStream::register(); } }
public function generate() { $generatedFile = $this->getGeneratedFileName(); $lastModified = $this->getLastModified(); if (!file_exists($generatedFile) || $lastModified > filemtime($generatedFile)) { if (!in_array(SafeStream::PROTOCOL, stream_get_wrappers())) { SafeStream::register(); } $content = null; foreach ($this->files as $file) { $content .= file_get_contents($file); foreach ($this->fileFilters as $filter) { $content = call_user_func($filter, $content, $this, $file); } } foreach ($this->filters as $filter) { $content = call_user_func($filter, $content, $this); } file_put_contents("safe://" . $generatedFile, $content); } return basename($generatedFile) . '?' . filemtime($generatedFile); }
/** * Load content and save file * @param array files * @return string filename of generated file */ protected function generate($files) { $name = $this->getGeneratedFilename($files); $path = $this->tempPath . "/" . $name; $lastModified = $this->getLastModified($files); if (!file_exists($path) || $lastModified > filemtime($path)) { if (!in_array(SafeStream::PROTOCOL, stream_get_wrappers())) { SafeStream::register(); } file_put_contents("safe://" . $path, $this->getContent($files)); } return $name . "?" . $lastModified; }
public function __construct() { SafeStream::register(); }