public function render($path, array $args = null) { $compilerOptions = $this->getRenderer()->getCompiler()->getOptions(); $ext = $compilerOptions['extension']; if (substr($path, -strlen($ext)) === $ext) { $path = substr($path, 0, -strlen($ext)); } $outputPath = PathUtil::join($this->getOption('outputDirectory'), $path . $this->getOption('extension')); $render = function ($__path, $__args) { ob_start(); extract($__args); include $__path; return ob_get_clean(); }; if (!file_exists($outputPath) || time() - filemtime($outputPath) >= $this->getOption('lifeTime')) { $dir = dirname($outputPath); if (!is_dir($dir)) { @mkdir($dir, $this->getOption('directoryMode'), true); if (!is_dir($dir)) { throw new \Exception("Failed to create directory {$dir}"); } } file_put_contents($outputPath, $this->getRenderer()->compileFile($path)); chmod($outputPath, $this->getOption('fileMode')); } return $render($outputPath, $args ? $args : []); }
<?php use Tale\Util\ArrayUtil, Tale\Util\StringUtil, Tale\Util\PathUtil; include 'vendor/autoload.php'; $array = ['name' => 'someApp', 'path' => '/some/path', 'paths' => ['a' => '{{path}}/a', 'b' => '{{path}}/b'], 'feature' => ['path' => '{{paths.a}}/feature', 'name' => '{{name}}.Feature']]; var_dump($array); ArrayUtil::interpolate($array); var_dump($array); $singulars = ['user', 'user_group', 'user_group_field', 'user_group_status']; var_dump($singulars, array_map([StringUtil::class, 'pluralize'], $singulars), array_map([StringUtil::class, 'camelize'], $singulars), array_map([StringUtil::class, 'variablize'], $singulars), array_map([StringUtil::class, 'canonicalize'], $singulars)); foreach (range(0, 10) as $i) { list($pl, $pr, $sl, $sr) = array_map(function () { return mt_rand(0, 1) ? '/' : ''; }, array_fill(0, 4, null)); $parentPath = $pl . 'parent/path' . $pr; $subPath = $sl . 'sub/path' . $sr; var_dump($parentPath, $subPath, PathUtil::join($parentPath, $subPath)); }
public function resolvePath($path, $extension = null) { $paths = $this->_options['paths']; $ext = $extension ? $extension : $this->_options['extension']; if (substr($path, -strlen($ext)) !== $ext) { $path .= $ext; } if (count($paths) < 1) { //We got no paths to search in. We use the include-path in that case $paths = explode(\PATH_SEPARATOR, get_include_path()); } if (count($this->_files) > 0) { $paths[] = dirname(end($this->_files)); } foreach ($paths as $directory) { $fullPath = realpath(PathUtil::join($directory, $path)); if ($fullPath) { return $fullPath; } } return false; }