public mergeViewsSpec ( array $spec ) | ||
$spec | array | Specification viewtype => [ view_name => path or array of paths ] |
public function mergeViewsSpec(array $spec)
{
foreach ($spec as $viewtype => $list) {
foreach ($list as $view => $paths) {
if (!is_array($paths)) {
$paths = [$paths];
}
foreach ($paths as $path) {
if (preg_match('~^([/\\\\]|[a-zA-Z]\\:)~', $path)) {
// absolute path
} else {
// relative path
$path = Directory\Local::root()->getPath($path);
}
if (substr($view, -1) === '/') {
// prefix
$this->autoregisterViews($view, $path, $viewtype);
} else {
$this->setViewLocation($view, $viewtype, $path);
}
}
}
}
}
public function testCanSetViewPathsViaSpec() { $this->views->mergeViewsSpec(['default' => ['hello.js' => __DIR__ . '/../test_files/views/default/js/static.js', 'hello/world.js' => 'engine/tests/phpunit/test_files/views/default/js/interpreted.js.php']]); $expected = file_get_contents("{$this->viewsDir}/default/js/static.js"); $this->assertEquals($expected, $this->views->renderView('hello.js')); $this->assertEquals("// PHPin", $this->views->renderView('hello/world.js', array('in' => 'in'))); }