function app_event_test_bundle($values) { global $config; $page = rea_views::default_page(); // Use bundle to help you access files in your app folder //Creating a bundle //$f = rea_app::bundle(); //is the same as $f = rea_bundle::create(); //$f = rea_app::bundle('/some/absolute/path'); //$f = rea_app::bundle('@engine'); //may also use @root for the document root //$bs = rea_files::create(REA_BASE_PATH . 'views/bootstrap/'); //$page->header->write( $bs->includeAll() ); //Using iterator with a callback $f = rea_files::create('@engine'); $m = function ($item) use($page) { $page->body->write("got file " . $item->url . " of type " . $item->type . ' (' . $item->extension . ')<br>'); }; $f->js->each($m); //call the function m for each of the items in the folder js //We can walk folders in the bundle path $item = $f->js->child('rea.helper.views.js'); //we can get some basic info $page->body->write("item path is=" . $item->path . '<br>'); $page->body->write("item url is=" . $item->url . '<br>'); $page->body->write("item is_directory=" . $item->is_directory . '<br>'); $page->body->write("item is_readable=" . $item->is_readable . '<br>'); $page->body->write("item extension=" . $item->extension . '<br>'); $page->body->write("item type=" . $item->type . '<br>'); if (!$item->exists()) { $page->body->write('item does not exists<br>'); } else { $page->body->write('item does exists<br>'); } //We can convert an instance of a bundle item to an html tag using $s = $item->html('js'); //We can put a file represented in a bundle directly in the template using write $page->header->write($item->html()); //$page->header->write($f->js->child('rea.helper.views.js')->html()); //the same as above //$page->header->write(rea_files::create('@engine')->js->child('rea.helper.views.js')->html()); //the same as above //also works like $s = $img_file->html(); //when no tag is provided the extension is used to figure out a default html tag for that file type eg: js, img, or css tag. //We can do all of these operation in one like $f = rea_files::create(); $s = $f->views->media->child('login_banner.png')->html(); $page->body->write(htmlentities($s)); }
public static function create($n) { $f = rea_views::getViewFileWithName($n); return self::createWithSource($n, file_get_contents($f), dirname($f)); }