/** * @param MvcContextInterface $context * @return null */ public function process(MvcContextInterface $context) { $input = $context->getInput(); $view = $context->getView(); if (!ResourceTreeManager::isTree()) { ResourceTreeManager::loadTree(); } $finder = new FileFinder('resource'); $writer = new FileWriter($finder); $reader = new FileReader($finder); if (!$writer->deleteTree('build', true)) { $err = "could not detete -({$finder->getPath('build')})"; throw new RunTimeException($err); } $list = ResourceTreeManager::getAllPageNames(); if (!is_array($list) || empty($list)) { return; } foreach ($list as $pageName) { $pkg = ResourceTreeManager::getPkg($pageName); $layers = $pkg->getLayers(); $pageStack = new FileStack(); foreach ($layers as $layerName) { $stack = new FileStack(); $layer = ResourceTreeManager::loadLayer($layerName, $stack); $this->buildLayer($layer, $reader, $writer, $pageStack); } $this->buildLayer(ResourceTreeManager::createPageLayer($pageName), $reader, $writer, $pageStack); $themeName = $pkg->getThemeName(); if ($themeName) { $this->buildTheme($themeName, $reader, $writer, $pageStack); } } $view->assign('result', 'build completed'); }
/** * Build the template file indicated by key into string. Use data in * the dictionary as scope * * @param string $key template file identifier * @param array $data used for private scope * @return string */ public function build() { $file = $this->getFile(); $finder = new FileFinder('resource'); $absolute = $finder->getPath($file); if (!$finder->fileExists($absolute, false)) { $err = "template file not found at -({$absolute})"; throw new DomainException($err, 404); } $data = $this->getAll(); $compositor = new SqlFileCompositor(); $compositor->setDbMap($this->getDbMap()); return $compositor->compose($absolute, $data); }
/** * @test * @return null */ public function isFileBasePath() { $root = 'test/resource/testfuel'; $finder = new FileFinder($root); $this->assertTrue($finder->isFile('test-file.txt')); $this->assertFalse($finder->isFile()); }
/** * @param string $vendorFile * @return array */ public function discoverPackageTree($path) { $isBasePath = true; if ('/' === $path[0]) { $isBasePath = false; } $finder = new FileFinder('resource', $isBasePath); $fileReader = new FileReader($finder); $packages = array(); $topDir = new RecursiveDirectoryIterator($finder->getPath($path)); $fileReader->setFileFinder(new FileFinder(null, false)); foreach (new RecursiveIteratorIterator($topDir) as $file) { if ('json' !== $file->getExtension()) { continue; } $data = $fileReader->decodeJsonAt($file->getPathName(), true); if (null === $data) { $info = $file->getPathInfo(); $dir = $info->getFileName(); $err = "error parsing the manfiest json file for -({$dir}): "; $err .= "{$fileReader->getLastJsonError()}"; throw new RunTimeException($err); } if (!isset($data['name'])) { $pathName = $file->getPathName(); $err = 'every resource pkg must have a -(name) property '; $err .= "file: -({$pathName})"; throw new DomainException($err); } $name = $data['name']; if (!is_string($name) || empty($name)) { $err = "property -(name) must be a none empty string "; $err .= "-({$file->getPathInfo()->getFileName()})"; throw new RunTimeException($err); } if (!isset($data['type'])) { $err = 'every resource pkg must have a -(type) property '; $err .= "defined: none found for -({$name})"; throw new DomainException($err); } $type = $data['type']; if (!is_string($type) || empty($type)) { $err = "appfuel resource -({$name}) json must have a type "; $err .= "property as which is a non empty string "; throw new DomainException($err); } if (isset($packages[$type][$name])) { $info = $file->getPathInfo(); $err = "can not build tree -({$type}, {$name}) is already "; $err .= "defined -({$info->getPathName()})"; throw new RunTimeException($err); } $packages[$type][$name] = $data; } return $packages; }