Elgg\ViewsService::mergeViewsSpec PHP Метод

mergeViewsSpec() публичный Метод

Merge a specification of absolute view paths
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);
                    }
                }
            }
        }
    }

Usage Example

Пример #1
0
 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')));
 }