public function view($file, $vars = [], $paths = []) { // loop through vars and // print our params foreach ($this->_parameters as $key => $value) { if (!array_key_exists($key, $vars)) { $vars[$key] = $value; } } if (!is_array($paths)) { $paths = []; } // paths to find $paths += $this->parent('bolt\\browser')->path('views'); // find this template $find = new Finder(); $base = pathinfo($file)['dirname']; $name = pathinfo($file)['basename']; // loop through each path foreach ($paths as $path) { $files = $find->files()->in(b::path($path, $base))->name($name); if (iterator_count($files)) { $it = iterator_to_array($files); $first = array_shift($it); return new view(['file' => $first->getRealPath(), 'vars' => $vars, 'context' => $this, 'helpers' => []]); } } // nope return false; }
public function test_devModeFilter() { if (!class_exists('lessc')) { $this->markTestSkipped('LessPHP is not installed'); } b::env('dev'); // we need out less filter $this->a->filter('less', 'Lessphp'); $this->a->filter('*', 'CssMin', false); $file = b::path($this->dir, 'less/file.less'); $exp = "footer {\n background: green;\n}\n" . "body header {\n background: red;\n}"; $this->assertEquals($exp, $this->a->processFile($file)); b::env('prod'); $exp = "footer{background:green}" . "body header{background:red}"; $this->assertEquals($exp, $this->a->processFile($file)); }
public function handle($req, $res) { $route = b::browser('route\\create', ['path' => $this->config->value('route', '/a/{path}'), 'require' => ['path' => '.*']]); // match a route if (($params = $this->matchRoute($route, $req)) === false) { return false; } // content $content = ""; // paths $paths = $req->assets->getDirs(); // explode out the path foreach (explode('&', $params['path']) as $path) { $info = pathinfo($path); // get our path $dir = $info['dirname']; $file = $info['basename']; $ext = $info['extension']; // find this template $find = new Finder(); // loop through each path foreach ($paths as $path) { // find the files $files = $find->files()->in(b::path($path, $dir))->name($file); if (iterator_count($files)) { $it = iterator_to_array($files); $first = array_shift($it); $real = $first->getRealPath(); // rel $rel = str_replace($path, '', $real); // process a file and append it's content $content .= \bolt\browser\assets::instance()->processFile($real, ['rel' => $rel, 'url' => 'http://localhost/' . str_replace('{path}', '', $route->getPath()), 'filterOnly' => $req->query->get('filterOnly')]); } } } // figureo ut $res->headers->set('Content-Type', $this->_mapContentTypeFromExt($ext)); // set our content $res->setContent($content); return $res; }
public function find($find, $root = false) { if (substr($find, 0, 4) === 'http') { return [null, $find]; } foreach (array_merge([$root], $this->_dir) as $path) { $_ = b::path($path, $find); if (file_exists($_)) { return [$path, $_]; } } return false; }
public function test_path() { $this->assertEquals("/test/path", b::path('test', 'path')); $this->assertEquals("/test/path", b::path('test', '/path/')); }
/** * get a path relative to $root * * @param $path * * @return string path relative to $root */ public function path($path) { return b::path($this->_root, $path); }