Exception Class !MongoCursorException

Exception Message ! localhost:27017: bad skip value in query

Exception From ! {{ CMS }} » content/vendor/Bongo/DocumentIterator.php # Line No. 68

MongoCursorException { Throw Exception in here. } # Line No. 68
{{ CMS }} » content/vendor/Bongo/DocumentIterator.php
		$this->cursor->next();
	}

	public function rewind()
	{
		$this->cursor->rewind();

	}

	public function valid()
	{
MongoCursor::rewind( ) # Line No. 68
{{ CMS }} » content/vendor/Bongo/DocumentIterator.php
		$this->cursor->next();
	}

	public function rewind()
	{
		$this->cursor->rewind();

	}

	public function valid()
	{
Bongo\DocumentIterator::rewind( ) # Line No. 219
{{ CMS }} » content/vendor/Bongo/Collection.php
        return array_filter($this->items, $callback);
    }

    public function buildModel($model, $items)
    {
        foreach ($items as $item) {

            $model = new $model;
            $model->setAttributes($item);
            $model->setOriginal($item);
            $model->setOldies();
Bongo\Collection::buildModel( ) # Line No. 113
{{ CMS }} » content/vendor/Bongo/Collection.php
    }

    public function get($keys = array())
    {
        $result = $this->query->get((array)$keys);
        $this->buildModel($this->model, $result);

        return $this;
    }

    public function distinct($key)
Bongo\Collection::get( ) # Line No. 246
{{ CMS }} » content/vendor/Data/Repositories/AbstractRepository.php
	 * @return \Bongo\Collection
	 **/
	public function getMany($limit = 10, $offset = null, $keys = array())
	{
		$model = $this->model;
		return $model::limit($limit)->skip($offset)->get($keys);
	}

	/**
	 * Get data collection by limit, skip and order by created_at 'desc'.
Data\Repositories\AbstractRepository::getMany( ) # Line No. 144
{{ CMS }} » content/shared/modules/university/src/University/Facade/University.php
    public static function ouaSlider()
    {
        $uni = DataFactory::make('university');
        $ran = floor(rand(0,$uni->count()-5));
        
        $result = $uni->getMany(5,$ran);

        return $result;
    }
University\Facade\University::ouaSlider( ) # Line No. 47
{{ CMS }} » content/shared/themes/ouathemes/helpers.php
 * @return html
 */
function ouaSlide()
{
	$html = "";
	$data = University::ouaSlider();

	$active = 'active';
	foreach ($data as $key) {
		$html .= '
';
::ouaSlide( ) # Line No. 53
{{ CMS }} » storages/template/916ff5d940064ce7c5a44b525e192990.php
::include( ) # Line No. 432
{{ CMS }} » storages/compile.php
 namespace Reborn\MVC\Model; class Search extends Model { protected $skip; protected $limit = 20; protected $wheres = array(); protected $joint = 'or'; protected $support_joints = array('on', 'and'); protected $order_by = array(); public static function make($table = '') { $ins = new static(); return $ins; } public function joint($joint = 'or') { $joint = strtolower($joint); if (in_array($joint, $this->support_joints)) { $this->joint = $joint; } return $this; } public function must($field, $text) { $this->wheres[$field] = array('=', $text); return $this; } public function startWith($field, $text) { $this->wheres[$field] = array('like', $text.'%'); return $this; } public function endWith($field, $text) { $this->wheres[$field] = array('like', '%'.$text); return $this; } public function contain($field, $text) { $this->wheres[$field] = array('like', '%'.$text.'%'); return $this; } public function charLength($field, $length) { if (is_string($length) and !is_numeric($length)) { $length = strlen($length); } $text = str_repeat('_', (int) $length); $this->wheres[$field] = array('like', $text); return $this; } public function desc($columns) { $columns = array($columns); $this->order_by['desc'] = $columns; return $this; } public function asc($columns) { $columns = array($columns); $this->order_by['asc'] = $columns; return $this; } public function skip($skip) { $this->skip = $skip; return $this; } public function take($limit) { $this->limit = $limit; return $this; } public function get($columns = array('*')) { $builder = $this->prepare(); $builder->take($this->limit); if (! is_null($this->skip) ) { $builder->skip($this->skip); } return $builder->get($columns); } public function setTable($table) { $this->table = $table; return $this; } protected function prepare() { $builder = $this->newQuery(); $i = 0; foreach ($this->wheres as $column => $w) { if ($i > 0) { $builder->where($column, $w[0], $w[1], $this->joint); } else { $builder->where($column, $w[0], $w[1]); } $i++; } $order_by = $this->order_by; if (isset($order_by['desc'])) { foreach ($order_by['desc'] as $col) { $builder->orderBy($col, 'desc'); } } if (isset($order_by['asc'])) { foreach ($order_by['asc'] as $col) { $builder->orderBy($col, 'asc'); } } return $builder; } } 

 namespace Reborn\MVC\View; use Reborn\Cores\Setting; use Reborn\Filesystem\File; use Reborn\Cores\Application; use Reborn\Filesystem\Directory as Dir; use Reborn\Event\EventManager as Event; class ViewManager { protected $app; protected $template; protected $theme; protected $view; protected $parser; protected $ext = '.html'; public function __construct(Application $app) { $this->app = $app; $this->theme = $this->themeSetter(); $this->parser = new Parser(); Event::call('reborn.parser.create', array($this->parser)); $this->addParserHandler(); $this->checkHelpersFileFromTheme(); $this->view = new View($app['config']->get('template.cache_path'), new Block()); $this->ext = $app['config']->get('template.template_extension'); $this->template = new Template($this->theme, $this->view, $this->ext); $this->setObject(); } public function getTemplate() { return $this->template; } public function getTheme() { return $this->theme; } public function getView() { return $this->view; } public function getParser() { return $this->parser; } public function adminTheme() { $theme = Setting::get('admin_theme'); $themePath = ADMIN_THEME; return new Theme($this->app, $theme, $themePath); } protected function themeSetter() { if (defined('ADMIN')) { $theme = Setting::get('admin_theme'); $themePath = ADMIN_THEME; } else { $theme = Setting::get('public_theme'); $themePath = THEMES; } if (! Dir::is($themePath.$theme)) { if (Dir::is(SHARED.'themes'.DS.$theme)) { $themePath = SHARED.'themes'.DS; } } $events = $themePath.$theme.DS.'events.php'; if (File::is($events)) { require $events; } return new Theme($this->app, $theme, $themePath); } protected function setObject() { $this->view->setObject($this->parser, $this->template); } protected function addParserHandler() { $active = $this->theme->getThemePath(); $handler = $active.'handler'.DS.'register.php'; if (Dir::is($active.'handler') and file_exists($handler)) { require $handler; } $files = Dir::get(__DIR__.DS.'Handler'.DS.'*.php'); $namespace = '\Reborn\MVC\View\Handler\\'; foreach ($files as $file) { $name = pathinfo($file, PATHINFO_FILENAME); $obj = $namespace.$name; $ins = new $obj($this->parser); $key = $ins->getKey(); $this->parser->addHandler($key, $namespace.$name); } } protected function checkHelpersFileFromTheme() { $active = $this->theme->getThemePath(); $file = $active.'helpers.php'; if (file_exists($file)) { require $file; } } } 

 namespace Reborn\MVC\View; use ArrayAccess; use Reborn\Filesystem\File; use Reborn\Exception\FileNotFoundException; class View implements ArrayAccess { protected $data = array(); protected $parser; protected $template; protected $cache; protected $_block; public function __construct($cachePath = null, Block $block = null) { $this->cache = is_null($cachePath) ? STORAGES.'template'.DS : $cachePath; $this->_block = is_null($block) ? new Block : $block; } public function setObject(Parser $parser, Template $template) { $this->parser = $parser; $this->template = $template; } public function getParser() { return $this->parser; } public function render($file) { if (file_exists($file)) { if (\Event::has('reborn.view.before.render')) { $hook_data = \Event::call('reborn.view.before.render'); } $data = $this->data; if ('html' == pathinfo($file, PATHINFO_EXTENSION)) { $file = $this->fileParse($file, $data); } ob_start(); extract($data, EXTR_SKIP); if (isset($hook_data) and !is_null($hook_data)) { foreach ($hook_data as $hook) { if(is_null($hook)) continue; extract($hook, EXTR_SKIP); } } try { include $file; } catch (\Exception $e) { ob_get_clean(); throw $e; } $result = ob_get_clean(); return $result; } else { throw new FileNotFoundException($file, $this->theme); } } public function renderAsStr($template, $data = array()) { $data = $this->data = array_merge($this->data, $data); $contents = $this->parser->parseString($template); ob_start(); extract($data, EXTR_SKIP); try { eval('?>'.$contents); } catch (\Exception $e) { ob_get_clean(); throw $e; } $content = ob_get_clean(); return $content; } public function set($key, $value = null) { if (is_array($key)) { $this->data = array_merge($this->data, $key); } else { $this->data[$key] = $value; } return $this; } protected function includeFile($file) { $file = trim($file, ' '); $file = $this->template->findFile($file); if ($file) { return $this->render($file); } else { return null; } } protected function partialLoop($file, $model = null, $value_name = '_value', $key_name = '_key') { $content = ''; if (!is_array($model) || !is_object($model)) { if (is_null($model)) { return $this->template->partialRender($file); } return $content; } foreach ($model as $key => $value) { $this->data[$key_name] = $key; $this->data[$value_name] = $value; $content .= $this->template->partialRender($file); } return $content; } protected function partialFile($file) { $file = trim($file, ' '); return $this->template->partialRender($file); } protected function fileParse($file, $data) { $cacheFile = $this->cache.md5($file).'.php'; if ($cfile = $this->cacheFileCheck($cacheFile, $file)) { return $cfile; } $fileData = File::getContent($file); $header = "\n"; $filename = '\n"; $content = $this->parser->parse($fileData, $data); File::write($this->cache, md5($file).'.php', $header.$filename.$content); return $cacheFile; } protected function cacheFileCheck($cacheFile, $file) { if (file_exists($cacheFile)) { if ($this->isModified($cacheFile, $file)) { File::delete($cacheFile); return false; } return $cacheFile; } return false; } protected function isModified($cacheFile, $file) { $time = filemtime($file); $cacheTime = filemtime($cacheFile); return $time > $cacheTime; } public function __set($key, $value) { $this->set($key, $value); } public function __get($key) { return $this->data[$key]; } public function __toString() { $this->render(); } public function offsetSet($key, $value) { $this->set($key, $value); } public function offsetGet($key) { return isset($this->data[$key]) ? $this->data[$key] : null; } public function offsetExists($key) { return isset($this->data[$key]) ? true : false; } public function offsetUnset($key) { unset($this->data[$key]); } } 

 namespace Reborn\MVC\View; use Reborn\Util\Str; use Reborn\Cores\Application; use Reborn\Filesystem\File; use Reborn\Filesystem\Directory as Dir; use Reborn\Exception\FileNotFoundException; class Theme { protected $theme; protected $path; protected $app; public function __construct(Application $app, $name, $path) { $this->app = $app; $this->theme = $name; $this->path = $path; } public function all($name_only = false) { $paths = $this->getThemeFolderPaths(); $all = array(); $type = 'private'; foreach ($paths as $path) { $all[$type] = Dir::get($path.'*', GLOB_ONLYDIR); $type = 'shared'; } if ($name_only) { $names = array(); foreach ($all as $type => $paths) { foreach ($paths as $path) { $names[] = basename($path); } } return $names; } return $all; } public function findTheme($theme) { $paths = $this->getThemeFolderPaths($theme); foreach ($paths as $path) { if (Dir::is($path)) { return $path; } } return null; } public function setPath($path) { $this->path = $path; } public function getThemePath() { if (! Dir::is($this->path.$this->theme)) { throw new \Exception("{$this->theme} folder doesn't exists in {$this->path}"); } return $this->path.$this->theme.DS; } public function getLayouts() { $path = $this->path.$this->theme.DS.'views'.DS.'layout'.DS; $layouts = array(); $all = glob($path.'*.html'); foreach ($all as $file) { $layouts[] = str_replace($path, '', $file); } return $layouts; } public function layoutsFrom($name) { $path = $this->findTheme($name); $layouts = array(); if (is_null($path)) return $layouts; $all = glob($path.'views'.DS.'layout'.DS.'*.html'); foreach ($all as $s) { $layouts[] = str_replace($path.'views'.DS.'layout'.DS, '', $s); } return $layouts; } public function hasLayout($name) { $file = $this->path.$this->theme.DS.'views'.DS.'layout'.DS.$name.'.html'; return File::is($file); } public function hasFile($name, $folder = 'partial') { $file = $this->path.$this->theme.DS.'views'.DS.$folder.DS.$name.'.html'; return File::is($file); } public function info($name = null, $frontend_only = false) { $theme = is_null($name) ? $this->theme : $name; if ($frontend_only) { if ($file = $this->findThemeFile($theme, 'theme.info')) { return $this->parseThemeInfo($file); } } else { if (File::is($this->path.$theme.DS.'info.php')) { return require $this->path.$theme.DS.'info.php'; } elseif (File::is($this->path.$theme.DS.'theme.info')) { return $this->parseThemeInfo($this->path.$theme.DS.'theme.info'); } } throw new FileNotFoundException("info.php", 'theme '.$theme); } public function config($name = null, $frontend_only = false) { $theme = is_null($name) ? $this->theme : $name; if ($frontend_only) { if ($file = $this->findThemeFile($theme, 'config.php')) { return $file; } } else { if (File::is($this->path.$theme.DS.'config.php')) { return require $this->path.$theme.DS.'config.php'; } } throw new FileNotFoundException("config.php", 'theme '.$theme); } public function option($name = null, $frontend_only = false) { $theme = is_null($name) ? $this->theme : $name; if ($frontend_only) { if ($file = $this->findThemeFile($theme, 'options.php')) { return $file; } } else { if (File::is($this->path.$theme.DS.'options.php')) { return require $this->path.$theme.DS.'options.php'; } } return null; } public function findWidgets($name = null) { $theme = is_null($name) ? $this->theme : $name; $path = $this->findTheme($theme); if (!Dir::is($path.DS.'widgets')) { return array(); } $all = Dir::get($path.DS.'widgets'.DS.'*', GLOB_ONLYDIR); return $all; } protected function parseThemeInfo($file) { $info_parser = $this->app->info_parser; return $info_parser->parse($file); } protected function findThemeFile($theme, $filename) { $paths = $this->getThemeFolderPaths($theme); foreach ($paths as $path) { if (File::is($path) and File::is($path.$filename)) { return $path.$filename; } } return null; } protected function getThemeFolderPaths($theme = null) { $private = Str::endIs(THEMES.$theme.DS, DS); $shared = Str::endIs(SHARED.'themes'.DS.$theme.DS, DS); return array($private, $shared); } } 

 namespace Reborn\MVC\View; use Reborn\Cores\Facade; use Reborn\Module\ModuleManager as Module; use Reborn\Exception\FileNotFoundException; class Template { protected $defaultKeys = array( 'title' => 'layoutTitle', 'body' => 'layoutBody', 'headStyle' => 'headerStyle', 'headStyleInline' => 'headerStyleInline', 'footerStyle' => 'footerStyle', 'footerStyleInline' => 'footerStyleInline', 'headScript' => 'headerScript', 'headScriptInline' => 'headerScriptInline', 'footerScript' => 'footerScript', 'footerScriptInline'=> 'footerScriptInline', 'metadata' => 'metadata', 'breadcrumb' => 'breadcrumbs' ); protected $view; protected $theme; protected $partial; protected $layout = "default"; protected $layout404 = '404'; protected $maintain = 'maintain'; protected $error = 'production-error'; protected $ext = '.php'; protected $path; protected $themePath; protected $partialFolder = 'partial'; protected $layoutFolder = 'layout'; protected $useLayout = true; protected $layoutTitle; protected $style = array(); protected $inlineStyles = array(); protected $script = array(); protected $inlineScripts = array(); protected $jsVars = array(); protected $metadata = array(); protected $breadcrumb = array(); public function __construct(Theme $theme, View $view, $ext) { $this->view = $view; $this->theme = $theme; $this->ext = $ext; $this->path = $this->theme->getThemePath().'views'.DS; return $this; } public function getPath() { return $this->path; } public function getExt() { return $this->ext; } public function getPartialPath() { return $this->path.$this->partialFolder.DS; } public function findFile($file, $type = 'partial') { if ($type == 'partial') { $folder = $this->partialFolder; } elseif ($type == 'layout') { $folder = $this->layoutFolder; } else { $folder = $type; } $file = $file.$this->ext; if (file_exists($this->path.$folder.DS.$file)) { return $this->path.$folder.DS.$file; } return false; } public function setLayout($layout) { $layout = str_replace(array('\\', '/'), DS, $layout); $this->layout = $layout; return $this; } public function view($partial, $data = array()) { $partial = str_replace(array('\\', '/'), DS, $partial); $this->partial = $partial; if (! empty($data)) { $this->set($data); } return $this; } public function setPartial($partial, $data = array()) { return $this->view($partial, $data); } public function set($key, $value = null) { $this->view->set($key, $value); return $this; } public function title($title) { $this->layoutTitle = $title; return $this; } public function style($files = array(), $module = null, $place = 'header') { if (! is_array($files)) { $files = (array) $files; } foreach ($files as $file) { $this->style[$place][] = array('file' => $file, 'module' => $module); } return $this; } public function inlineStyle($styles, $place = 'header') { $this->inlineStyles[$place][] = $styles; return $this; } public function script($files = array(), $module = null, $place = 'header') { if (! is_array($files)) { $files = (array) $files; } foreach ($files as $file) { $this->script[$place][] = array('file' => $file, 'module' => $module); } return $this; } public function inlineScript($scripts, $place = 'header') { $this->inlineScripts[$place][] = $scripts; return $this; } public function jsValue($key, $value = null) { if (is_array($key)) { foreach ($key as $name => $value) { $this->jsVars[$name] = $value; } } else { $this->jsVars[$key] = $value; } return $this; } public function metadata($name, $content, $type = 'meta') { $name = htmlspecialchars(strip_tags($name)); $content = htmlspecialchars(strip_tags($content)); if ($name == 'keywords' AND ! strpos($content, ',')) { $content = preg_replace('/[\s]+/', ', ', trim($content)); } switch ($type) { case 'meta': case 'twitter': $this->metadata[$name] = ''; break; case 'og': $this->metadata[$name] = ''; break; case 'link': $this->metadata[$name] = ''; break; } return $this; } public function breadcrumb($label, $uri = null) { $this->breadcrumb[$label] = $uri; return $this; } public function partialOnly() { $this->useLayout = false; return $this; } public function render() { if (!is_null($this->partial)) { $mainContent = $this->partialRender(); } else { $mainContent = ''; } if ($this->useLayout) { $this->setLayoutVariables(); $this->view->set($this->defaultKeys['body'], $mainContent); $mainContent = $this->layoutRender(); } return $mainContent; } public function render404($message = null) { if (file_exists($this->path.$this->layout404.$this->ext)) { $file = $this->path.$this->layout404.$this->ext; } else { $file = APP.'views'.DS.'404.php'; } $this->view->set('clueless', $message); return $this->view->render($file); } public function renderMaintain($message = null) { if (file_exists($this->path.$this->maintain.$this->ext)) { $file = $this->path.$this->maintain.$this->ext; } else { $file = APP.'views'.DS.$this->maintain.'.php'; } $this->view->set('maintain', $message); return $this->view->render($file); } public function renderProductionError() { if (file_exists($this->path.$this->error.$this->ext)) { $file = $this->path.$this->error.$this->ext; } else { $file = APP.'views'.DS.$this->error.'.php'; } return $this->view->render($file); } public function partialRender($partial = null) { if (is_null($partial)) { $partial = $this->partial; } if (false !== strpos($partial, "::")) { list($module, $file) = $this->keyParse($partial); } else { $file = $partial; $module = $this->getModule(); } $file = str_replace(array('\\', '/', '.'), DS, $file); $filename = $file.$this->ext; $modPath = $this->getModulePath($module); $modFormTheme = strtolower($module); if (file_exists($this->path.$modFormTheme.DS.$filename)) { $file = $this->path.$modFormTheme.DS.$filename; } elseif (file_exists($modPath.$filename)) { $file = $modPath.$filename; } elseif (file_exists($this->path.$this->partialFolder.DS.$filename)) { $file = $this->path.$this->partialFolder.DS.$filename; } else { throw new FileNotFoundException($filename, 'Relative'); } if (! empty($this->jsVars)) { if (! $this->useLayout) { $this->view->set('js_var', $this->compileJsVars('')); } } return $this->view->render($file); } protected function layoutRender() { $file = $this->path.$this->layoutFolder.DS.$this->layout.$this->ext; if (file_exists($file)) { return $this->view->render($file); } else { throw new FileNotFoundException($this->layout.$this->ext, $this->path.$this->layoutFolder); } } protected function setLayoutVariables() { $headStyle = $this->getAssetTag('header', 'style'); $footerStyle = $this->getAssetTag('footer', 'style'); $headScript = $this->getAssetTag('header', 'script'); $footerScript = $this->getAssetTag('footer', 'script'); $headStyleInline = $this->getInlineStyleString('header'); $footerStyleInline = $this->getInlineStyleString('footer'); $headScriptInline = $this->getInlineScriptString('header'); $footerScriptInline = $this->getInlineScriptString('footer'); $metadata = $this->getMetadataString(); if (! empty($this->jsVars) ) { $headScript = $this->compileJsVars($headScript); } $data = array( $this->defaultKeys['title'] => $this->layoutTitle, $this->defaultKeys['headStyle'] => $headStyle, $this->defaultKeys['headStyleInline'] => $headStyleInline, $this->defaultKeys['headScript'] => $headScript, $this->defaultKeys['headScriptInline'] => $headScriptInline, $this->defaultKeys['footerStyle'] => $footerStyle, $this->defaultKeys['footerStyleInline'] => $footerStyleInline, $this->defaultKeys['footerScript'] => $footerScript, $this->defaultKeys['footerScriptInline'] => $footerScriptInline, $this->defaultKeys['metadata'] => $metadata, $this->defaultKeys['breadcrumb'] => $this->breadcrumb ); $this->view->set($data); } protected function compileJsVars($scripts) { $vars = ""; return $vars."\n".$scripts; } protected function getAssetTag($place, $type) { $files = isset($this->{$type}[$place]) ? $this->{$type}[$place] : array(); $res = \Event::call('reborn.template.'.$type.'.render.'.$place, array($files)); if (! empty($res[0])) { $files = $res[0]; } if (count($files) == 0) { return null; } $url = ''; foreach ($files as $file) { if (is_null($file['module'])) { $url .= $file['file'].','; } else { $url .= $file['module'].'__'.$file['file'].','; } } $base = defined('ADMIN') ? url('assets/a/') : url('assets'); switch ($type) { case 'style': $url = $base.'/styles/'.rtrim($url, ','); return ''."\n"; break; case 'script': $url = $base.'/scripts/'.rtrim($url, ','); return ''."\n"; break; default: return null; break; } } protected function getInlineScriptString($place) { if (isset($this->inlineScripts[$place])) { if (count($this->inlineScripts[$place]) == 1) { return "\n\t\t\n"; } $scripts = "\n\t\t"; foreach ($this->inlineScripts[$place] as $s) { $scripts .= ''."\n"; } return $scripts; } return null; } protected function getInlineStyleString($place) { if (isset($this->inlineStyles[$place])) { if (count($this->inlineStyles[$place]) == 1) { return "\n\t\t\n"; } $styles = "\n\t\t"; foreach ($this->inlineStyles[$place] as $s) { $styles .= ''."\n"; } return $styles; } return null; } protected function getMetadataString() { if (isset($this->metadata)) { return "\n\t\t".implode("\n\t\t", $this->metadata)."\n"; } return null; } protected function keyParse($key) { $arr = explode('::', $key); return array($arr[0], $arr[1]); } protected function getModule() { $request = Facade::getApplication()->request; return $request->module; } protected function getModulePath($module) { $mod = Module::get($module); return $mod->path.DS.'views'.DS; } public function __set($key, $value) { $this->view->set($key, $value); } } 
Reborn\MVC\View\View::render( ) # Line No. 436
{{ CMS }} » storages/compile.php
 namespace Reborn\MVC\View; use ArrayAccess; use Reborn\Filesystem\File; use Reborn\Exception\FileNotFoundException; class View implements ArrayAccess { protected $data = array(); protected $parser; protected $template; protected $cache; protected $_block; public function __construct($cachePath = null, Block $block = null) { $this->cache = is_null($cachePath) ? STORAGES.'template'.DS : $cachePath; $this->_block = is_null($block) ? new Block : $block; } public function setObject(Parser $parser, Template $template) { $this->parser = $parser; $this->template = $template; } public function getParser() { return $this->parser; } public function render($file) { if (file_exists($file)) { if (\Event::has('reborn.view.before.render')) { $hook_data = \Event::call('reborn.view.before.render'); } $data = $this->data; if ('html' == pathinfo($file, PATHINFO_EXTENSION)) { $file = $this->fileParse($file, $data); } ob_start(); extract($data, EXTR_SKIP); if (isset($hook_data) and !is_null($hook_data)) { foreach ($hook_data as $hook) { if(is_null($hook)) continue; extract($hook, EXTR_SKIP); } } try { include $file; } catch (\Exception $e) { ob_get_clean(); throw $e; } $result = ob_get_clean(); return $result; } else { throw new FileNotFoundException($file, $this->theme); } } public function renderAsStr($template, $data = array()) { $data = $this->data = array_merge($this->data, $data); $contents = $this->parser->parseString($template); ob_start(); extract($data, EXTR_SKIP); try { eval('?>'.$contents); } catch (\Exception $e) { ob_get_clean(); throw $e; } $content = ob_get_clean(); return $content; } public function set($key, $value = null) { if (is_array($key)) { $this->data = array_merge($this->data, $key); } else { $this->data[$key] = $value; } return $this; } protected function includeFile($file) { $file = trim($file, ' '); $file = $this->template->findFile($file); if ($file) { return $this->render($file); } else { return null; } } protected function partialLoop($file, $model = null, $value_name = '_value', $key_name = '_key') { $content = ''; if (!is_array($model) || !is_object($model)) { if (is_null($model)) { return $this->template->partialRender($file); } return $content; } foreach ($model as $key => $value) { $this->data[$key_name] = $key; $this->data[$value_name] = $value; $content .= $this->template->partialRender($file); } return $content; } protected function partialFile($file) { $file = trim($file, ' '); return $this->template->partialRender($file); } protected function fileParse($file, $data) { $cacheFile = $this->cache.md5($file).'.php'; if ($cfile = $this->cacheFileCheck($cacheFile, $file)) { return $cfile; } $fileData = File::getContent($file); $header = "\n"; $filename = '\n"; $content = $this->parser->parse($fileData, $data); File::write($this->cache, md5($file).'.php', $header.$filename.$content); return $cacheFile; } protected function cacheFileCheck($cacheFile, $file) { if (file_exists($cacheFile)) { if ($this->isModified($cacheFile, $file)) { File::delete($cacheFile); return false; } return $cacheFile; } return false; } protected function isModified($cacheFile, $file) { $time = filemtime($file); $cacheTime = filemtime($cacheFile); return $time > $cacheTime; } public function __set($key, $value) { $this->set($key, $value); } public function __get($key) { return $this->data[$key]; } public function __toString() { $this->render(); } public function offsetSet($key, $value) { $this->set($key, $value); } public function offsetGet($key) { return isset($this->data[$key]) ? $this->data[$key] : null; } public function offsetExists($key) { return isset($this->data[$key]) ? true : false; } public function offsetUnset($key) { unset($this->data[$key]); } } 

 namespace Reborn\MVC\View; use Reborn\Util\Str; use Reborn\Cores\Application; use Reborn\Filesystem\File; use Reborn\Filesystem\Directory as Dir; use Reborn\Exception\FileNotFoundException; class Theme { protected $theme; protected $path; protected $app; public function __construct(Application $app, $name, $path) { $this->app = $app; $this->theme = $name; $this->path = $path; } public function all($name_only = false) { $paths = $this->getThemeFolderPaths(); $all = array(); $type = 'private'; foreach ($paths as $path) { $all[$type] = Dir::get($path.'*', GLOB_ONLYDIR); $type = 'shared'; } if ($name_only) { $names = array(); foreach ($all as $type => $paths) { foreach ($paths as $path) { $names[] = basename($path); } } return $names; } return $all; } public function findTheme($theme) { $paths = $this->getThemeFolderPaths($theme); foreach ($paths as $path) { if (Dir::is($path)) { return $path; } } return null; } public function setPath($path) { $this->path = $path; } public function getThemePath() { if (! Dir::is($this->path.$this->theme)) { throw new \Exception("{$this->theme} folder doesn't exists in {$this->path}"); } return $this->path.$this->theme.DS; } public function getLayouts() { $path = $this->path.$this->theme.DS.'views'.DS.'layout'.DS; $layouts = array(); $all = glob($path.'*.html'); foreach ($all as $file) { $layouts[] = str_replace($path, '', $file); } return $layouts; } public function layoutsFrom($name) { $path = $this->findTheme($name); $layouts = array(); if (is_null($path)) return $layouts; $all = glob($path.'views'.DS.'layout'.DS.'*.html'); foreach ($all as $s) { $layouts[] = str_replace($path.'views'.DS.'layout'.DS, '', $s); } return $layouts; } public function hasLayout($name) { $file = $this->path.$this->theme.DS.'views'.DS.'layout'.DS.$name.'.html'; return File::is($file); } public function hasFile($name, $folder = 'partial') { $file = $this->path.$this->theme.DS.'views'.DS.$folder.DS.$name.'.html'; return File::is($file); } public function info($name = null, $frontend_only = false) { $theme = is_null($name) ? $this->theme : $name; if ($frontend_only) { if ($file = $this->findThemeFile($theme, 'theme.info')) { return $this->parseThemeInfo($file); } } else { if (File::is($this->path.$theme.DS.'info.php')) { return require $this->path.$theme.DS.'info.php'; } elseif (File::is($this->path.$theme.DS.'theme.info')) { return $this->parseThemeInfo($this->path.$theme.DS.'theme.info'); } } throw new FileNotFoundException("info.php", 'theme '.$theme); } public function config($name = null, $frontend_only = false) { $theme = is_null($name) ? $this->theme : $name; if ($frontend_only) { if ($file = $this->findThemeFile($theme, 'config.php')) { return $file; } } else { if (File::is($this->path.$theme.DS.'config.php')) { return require $this->path.$theme.DS.'config.php'; } } throw new FileNotFoundException("config.php", 'theme '.$theme); } public function option($name = null, $frontend_only = false) { $theme = is_null($name) ? $this->theme : $name; if ($frontend_only) { if ($file = $this->findThemeFile($theme, 'options.php')) { return $file; } } else { if (File::is($this->path.$theme.DS.'options.php')) { return require $this->path.$theme.DS.'options.php'; } } return null; } public function findWidgets($name = null) { $theme = is_null($name) ? $this->theme : $name; $path = $this->findTheme($theme); if (!Dir::is($path.DS.'widgets')) { return array(); } $all = Dir::get($path.DS.'widgets'.DS.'*', GLOB_ONLYDIR); return $all; } protected function parseThemeInfo($file) { $info_parser = $this->app->info_parser; return $info_parser->parse($file); } protected function findThemeFile($theme, $filename) { $paths = $this->getThemeFolderPaths($theme); foreach ($paths as $path) { if (File::is($path) and File::is($path.$filename)) { return $path.$filename; } } return null; } protected function getThemeFolderPaths($theme = null) { $private = Str::endIs(THEMES.$theme.DS, DS); $shared = Str::endIs(SHARED.'themes'.DS.$theme.DS, DS); return array($private, $shared); } } 

 namespace Reborn\MVC\View; use Reborn\Cores\Facade; use Reborn\Module\ModuleManager as Module; use Reborn\Exception\FileNotFoundException; class Template { protected $defaultKeys = array( 'title' => 'layoutTitle', 'body' => 'layoutBody', 'headStyle' => 'headerStyle', 'headStyleInline' => 'headerStyleInline', 'footerStyle' => 'footerStyle', 'footerStyleInline' => 'footerStyleInline', 'headScript' => 'headerScript', 'headScriptInline' => 'headerScriptInline', 'footerScript' => 'footerScript', 'footerScriptInline'=> 'footerScriptInline', 'metadata' => 'metadata', 'breadcrumb' => 'breadcrumbs' ); protected $view; protected $theme; protected $partial; protected $layout = "default"; protected $layout404 = '404'; protected $maintain = 'maintain'; protected $error = 'production-error'; protected $ext = '.php'; protected $path; protected $themePath; protected $partialFolder = 'partial'; protected $layoutFolder = 'layout'; protected $useLayout = true; protected $layoutTitle; protected $style = array(); protected $inlineStyles = array(); protected $script = array(); protected $inlineScripts = array(); protected $jsVars = array(); protected $metadata = array(); protected $breadcrumb = array(); public function __construct(Theme $theme, View $view, $ext) { $this->view = $view; $this->theme = $theme; $this->ext = $ext; $this->path = $this->theme->getThemePath().'views'.DS; return $this; } public function getPath() { return $this->path; } public function getExt() { return $this->ext; } public function getPartialPath() { return $this->path.$this->partialFolder.DS; } public function findFile($file, $type = 'partial') { if ($type == 'partial') { $folder = $this->partialFolder; } elseif ($type == 'layout') { $folder = $this->layoutFolder; } else { $folder = $type; } $file = $file.$this->ext; if (file_exists($this->path.$folder.DS.$file)) { return $this->path.$folder.DS.$file; } return false; } public function setLayout($layout) { $layout = str_replace(array('\\', '/'), DS, $layout); $this->layout = $layout; return $this; } public function view($partial, $data = array()) { $partial = str_replace(array('\\', '/'), DS, $partial); $this->partial = $partial; if (! empty($data)) { $this->set($data); } return $this; } public function setPartial($partial, $data = array()) { return $this->view($partial, $data); } public function set($key, $value = null) { $this->view->set($key, $value); return $this; } public function title($title) { $this->layoutTitle = $title; return $this; } public function style($files = array(), $module = null, $place = 'header') { if (! is_array($files)) { $files = (array) $files; } foreach ($files as $file) { $this->style[$place][] = array('file' => $file, 'module' => $module); } return $this; } public function inlineStyle($styles, $place = 'header') { $this->inlineStyles[$place][] = $styles; return $this; } public function script($files = array(), $module = null, $place = 'header') { if (! is_array($files)) { $files = (array) $files; } foreach ($files as $file) { $this->script[$place][] = array('file' => $file, 'module' => $module); } return $this; } public function inlineScript($scripts, $place = 'header') { $this->inlineScripts[$place][] = $scripts; return $this; } public function jsValue($key, $value = null) { if (is_array($key)) { foreach ($key as $name => $value) { $this->jsVars[$name] = $value; } } else { $this->jsVars[$key] = $value; } return $this; } public function metadata($name, $content, $type = 'meta') { $name = htmlspecialchars(strip_tags($name)); $content = htmlspecialchars(strip_tags($content)); if ($name == 'keywords' AND ! strpos($content, ',')) { $content = preg_replace('/[\s]+/', ', ', trim($content)); } switch ($type) { case 'meta': case 'twitter': $this->metadata[$name] = ''; break; case 'og': $this->metadata[$name] = ''; break; case 'link': $this->metadata[$name] = ''; break; } return $this; } public function breadcrumb($label, $uri = null) { $this->breadcrumb[$label] = $uri; return $this; } public function partialOnly() { $this->useLayout = false; return $this; } public function render() { if (!is_null($this->partial)) { $mainContent = $this->partialRender(); } else { $mainContent = ''; } if ($this->useLayout) { $this->setLayoutVariables(); $this->view->set($this->defaultKeys['body'], $mainContent); $mainContent = $this->layoutRender(); } return $mainContent; } public function render404($message = null) { if (file_exists($this->path.$this->layout404.$this->ext)) { $file = $this->path.$this->layout404.$this->ext; } else { $file = APP.'views'.DS.'404.php'; } $this->view->set('clueless', $message); return $this->view->render($file); } public function renderMaintain($message = null) { if (file_exists($this->path.$this->maintain.$this->ext)) { $file = $this->path.$this->maintain.$this->ext; } else { $file = APP.'views'.DS.$this->maintain.'.php'; } $this->view->set('maintain', $message); return $this->view->render($file); } public function renderProductionError() { if (file_exists($this->path.$this->error.$this->ext)) { $file = $this->path.$this->error.$this->ext; } else { $file = APP.'views'.DS.$this->error.'.php'; } return $this->view->render($file); } public function partialRender($partial = null) { if (is_null($partial)) { $partial = $this->partial; } if (false !== strpos($partial, "::")) { list($module, $file) = $this->keyParse($partial); } else { $file = $partial; $module = $this->getModule(); } $file = str_replace(array('\\', '/', '.'), DS, $file); $filename = $file.$this->ext; $modPath = $this->getModulePath($module); $modFormTheme = strtolower($module); if (file_exists($this->path.$modFormTheme.DS.$filename)) { $file = $this->path.$modFormTheme.DS.$filename; } elseif (file_exists($modPath.$filename)) { $file = $modPath.$filename; } elseif (file_exists($this->path.$this->partialFolder.DS.$filename)) { $file = $this->path.$this->partialFolder.DS.$filename; } else { throw new FileNotFoundException($filename, 'Relative'); } if (! empty($this->jsVars)) { if (! $this->useLayout) { $this->view->set('js_var', $this->compileJsVars('')); } } return $this->view->render($file); } protected function layoutRender() { $file = $this->path.$this->layoutFolder.DS.$this->layout.$this->ext; if (file_exists($file)) { return $this->view->render($file); } else { throw new FileNotFoundException($this->layout.$this->ext, $this->path.$this->layoutFolder); } } protected function setLayoutVariables() { $headStyle = $this->getAssetTag('header', 'style'); $footerStyle = $this->getAssetTag('footer', 'style'); $headScript = $this->getAssetTag('header', 'script'); $footerScript = $this->getAssetTag('footer', 'script'); $headStyleInline = $this->getInlineStyleString('header'); $footerStyleInline = $this->getInlineStyleString('footer'); $headScriptInline = $this->getInlineScriptString('header'); $footerScriptInline = $this->getInlineScriptString('footer'); $metadata = $this->getMetadataString(); if (! empty($this->jsVars) ) { $headScript = $this->compileJsVars($headScript); } $data = array( $this->defaultKeys['title'] => $this->layoutTitle, $this->defaultKeys['headStyle'] => $headStyle, $this->defaultKeys['headStyleInline'] => $headStyleInline, $this->defaultKeys['headScript'] => $headScript, $this->defaultKeys['headScriptInline'] => $headScriptInline, $this->defaultKeys['footerStyle'] => $footerStyle, $this->defaultKeys['footerStyleInline'] => $footerStyleInline, $this->defaultKeys['footerScript'] => $footerScript, $this->defaultKeys['footerScriptInline'] => $footerScriptInline, $this->defaultKeys['metadata'] => $metadata, $this->defaultKeys['breadcrumb'] => $this->breadcrumb ); $this->view->set($data); } protected function compileJsVars($scripts) { $vars = ""; return $vars."\n".$scripts; } protected function getAssetTag($place, $type) { $files = isset($this->{$type}[$place]) ? $this->{$type}[$place] : array(); $res = \Event::call('reborn.template.'.$type.'.render.'.$place, array($files)); if (! empty($res[0])) { $files = $res[0]; } if (count($files) == 0) { return null; } $url = ''; foreach ($files as $file) { if (is_null($file['module'])) { $url .= $file['file'].','; } else { $url .= $file['module'].'__'.$file['file'].','; } } $base = defined('ADMIN') ? url('assets/a/') : url('assets'); switch ($type) { case 'style': $url = $base.'/styles/'.rtrim($url, ','); return ''."\n"; break; case 'script': $url = $base.'/scripts/'.rtrim($url, ','); return ''."\n"; break; default: return null; break; } } protected function getInlineScriptString($place) { if (isset($this->inlineScripts[$place])) { if (count($this->inlineScripts[$place]) == 1) { return "\n\t\t\n"; } $scripts = "\n\t\t"; foreach ($this->inlineScripts[$place] as $s) { $scripts .= ''."\n"; } return $scripts; } return null; } protected function getInlineStyleString($place) { if (isset($this->inlineStyles[$place])) { if (count($this->inlineStyles[$place]) == 1) { return "\n\t\t\n"; } $styles = "\n\t\t"; foreach ($this->inlineStyles[$place] as $s) { $styles .= ''."\n"; } return $styles; } return null; } protected function getMetadataString() { if (isset($this->metadata)) { return "\n\t\t".implode("\n\t\t", $this->metadata)."\n"; } return null; } protected function keyParse($key) { $arr = explode('::', $key); return array($arr[0], $arr[1]); } protected function getModule() { $request = Facade::getApplication()->request; return $request->module; } protected function getModulePath($module) { $mod = Module::get($module); return $mod->path.DS.'views'.DS; } public function __set($key, $value) { $this->view->set($key, $value); } } 

 namespace Reborn\MVC\View; class Parser { protected $no_parse_tag = array('{{', '}}', '{#', '#}', '{##', '##}', '{=', '=}', '{@', '@}'); protected $replace_tag = array('7b7b', '7d7d', '7b23', '237d', '7b2323', '23237d', '7b3d', '3d7d', '7b40', '407d',); protected $handlers = array( 'include' => 'handleInclude', 'nav' => 'handleNavigation', 'partial' => 'handlePartial', 'partial_loop' => 'handlePartialLoop', 'loop' => 'handleLoop', 'if' => 'handleIf', 'ifnot' => 'handleIfNot', 'ifempty' => 'handleIfEmpty', 'ifnotempty' => 'handleIfNotEmpty', 'ifset' => 'handleIfIsset', 'ifnotset' => 'handleIfNotIsset', 'elseif' => 'handleElseIf', 'else' => 'handleElse', 'breadcrumb' => 'handleBreadcrumb', 'make' => 'handleMaker' ); protected $addHandlers = array(); protected $data = array(); protected $noparse = array(); public function addHandler($name, $handler) { $this->addHandlers[$name] = $handler; return $this; } public function parse($template, $data) { $this->data = $data; $content = $this->parseString($this->parsePHPTag($template)); return $content; } public function parseString($template) { $template = $this->handleUnParse($template); foreach ($this->addHandlers as $name => $handler) { if ($handler instanceof \Closure) { $template = $handler($template, $this->data); } else { $handler = new $handler($this); if ($handler instanceof AbstractHandler) { $template = $handler->handle($template, $this->data); } } } foreach ($this->handlers as $key => $func) { $pattern = '/(?{$func}($template); } } $template = $this->handleComment($template); $template = $this->handleCodeBlock($template); $template = $this->handleBlock($template); $template = $this->handleEcho($template); $template = $this->handleReParse($template); return $template; } public function splitContent($string, $keyStr = '_main') { $split = array(); if (preg_match('/\"(.*)\"/', $string, $m)) { $esc = str_replace(' ', '~', $m[1]); $string = str_replace($m[1], $esc, $string); } $bits = explode(' ', $string); foreach ($bits as $bit) { if (strpos($bit, ":")) { list($key, $value) = explode(':', $bit); $split[$key] = str_replace('~', ' ', $value); } else { $split[$keyStr] = str_replace('~', ' ', $bit); } } return $split; } protected function parsePHPTag($template) { return str_replace( array(""), array("<?","?>"), $template ); } protected function handleUnParse($template) { if (preg_match_all('/([\s\S]*?)<\/noparse>/m', $template, $match)) { foreach ($match[0] as $k => $m) { $replace = str_replace($this->no_parse_tag, $this->replace_tag, $match[1][$k]); $template = str_replace($m, $replace, $template); } } return $template; } protected function handleReParse($template) { return str_replace($this->replace_tag, $this->no_parse_tag, $template); } protected function handleInclude($template) { $pattern = '/\{\{\s*(include):(.*)\s*\}\}/'; $d = preg_replace($pattern, 'includeFile("$2")$3; ?>', $template); return $d; } protected function handleNavigation($template) { $pattern = '/\{\{\s*(nav):(.*)\s*\}\}/'; $callback = function ($matches) { $arr = explode('.', rtrim($matches[2], ' ')); $nav = array_shift($arr); $str = ''; } else { return $str.', "'.$arr[0].'"); ?>'; } }; return preg_replace_callback($pattern, $callback, $template); } protected function handlePartial($template) { $pattern = '/\{\{\s*(partial):(.*)\s*\}\}/'; $d = preg_replace($pattern, 'partialFile("$2")$3; ?>', $template); return $d; } protected function handlePartialLoop($template) { $pattern = '/\{\{\spartial_loop(\s*\((.*)\))\s\}\}/'; return preg_replace($pattern, 'partialLoop$1; ?>', $template); } protected function handleLoop($template) { $pattern = '/\{\{\s*(loop)(\s*\(.*\))\s*\}\}/'; $d = preg_replace($pattern, '', $template); $d = preg_replace('/\{\{\s*(endloop)\s*\}\}/', '', $d); return $d; } protected function handleIf($template) { $pattern = '/\{\{\s*(if)(\s*\(.*\))\s*\}\}/'; $d = preg_replace($pattern, '', $template); $d = preg_replace('/\{\{\s*(endif)\s*\}\}/', '', $d); return $d; } protected function handleIfNot($template) { $pattern = '/\{\{\s*(ifnot)(\s*\((.*)\))\s*\}\}/'; $d = preg_replace($pattern, '', $template); $d = preg_replace('/\{\{\s*(endif)\s*\}\}/', '', $d); return $d; } protected function handleIfEmpty($template) { $pattern = '/\{\{\s*(ifempty)(\s*\((.*)\))\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleIfNotEmpty($template) { $pattern = '/\{\{\s*(ifnotempty)(\s*\((.*)\))\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleIfIsset($template) { $pattern = '/\{\{\s*(ifset)(\s*\((.*)\))\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleIfNotIsset($template) { $pattern = '/\{\{\s*(ifnotset)(\s*\((.*)\))\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleElseIf($template) { $pattern = '/\{\{\s*(elseif)(\s*\(.*\))\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleElse($template) { $pattern = '/\{\{\s*(else)\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleBreadcrumb($template) { $pattern = '/\{\{\sbreadcrumb\s\}\}/'; $replace = '
             $url) : ?>
                
Reborn\MVC\View\Template::layoutRender( ) # Line No. 436
{{ CMS }} » storages/compile.php
 namespace Reborn\MVC\View; use ArrayAccess; use Reborn\Filesystem\File; use Reborn\Exception\FileNotFoundException; class View implements ArrayAccess { protected $data = array(); protected $parser; protected $template; protected $cache; protected $_block; public function __construct($cachePath = null, Block $block = null) { $this->cache = is_null($cachePath) ? STORAGES.'template'.DS : $cachePath; $this->_block = is_null($block) ? new Block : $block; } public function setObject(Parser $parser, Template $template) { $this->parser = $parser; $this->template = $template; } public function getParser() { return $this->parser; } public function render($file) { if (file_exists($file)) { if (\Event::has('reborn.view.before.render')) { $hook_data = \Event::call('reborn.view.before.render'); } $data = $this->data; if ('html' == pathinfo($file, PATHINFO_EXTENSION)) { $file = $this->fileParse($file, $data); } ob_start(); extract($data, EXTR_SKIP); if (isset($hook_data) and !is_null($hook_data)) { foreach ($hook_data as $hook) { if(is_null($hook)) continue; extract($hook, EXTR_SKIP); } } try { include $file; } catch (\Exception $e) { ob_get_clean(); throw $e; } $result = ob_get_clean(); return $result; } else { throw new FileNotFoundException($file, $this->theme); } } public function renderAsStr($template, $data = array()) { $data = $this->data = array_merge($this->data, $data); $contents = $this->parser->parseString($template); ob_start(); extract($data, EXTR_SKIP); try { eval('?>'.$contents); } catch (\Exception $e) { ob_get_clean(); throw $e; } $content = ob_get_clean(); return $content; } public function set($key, $value = null) { if (is_array($key)) { $this->data = array_merge($this->data, $key); } else { $this->data[$key] = $value; } return $this; } protected function includeFile($file) { $file = trim($file, ' '); $file = $this->template->findFile($file); if ($file) { return $this->render($file); } else { return null; } } protected function partialLoop($file, $model = null, $value_name = '_value', $key_name = '_key') { $content = ''; if (!is_array($model) || !is_object($model)) { if (is_null($model)) { return $this->template->partialRender($file); } return $content; } foreach ($model as $key => $value) { $this->data[$key_name] = $key; $this->data[$value_name] = $value; $content .= $this->template->partialRender($file); } return $content; } protected function partialFile($file) { $file = trim($file, ' '); return $this->template->partialRender($file); } protected function fileParse($file, $data) { $cacheFile = $this->cache.md5($file).'.php'; if ($cfile = $this->cacheFileCheck($cacheFile, $file)) { return $cfile; } $fileData = File::getContent($file); $header = "\n"; $filename = '\n"; $content = $this->parser->parse($fileData, $data); File::write($this->cache, md5($file).'.php', $header.$filename.$content); return $cacheFile; } protected function cacheFileCheck($cacheFile, $file) { if (file_exists($cacheFile)) { if ($this->isModified($cacheFile, $file)) { File::delete($cacheFile); return false; } return $cacheFile; } return false; } protected function isModified($cacheFile, $file) { $time = filemtime($file); $cacheTime = filemtime($cacheFile); return $time > $cacheTime; } public function __set($key, $value) { $this->set($key, $value); } public function __get($key) { return $this->data[$key]; } public function __toString() { $this->render(); } public function offsetSet($key, $value) { $this->set($key, $value); } public function offsetGet($key) { return isset($this->data[$key]) ? $this->data[$key] : null; } public function offsetExists($key) { return isset($this->data[$key]) ? true : false; } public function offsetUnset($key) { unset($this->data[$key]); } } 

 namespace Reborn\MVC\View; use Reborn\Util\Str; use Reborn\Cores\Application; use Reborn\Filesystem\File; use Reborn\Filesystem\Directory as Dir; use Reborn\Exception\FileNotFoundException; class Theme { protected $theme; protected $path; protected $app; public function __construct(Application $app, $name, $path) { $this->app = $app; $this->theme = $name; $this->path = $path; } public function all($name_only = false) { $paths = $this->getThemeFolderPaths(); $all = array(); $type = 'private'; foreach ($paths as $path) { $all[$type] = Dir::get($path.'*', GLOB_ONLYDIR); $type = 'shared'; } if ($name_only) { $names = array(); foreach ($all as $type => $paths) { foreach ($paths as $path) { $names[] = basename($path); } } return $names; } return $all; } public function findTheme($theme) { $paths = $this->getThemeFolderPaths($theme); foreach ($paths as $path) { if (Dir::is($path)) { return $path; } } return null; } public function setPath($path) { $this->path = $path; } public function getThemePath() { if (! Dir::is($this->path.$this->theme)) { throw new \Exception("{$this->theme} folder doesn't exists in {$this->path}"); } return $this->path.$this->theme.DS; } public function getLayouts() { $path = $this->path.$this->theme.DS.'views'.DS.'layout'.DS; $layouts = array(); $all = glob($path.'*.html'); foreach ($all as $file) { $layouts[] = str_replace($path, '', $file); } return $layouts; } public function layoutsFrom($name) { $path = $this->findTheme($name); $layouts = array(); if (is_null($path)) return $layouts; $all = glob($path.'views'.DS.'layout'.DS.'*.html'); foreach ($all as $s) { $layouts[] = str_replace($path.'views'.DS.'layout'.DS, '', $s); } return $layouts; } public function hasLayout($name) { $file = $this->path.$this->theme.DS.'views'.DS.'layout'.DS.$name.'.html'; return File::is($file); } public function hasFile($name, $folder = 'partial') { $file = $this->path.$this->theme.DS.'views'.DS.$folder.DS.$name.'.html'; return File::is($file); } public function info($name = null, $frontend_only = false) { $theme = is_null($name) ? $this->theme : $name; if ($frontend_only) { if ($file = $this->findThemeFile($theme, 'theme.info')) { return $this->parseThemeInfo($file); } } else { if (File::is($this->path.$theme.DS.'info.php')) { return require $this->path.$theme.DS.'info.php'; } elseif (File::is($this->path.$theme.DS.'theme.info')) { return $this->parseThemeInfo($this->path.$theme.DS.'theme.info'); } } throw new FileNotFoundException("info.php", 'theme '.$theme); } public function config($name = null, $frontend_only = false) { $theme = is_null($name) ? $this->theme : $name; if ($frontend_only) { if ($file = $this->findThemeFile($theme, 'config.php')) { return $file; } } else { if (File::is($this->path.$theme.DS.'config.php')) { return require $this->path.$theme.DS.'config.php'; } } throw new FileNotFoundException("config.php", 'theme '.$theme); } public function option($name = null, $frontend_only = false) { $theme = is_null($name) ? $this->theme : $name; if ($frontend_only) { if ($file = $this->findThemeFile($theme, 'options.php')) { return $file; } } else { if (File::is($this->path.$theme.DS.'options.php')) { return require $this->path.$theme.DS.'options.php'; } } return null; } public function findWidgets($name = null) { $theme = is_null($name) ? $this->theme : $name; $path = $this->findTheme($theme); if (!Dir::is($path.DS.'widgets')) { return array(); } $all = Dir::get($path.DS.'widgets'.DS.'*', GLOB_ONLYDIR); return $all; } protected function parseThemeInfo($file) { $info_parser = $this->app->info_parser; return $info_parser->parse($file); } protected function findThemeFile($theme, $filename) { $paths = $this->getThemeFolderPaths($theme); foreach ($paths as $path) { if (File::is($path) and File::is($path.$filename)) { return $path.$filename; } } return null; } protected function getThemeFolderPaths($theme = null) { $private = Str::endIs(THEMES.$theme.DS, DS); $shared = Str::endIs(SHARED.'themes'.DS.$theme.DS, DS); return array($private, $shared); } } 

 namespace Reborn\MVC\View; use Reborn\Cores\Facade; use Reborn\Module\ModuleManager as Module; use Reborn\Exception\FileNotFoundException; class Template { protected $defaultKeys = array( 'title' => 'layoutTitle', 'body' => 'layoutBody', 'headStyle' => 'headerStyle', 'headStyleInline' => 'headerStyleInline', 'footerStyle' => 'footerStyle', 'footerStyleInline' => 'footerStyleInline', 'headScript' => 'headerScript', 'headScriptInline' => 'headerScriptInline', 'footerScript' => 'footerScript', 'footerScriptInline'=> 'footerScriptInline', 'metadata' => 'metadata', 'breadcrumb' => 'breadcrumbs' ); protected $view; protected $theme; protected $partial; protected $layout = "default"; protected $layout404 = '404'; protected $maintain = 'maintain'; protected $error = 'production-error'; protected $ext = '.php'; protected $path; protected $themePath; protected $partialFolder = 'partial'; protected $layoutFolder = 'layout'; protected $useLayout = true; protected $layoutTitle; protected $style = array(); protected $inlineStyles = array(); protected $script = array(); protected $inlineScripts = array(); protected $jsVars = array(); protected $metadata = array(); protected $breadcrumb = array(); public function __construct(Theme $theme, View $view, $ext) { $this->view = $view; $this->theme = $theme; $this->ext = $ext; $this->path = $this->theme->getThemePath().'views'.DS; return $this; } public function getPath() { return $this->path; } public function getExt() { return $this->ext; } public function getPartialPath() { return $this->path.$this->partialFolder.DS; } public function findFile($file, $type = 'partial') { if ($type == 'partial') { $folder = $this->partialFolder; } elseif ($type == 'layout') { $folder = $this->layoutFolder; } else { $folder = $type; } $file = $file.$this->ext; if (file_exists($this->path.$folder.DS.$file)) { return $this->path.$folder.DS.$file; } return false; } public function setLayout($layout) { $layout = str_replace(array('\\', '/'), DS, $layout); $this->layout = $layout; return $this; } public function view($partial, $data = array()) { $partial = str_replace(array('\\', '/'), DS, $partial); $this->partial = $partial; if (! empty($data)) { $this->set($data); } return $this; } public function setPartial($partial, $data = array()) { return $this->view($partial, $data); } public function set($key, $value = null) { $this->view->set($key, $value); return $this; } public function title($title) { $this->layoutTitle = $title; return $this; } public function style($files = array(), $module = null, $place = 'header') { if (! is_array($files)) { $files = (array) $files; } foreach ($files as $file) { $this->style[$place][] = array('file' => $file, 'module' => $module); } return $this; } public function inlineStyle($styles, $place = 'header') { $this->inlineStyles[$place][] = $styles; return $this; } public function script($files = array(), $module = null, $place = 'header') { if (! is_array($files)) { $files = (array) $files; } foreach ($files as $file) { $this->script[$place][] = array('file' => $file, 'module' => $module); } return $this; } public function inlineScript($scripts, $place = 'header') { $this->inlineScripts[$place][] = $scripts; return $this; } public function jsValue($key, $value = null) { if (is_array($key)) { foreach ($key as $name => $value) { $this->jsVars[$name] = $value; } } else { $this->jsVars[$key] = $value; } return $this; } public function metadata($name, $content, $type = 'meta') { $name = htmlspecialchars(strip_tags($name)); $content = htmlspecialchars(strip_tags($content)); if ($name == 'keywords' AND ! strpos($content, ',')) { $content = preg_replace('/[\s]+/', ', ', trim($content)); } switch ($type) { case 'meta': case 'twitter': $this->metadata[$name] = ''; break; case 'og': $this->metadata[$name] = ''; break; case 'link': $this->metadata[$name] = ''; break; } return $this; } public function breadcrumb($label, $uri = null) { $this->breadcrumb[$label] = $uri; return $this; } public function partialOnly() { $this->useLayout = false; return $this; } public function render() { if (!is_null($this->partial)) { $mainContent = $this->partialRender(); } else { $mainContent = ''; } if ($this->useLayout) { $this->setLayoutVariables(); $this->view->set($this->defaultKeys['body'], $mainContent); $mainContent = $this->layoutRender(); } return $mainContent; } public function render404($message = null) { if (file_exists($this->path.$this->layout404.$this->ext)) { $file = $this->path.$this->layout404.$this->ext; } else { $file = APP.'views'.DS.'404.php'; } $this->view->set('clueless', $message); return $this->view->render($file); } public function renderMaintain($message = null) { if (file_exists($this->path.$this->maintain.$this->ext)) { $file = $this->path.$this->maintain.$this->ext; } else { $file = APP.'views'.DS.$this->maintain.'.php'; } $this->view->set('maintain', $message); return $this->view->render($file); } public function renderProductionError() { if (file_exists($this->path.$this->error.$this->ext)) { $file = $this->path.$this->error.$this->ext; } else { $file = APP.'views'.DS.$this->error.'.php'; } return $this->view->render($file); } public function partialRender($partial = null) { if (is_null($partial)) { $partial = $this->partial; } if (false !== strpos($partial, "::")) { list($module, $file) = $this->keyParse($partial); } else { $file = $partial; $module = $this->getModule(); } $file = str_replace(array('\\', '/', '.'), DS, $file); $filename = $file.$this->ext; $modPath = $this->getModulePath($module); $modFormTheme = strtolower($module); if (file_exists($this->path.$modFormTheme.DS.$filename)) { $file = $this->path.$modFormTheme.DS.$filename; } elseif (file_exists($modPath.$filename)) { $file = $modPath.$filename; } elseif (file_exists($this->path.$this->partialFolder.DS.$filename)) { $file = $this->path.$this->partialFolder.DS.$filename; } else { throw new FileNotFoundException($filename, 'Relative'); } if (! empty($this->jsVars)) { if (! $this->useLayout) { $this->view->set('js_var', $this->compileJsVars('')); } } return $this->view->render($file); } protected function layoutRender() { $file = $this->path.$this->layoutFolder.DS.$this->layout.$this->ext; if (file_exists($file)) { return $this->view->render($file); } else { throw new FileNotFoundException($this->layout.$this->ext, $this->path.$this->layoutFolder); } } protected function setLayoutVariables() { $headStyle = $this->getAssetTag('header', 'style'); $footerStyle = $this->getAssetTag('footer', 'style'); $headScript = $this->getAssetTag('header', 'script'); $footerScript = $this->getAssetTag('footer', 'script'); $headStyleInline = $this->getInlineStyleString('header'); $footerStyleInline = $this->getInlineStyleString('footer'); $headScriptInline = $this->getInlineScriptString('header'); $footerScriptInline = $this->getInlineScriptString('footer'); $metadata = $this->getMetadataString(); if (! empty($this->jsVars) ) { $headScript = $this->compileJsVars($headScript); } $data = array( $this->defaultKeys['title'] => $this->layoutTitle, $this->defaultKeys['headStyle'] => $headStyle, $this->defaultKeys['headStyleInline'] => $headStyleInline, $this->defaultKeys['headScript'] => $headScript, $this->defaultKeys['headScriptInline'] => $headScriptInline, $this->defaultKeys['footerStyle'] => $footerStyle, $this->defaultKeys['footerStyleInline'] => $footerStyleInline, $this->defaultKeys['footerScript'] => $footerScript, $this->defaultKeys['footerScriptInline'] => $footerScriptInline, $this->defaultKeys['metadata'] => $metadata, $this->defaultKeys['breadcrumb'] => $this->breadcrumb ); $this->view->set($data); } protected function compileJsVars($scripts) { $vars = ""; return $vars."\n".$scripts; } protected function getAssetTag($place, $type) { $files = isset($this->{$type}[$place]) ? $this->{$type}[$place] : array(); $res = \Event::call('reborn.template.'.$type.'.render.'.$place, array($files)); if (! empty($res[0])) { $files = $res[0]; } if (count($files) == 0) { return null; } $url = ''; foreach ($files as $file) { if (is_null($file['module'])) { $url .= $file['file'].','; } else { $url .= $file['module'].'__'.$file['file'].','; } } $base = defined('ADMIN') ? url('assets/a/') : url('assets'); switch ($type) { case 'style': $url = $base.'/styles/'.rtrim($url, ','); return ''."\n"; break; case 'script': $url = $base.'/scripts/'.rtrim($url, ','); return ''."\n"; break; default: return null; break; } } protected function getInlineScriptString($place) { if (isset($this->inlineScripts[$place])) { if (count($this->inlineScripts[$place]) == 1) { return "\n\t\t\n"; } $scripts = "\n\t\t"; foreach ($this->inlineScripts[$place] as $s) { $scripts .= ''."\n"; } return $scripts; } return null; } protected function getInlineStyleString($place) { if (isset($this->inlineStyles[$place])) { if (count($this->inlineStyles[$place]) == 1) { return "\n\t\t\n"; } $styles = "\n\t\t"; foreach ($this->inlineStyles[$place] as $s) { $styles .= ''."\n"; } return $styles; } return null; } protected function getMetadataString() { if (isset($this->metadata)) { return "\n\t\t".implode("\n\t\t", $this->metadata)."\n"; } return null; } protected function keyParse($key) { $arr = explode('::', $key); return array($arr[0], $arr[1]); } protected function getModule() { $request = Facade::getApplication()->request; return $request->module; } protected function getModulePath($module) { $mod = Module::get($module); return $mod->path.DS.'views'.DS; } public function __set($key, $value) { $this->view->set($key, $value); } } 

 namespace Reborn\MVC\View; class Parser { protected $no_parse_tag = array('{{', '}}', '{#', '#}', '{##', '##}', '{=', '=}', '{@', '@}'); protected $replace_tag = array('7b7b', '7d7d', '7b23', '237d', '7b2323', '23237d', '7b3d', '3d7d', '7b40', '407d',); protected $handlers = array( 'include' => 'handleInclude', 'nav' => 'handleNavigation', 'partial' => 'handlePartial', 'partial_loop' => 'handlePartialLoop', 'loop' => 'handleLoop', 'if' => 'handleIf', 'ifnot' => 'handleIfNot', 'ifempty' => 'handleIfEmpty', 'ifnotempty' => 'handleIfNotEmpty', 'ifset' => 'handleIfIsset', 'ifnotset' => 'handleIfNotIsset', 'elseif' => 'handleElseIf', 'else' => 'handleElse', 'breadcrumb' => 'handleBreadcrumb', 'make' => 'handleMaker' ); protected $addHandlers = array(); protected $data = array(); protected $noparse = array(); public function addHandler($name, $handler) { $this->addHandlers[$name] = $handler; return $this; } public function parse($template, $data) { $this->data = $data; $content = $this->parseString($this->parsePHPTag($template)); return $content; } public function parseString($template) { $template = $this->handleUnParse($template); foreach ($this->addHandlers as $name => $handler) { if ($handler instanceof \Closure) { $template = $handler($template, $this->data); } else { $handler = new $handler($this); if ($handler instanceof AbstractHandler) { $template = $handler->handle($template, $this->data); } } } foreach ($this->handlers as $key => $func) { $pattern = '/(?{$func}($template); } } $template = $this->handleComment($template); $template = $this->handleCodeBlock($template); $template = $this->handleBlock($template); $template = $this->handleEcho($template); $template = $this->handleReParse($template); return $template; } public function splitContent($string, $keyStr = '_main') { $split = array(); if (preg_match('/\"(.*)\"/', $string, $m)) { $esc = str_replace(' ', '~', $m[1]); $string = str_replace($m[1], $esc, $string); } $bits = explode(' ', $string); foreach ($bits as $bit) { if (strpos($bit, ":")) { list($key, $value) = explode(':', $bit); $split[$key] = str_replace('~', ' ', $value); } else { $split[$keyStr] = str_replace('~', ' ', $bit); } } return $split; } protected function parsePHPTag($template) { return str_replace( array(""), array("<?","?>"), $template ); } protected function handleUnParse($template) { if (preg_match_all('/([\s\S]*?)<\/noparse>/m', $template, $match)) { foreach ($match[0] as $k => $m) { $replace = str_replace($this->no_parse_tag, $this->replace_tag, $match[1][$k]); $template = str_replace($m, $replace, $template); } } return $template; } protected function handleReParse($template) { return str_replace($this->replace_tag, $this->no_parse_tag, $template); } protected function handleInclude($template) { $pattern = '/\{\{\s*(include):(.*)\s*\}\}/'; $d = preg_replace($pattern, 'includeFile("$2")$3; ?>', $template); return $d; } protected function handleNavigation($template) { $pattern = '/\{\{\s*(nav):(.*)\s*\}\}/'; $callback = function ($matches) { $arr = explode('.', rtrim($matches[2], ' ')); $nav = array_shift($arr); $str = ''; } else { return $str.', "'.$arr[0].'"); ?>'; } }; return preg_replace_callback($pattern, $callback, $template); } protected function handlePartial($template) { $pattern = '/\{\{\s*(partial):(.*)\s*\}\}/'; $d = preg_replace($pattern, 'partialFile("$2")$3; ?>', $template); return $d; } protected function handlePartialLoop($template) { $pattern = '/\{\{\spartial_loop(\s*\((.*)\))\s\}\}/'; return preg_replace($pattern, 'partialLoop$1; ?>', $template); } protected function handleLoop($template) { $pattern = '/\{\{\s*(loop)(\s*\(.*\))\s*\}\}/'; $d = preg_replace($pattern, '', $template); $d = preg_replace('/\{\{\s*(endloop)\s*\}\}/', '', $d); return $d; } protected function handleIf($template) { $pattern = '/\{\{\s*(if)(\s*\(.*\))\s*\}\}/'; $d = preg_replace($pattern, '', $template); $d = preg_replace('/\{\{\s*(endif)\s*\}\}/', '', $d); return $d; } protected function handleIfNot($template) { $pattern = '/\{\{\s*(ifnot)(\s*\((.*)\))\s*\}\}/'; $d = preg_replace($pattern, '', $template); $d = preg_replace('/\{\{\s*(endif)\s*\}\}/', '', $d); return $d; } protected function handleIfEmpty($template) { $pattern = '/\{\{\s*(ifempty)(\s*\((.*)\))\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleIfNotEmpty($template) { $pattern = '/\{\{\s*(ifnotempty)(\s*\((.*)\))\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleIfIsset($template) { $pattern = '/\{\{\s*(ifset)(\s*\((.*)\))\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleIfNotIsset($template) { $pattern = '/\{\{\s*(ifnotset)(\s*\((.*)\))\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleElseIf($template) { $pattern = '/\{\{\s*(elseif)(\s*\(.*\))\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleElse($template) { $pattern = '/\{\{\s*(else)\s*\}\}/'; return preg_replace($pattern, '', $template); } protected function handleBreadcrumb($template) { $pattern = '/\{\{\sbreadcrumb\s\}\}/'; $replace = '
             $url) : ?>
                
Reborn\MVC\View\Template::render( ) # Line No. 414
{{ CMS }} » storages/compile.php
 namespace Reborn\Cache; use Closure; interface CacheDriverInterface { public function set($key, $value, $time = 10080); public function get($key, $default = null); public function solve($key, Closure $callback, $time = 10080); public function has($key); public function delete($key); } 

 namespace Reborn\Cache\Driver; use Closure; use Reborn\Config\Config; use Reborn\Filesystem\File as FileSystem; use Reborn\Filesystem\Directory as Dir; use Reborn\Cache\CacheDriverInterface; use Reborn\Cache\CacheFolderStoreInterface; class File implements CacheDriverInterface, CacheFolderStoreInterface { protected $path; protected $extension = 'cache'; public function __construct($app) { $this->path = $app['config']->get('cache.file.storage_path');; if (!is_dir($this->path)) { $this->createFolder($this->path); } } public function set($key, $value, $time = 10080) { list($filename, $filepath) = $this->keyParse($key); $path = str_replace($filename.'.'.$this->getExtension(), '', $filepath); if (!is_dir($path)) { $this->createFolder($path); } if (file_exists($filepath)) { FileSystem::delete($filepath); } $this->write($path, $filename, $value, $time); } public function get($key, $default = null) { list($filename, $filepath) = $this->keyParse($key); if (file_exists($filepath)) { $data = FileSystem::getContent($filepath); if ($this->checkExpire($data)) { return $this->unserializer(substr($data, 10)); } else { $this->delete($key); } } return value($default); } public function solve($key, Closure $callback, $time = 10080) { $data = $this->get($key); if (! is_null($data) ) { return $data; } $data = $callback(); $this->set($key, $data, $time); return $data; } public function has($key) { if ( is_null($this->get($key)) ) { return false; } return true; } public function delete($key) { list(, $filepath) = $this->keyParse($key); return FileSystem::delete($filepath); } public function deleteFolder($folder) { return Dir::delete($this->path.$folder); } public function setPath($path) { $this->path = $path; } public function getPath() { return $this->path; } public function setExtension($ext) { $this->extension = $ext; return $this; } public function getExtension() { return $this->extension; } protected function keyParse($key) { if (false !== strpos($key, '::')) { list($folder, $key) = explode('::', $key); } $key = md5($key); if (isset($folder)) { $file = $this->path.$folder.DS.$key.'.'.$this->getExtension(); } else { $file = $this->path.$key.'.'.$this->getExtension(); } return array($key, $file); } protected function write($path, $filename, $value, $time) { $value = $this->serializer($value); $expire = time() + ($time * 60); FileSystem::put($path.$filename.'.'.$this->getExtension(), $expire.$value); @chmod($path.$filename.'.'.$this->getExtension(), 0777); } protected function checkExpire($data) { $time = substr($data, 0, 10); return ($time > time()); } protected function serializer($data) { return serialize($data); } protected function unserializer($data) { return unserialize($data); } protected function createFolder($path) { return (Dir::make($path, 0777, true)) ? true : false; } } 

 namespace Reborn\MVC\Controller; use Reborn\Cores\Application; use Reborn\Http\Response; use Reborn\Exception\HttpNotFoundException; use Reborn\MVC\Controller\Exception\NotAuthException; use Reborn\MVC\Controller\Exception\NotAdminAccessException; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; class Controller { protected $app; protected $request = null; protected $template = null; protected $theme = null; protected $session = null; protected $HTTPstatus = 200; protected $Etag = false; protected $format = 'html'; protected function init() {} public function before() {} public function after($response) { if ($this->request->inner and !$response) { $this->request->inner = false; $response = $this->template->partialRender(); } if (is_null($response)) { $response = $this->template->render(); } if (! $response instanceof SymfonyResponse) { $response = Response::make($response, $this->HTTPstatus); $response->prepare($this->app['request']); $response = $this->app->injectCSRFToken($response); } if ($this->Etag) { $response->setEtag(md5($response->getContent())); } return $response; } protected function get($name) { return $this->app->{$name}; } protected function jsValue($key, $value = null) { $this->template->jsValue($key, $value); } protected function returnJson($data, $status = 200, $headers = array()) { return $this->json($data, $status, $headers); } protected function json($data, $status = 200, $headers = array()) { return Response::json($data, $status, $headers, 'json'); } protected function stream($callback, $status = 200, $headers = array()) { return Response::stream($callback, $status, $headers, 'stream'); } public function actionCaller(Application $app, $method, $params) { $this->app = $app; $this->variablesAssign(); \Event::call('reborn.controller.process.starting', array($this, $method)); try { $this->init(); } catch (NotAuthException $e) { throw $e; } catch (NotAdminAccessException $e) { throw $e; } $this->before(); if (! method_exists($this, $method)) { return $this->notFound(); } try { $response = call_user_func_array(array($this, $method), (array) $params); } catch (\Exception $e) { if ($this->app['env'] == 'dev') { throw $e; } else { throw new HttpNotFoundException("Request params doesn't match for method!"); } } $response = $this->after($response); \Event::call('reborn.controller.process.ending', array($response)); return $response; } protected function param($name, $default = null) { if (isset($this->request->params[$name]) and $this->request->params[$name] != '') { return $this->request->params[$name]; } return $default; } protected function variablesAssign() { $app = $this->app; $this->request = $app['request']; $this->session = $app['session']; $this->template = $app['template']; $this->theme = $app['theme']; switch ($this->request->getRequestFormat()) { case 'json': $this->format = 'json'; break; case 'xml': $this->format = 'xml'; break; case 'csv': $this->format = 'csv'; break; case 'html': default: $this->format = 'html'; break; } } protected function setLayout($name) { $this->template->setLayout($name); } protected function flash($key, $value) { $this->session->getFlashBag()->set($key, $value); } protected function notFound($message = null) { return Response::clueless($message); } protected function parse($template, $data = array()) { $view = $this->app['view']; return $view->renderAsStr($template, $data); } protected function setHTTPstatus($code) { $realCode = Response::$statusTexts; if (isset($realCode[$code])) { $this->HTTPstatus = $code; } } } 

 namespace Reborn\MVC\Controller; use Auth, Flash, Module, Translate; use Reborn\Cores\Setting; use Reborn\Http\Redirect; use Reborn\MVC\Controller\Exception\NotAuthException; use Reborn\MVC\Controller\Exception\NotAdminAccessException; class AdminController extends Controller { protected $module; protected $menu; protected function init() { if (! defined('ADMIN')) { define('ADMIN', true); } if (! defined('ADMIN_URL')) { define('ADMIN_URL', $this->getAdminLink()); } $lang = $this->app->session->get('reborn_dashboard_language', 'en'); $this->app->setLocale($lang); Translate::load('label'); Translate::load('global'); Translate::load('navigation'); $this->template->rebornVersion = \Reborn\Cores\Version::FULL; $this->template->rebornUrl = \Reborn\Cores\Version::URL; $this->checkAuthentication(); $this->module = $this->request->module; $this->varSetter(); if (Auth::check()) { $user = Auth::getUser(); if (!$user->hasAccess(strtolower($this->request->module))) { throw new NotAuthException(); } } } public function after($response) { return parent::after($response); } protected function getAdminLink() { $db = Setting::get('adminpanel_url'); $config = $this->app['config']->get('app.adminpanel'); if ($db != $config) { $this->app['config']->set('app.adminpanel', $db); } return $this->app['config']->get('app.adminpanel'); } protected function checkAuthentication() { $allow = array(ADMIN_URL.'/login', ADMIN_URL.'/logout'); $current = rtrim(implode('/', \Uri::segments()), '/'); if (!Auth::check()) { if (in_array($current, $allow)) { return true; } throw new NotAuthException(); } else { $user = Auth::getUser(); if ( ! $user->hasAccess('admin')) { Auth::logout(); Flash::error(t('global.not_ap_access')); throw new NotAdminAccessException(); } return true; } return true; } protected function varSetter() { $this->template->adminUrl = ADMIN_URL; $this->template->adminMenus = $this->getMenu(); $lang = $this->app->session->get('reborn_dashboard_language', 'en'); $this->template->lang = $lang; $user = Auth::getUser(); $this->template->login_user = $user; $this->template->siteTitle = Setting::get('site_title'); $toolbar = Module::moduleToolbar($this->module); $this->template->set('modToolbar', $toolbar); $module = Module::get($this->module); $this->template->set('module', $module); $start_year = '2012'; $end_year = date('Y'); $cp_right = t('global.rb_copyright'); if ($start_year == $end_year) { $copyright = $cp_right.$end_year; } else { $copyright = $cp_right.$start_year.' - '.$end_year; } $this->template->copyRight = $copyright; } protected function getMenu() { $this->menu = new \Reborn\Util\Menu(); return $this->menu; } } 

 namespace Reborn\MVC\Controller; use Reborn\Cores\Version; use Reborn\Http\Uri; class PublicController extends Controller { protected function init() { if (! defined('PUBLIC')) { define('PUBLIC', true); } $module_layout = strtolower($this->request->module); if ($this->theme->hasLayout($module_layout)) { $this->setLayout($module_layout); } $this->template->metadata('canonical', Uri::current(), 'link'); $this->template->metadata('generator', Version::NAME.' - '.Version::FULL , 'meta'); } public function after($response) { return parent::after($response); } } 
Reborn\MVC\Controller\Controller::after( ) # Line No. 418
{{ CMS }} » storages/compile.php
 namespace Reborn\MVC\Controller; use Reborn\Cores\Application; use Reborn\Http\Response; use Reborn\Exception\HttpNotFoundException; use Reborn\MVC\Controller\Exception\NotAuthException; use Reborn\MVC\Controller\Exception\NotAdminAccessException; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; class Controller { protected $app; protected $request = null; protected $template = null; protected $theme = null; protected $session = null; protected $HTTPstatus = 200; protected $Etag = false; protected $format = 'html'; protected function init() {} public function before() {} public function after($response) { if ($this->request->inner and !$response) { $this->request->inner = false; $response = $this->template->partialRender(); } if (is_null($response)) { $response = $this->template->render(); } if (! $response instanceof SymfonyResponse) { $response = Response::make($response, $this->HTTPstatus); $response->prepare($this->app['request']); $response = $this->app->injectCSRFToken($response); } if ($this->Etag) { $response->setEtag(md5($response->getContent())); } return $response; } protected function get($name) { return $this->app->{$name}; } protected function jsValue($key, $value = null) { $this->template->jsValue($key, $value); } protected function returnJson($data, $status = 200, $headers = array()) { return $this->json($data, $status, $headers); } protected function json($data, $status = 200, $headers = array()) { return Response::json($data, $status, $headers, 'json'); } protected function stream($callback, $status = 200, $headers = array()) { return Response::stream($callback, $status, $headers, 'stream'); } public function actionCaller(Application $app, $method, $params) { $this->app = $app; $this->variablesAssign(); \Event::call('reborn.controller.process.starting', array($this, $method)); try { $this->init(); } catch (NotAuthException $e) { throw $e; } catch (NotAdminAccessException $e) { throw $e; } $this->before(); if (! method_exists($this, $method)) { return $this->notFound(); } try { $response = call_user_func_array(array($this, $method), (array) $params); } catch (\Exception $e) { if ($this->app['env'] == 'dev') { throw $e; } else { throw new HttpNotFoundException("Request params doesn't match for method!"); } } $response = $this->after($response); \Event::call('reborn.controller.process.ending', array($response)); return $response; } protected function param($name, $default = null) { if (isset($this->request->params[$name]) and $this->request->params[$name] != '') { return $this->request->params[$name]; } return $default; } protected function variablesAssign() { $app = $this->app; $this->request = $app['request']; $this->session = $app['session']; $this->template = $app['template']; $this->theme = $app['theme']; switch ($this->request->getRequestFormat()) { case 'json': $this->format = 'json'; break; case 'xml': $this->format = 'xml'; break; case 'csv': $this->format = 'csv'; break; case 'html': default: $this->format = 'html'; break; } } protected function setLayout($name) { $this->template->setLayout($name); } protected function flash($key, $value) { $this->session->getFlashBag()->set($key, $value); } protected function notFound($message = null) { return Response::clueless($message); } protected function parse($template, $data = array()) { $view = $this->app['view']; return $view->renderAsStr($template, $data); } protected function setHTTPstatus($code) { $realCode = Response::$statusTexts; if (isset($realCode[$code])) { $this->HTTPstatus = $code; } } } 

 namespace Reborn\MVC\Controller; use Auth, Flash, Module, Translate; use Reborn\Cores\Setting; use Reborn\Http\Redirect; use Reborn\MVC\Controller\Exception\NotAuthException; use Reborn\MVC\Controller\Exception\NotAdminAccessException; class AdminController extends Controller { protected $module; protected $menu; protected function init() { if (! defined('ADMIN')) { define('ADMIN', true); } if (! defined('ADMIN_URL')) { define('ADMIN_URL', $this->getAdminLink()); } $lang = $this->app->session->get('reborn_dashboard_language', 'en'); $this->app->setLocale($lang); Translate::load('label'); Translate::load('global'); Translate::load('navigation'); $this->template->rebornVersion = \Reborn\Cores\Version::FULL; $this->template->rebornUrl = \Reborn\Cores\Version::URL; $this->checkAuthentication(); $this->module = $this->request->module; $this->varSetter(); if (Auth::check()) { $user = Auth::getUser(); if (!$user->hasAccess(strtolower($this->request->module))) { throw new NotAuthException(); } } } public function after($response) { return parent::after($response); } protected function getAdminLink() { $db = Setting::get('adminpanel_url'); $config = $this->app['config']->get('app.adminpanel'); if ($db != $config) { $this->app['config']->set('app.adminpanel', $db); } return $this->app['config']->get('app.adminpanel'); } protected function checkAuthentication() { $allow = array(ADMIN_URL.'/login', ADMIN_URL.'/logout'); $current = rtrim(implode('/', \Uri::segments()), '/'); if (!Auth::check()) { if (in_array($current, $allow)) { return true; } throw new NotAuthException(); } else { $user = Auth::getUser(); if ( ! $user->hasAccess('admin')) { Auth::logout(); Flash::error(t('global.not_ap_access')); throw new NotAdminAccessException(); } return true; } return true; } protected function varSetter() { $this->template->adminUrl = ADMIN_URL; $this->template->adminMenus = $this->getMenu(); $lang = $this->app->session->get('reborn_dashboard_language', 'en'); $this->template->lang = $lang; $user = Auth::getUser(); $this->template->login_user = $user; $this->template->siteTitle = Setting::get('site_title'); $toolbar = Module::moduleToolbar($this->module); $this->template->set('modToolbar', $toolbar); $module = Module::get($this->module); $this->template->set('module', $module); $start_year = '2012'; $end_year = date('Y'); $cp_right = t('global.rb_copyright'); if ($start_year == $end_year) { $copyright = $cp_right.$end_year; } else { $copyright = $cp_right.$start_year.' - '.$end_year; } $this->template->copyRight = $copyright; } protected function getMenu() { $this->menu = new \Reborn\Util\Menu(); return $this->menu; } } 

 namespace Reborn\MVC\Controller; use Reborn\Cores\Version; use Reborn\Http\Uri; class PublicController extends Controller { protected function init() { if (! defined('PUBLIC')) { define('PUBLIC', true); } $module_layout = strtolower($this->request->module); if ($this->theme->hasLayout($module_layout)) { $this->setLayout($module_layout); } $this->template->metadata('canonical', Uri::current(), 'link'); $this->template->metadata('generator', Version::NAME.' - '.Version::FULL , 'meta'); } public function after($response) { return parent::after($response); } } 

 namespace Reborn\MVC\Controller; use Auth; use Reborn\Http\Redirect; class PrivateController extends PublicController { protected function init() { parent::init(); $this->checkAuthentication(); } protected function checkAuthentication() { if (!Auth::check()) { return Redirect::to('login'); } else { $this->template->loggedin_user = Auth::getUser(); } return true; } } 

 namespace Reborn\MVC\Controller\Exception; class NotAdminAccessException extends NotAuthException { public function __construct($code=NULL) { parent::__construct("You don't have permission for admin panel!", 401); } } 
Reborn\MVC\Controller\PublicController::after( ) # Line No. 135
{{ CMS }} » heart/modules/pages/src/Pages/Controller/PagesController.php
        }
    }

    public function after($response)
    {
        return parent::after($response);
    }
}
Pages\Controller\PagesController::after( ) # Line No. 414
{{ CMS }} » storages/compile.php
 namespace Reborn\Cache; use Closure; interface CacheDriverInterface { public function set($key, $value, $time = 10080); public function get($key, $default = null); public function solve($key, Closure $callback, $time = 10080); public function has($key); public function delete($key); } 

 namespace Reborn\Cache\Driver; use Closure; use Reborn\Config\Config; use Reborn\Filesystem\File as FileSystem; use Reborn\Filesystem\Directory as Dir; use Reborn\Cache\CacheDriverInterface; use Reborn\Cache\CacheFolderStoreInterface; class File implements CacheDriverInterface, CacheFolderStoreInterface { protected $path; protected $extension = 'cache'; public function __construct($app) { $this->path = $app['config']->get('cache.file.storage_path');; if (!is_dir($this->path)) { $this->createFolder($this->path); } } public function set($key, $value, $time = 10080) { list($filename, $filepath) = $this->keyParse($key); $path = str_replace($filename.'.'.$this->getExtension(), '', $filepath); if (!is_dir($path)) { $this->createFolder($path); } if (file_exists($filepath)) { FileSystem::delete($filepath); } $this->write($path, $filename, $value, $time); } public function get($key, $default = null) { list($filename, $filepath) = $this->keyParse($key); if (file_exists($filepath)) { $data = FileSystem::getContent($filepath); if ($this->checkExpire($data)) { return $this->unserializer(substr($data, 10)); } else { $this->delete($key); } } return value($default); } public function solve($key, Closure $callback, $time = 10080) { $data = $this->get($key); if (! is_null($data) ) { return $data; } $data = $callback(); $this->set($key, $data, $time); return $data; } public function has($key) { if ( is_null($this->get($key)) ) { return false; } return true; } public function delete($key) { list(, $filepath) = $this->keyParse($key); return FileSystem::delete($filepath); } public function deleteFolder($folder) { return Dir::delete($this->path.$folder); } public function setPath($path) { $this->path = $path; } public function getPath() { return $this->path; } public function setExtension($ext) { $this->extension = $ext; return $this; } public function getExtension() { return $this->extension; } protected function keyParse($key) { if (false !== strpos($key, '::')) { list($folder, $key) = explode('::', $key); } $key = md5($key); if (isset($folder)) { $file = $this->path.$folder.DS.$key.'.'.$this->getExtension(); } else { $file = $this->path.$key.'.'.$this->getExtension(); } return array($key, $file); } protected function write($path, $filename, $value, $time) { $value = $this->serializer($value); $expire = time() + ($time * 60); FileSystem::put($path.$filename.'.'.$this->getExtension(), $expire.$value); @chmod($path.$filename.'.'.$this->getExtension(), 0777); } protected function checkExpire($data) { $time = substr($data, 0, 10); return ($time > time()); } protected function serializer($data) { return serialize($data); } protected function unserializer($data) { return unserialize($data); } protected function createFolder($path) { return (Dir::make($path, 0777, true)) ? true : false; } } 

 namespace Reborn\MVC\Controller; use Reborn\Cores\Application; use Reborn\Http\Response; use Reborn\Exception\HttpNotFoundException; use Reborn\MVC\Controller\Exception\NotAuthException; use Reborn\MVC\Controller\Exception\NotAdminAccessException; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; class Controller { protected $app; protected $request = null; protected $template = null; protected $theme = null; protected $session = null; protected $HTTPstatus = 200; protected $Etag = false; protected $format = 'html'; protected function init() {} public function before() {} public function after($response) { if ($this->request->inner and !$response) { $this->request->inner = false; $response = $this->template->partialRender(); } if (is_null($response)) { $response = $this->template->render(); } if (! $response instanceof SymfonyResponse) { $response = Response::make($response, $this->HTTPstatus); $response->prepare($this->app['request']); $response = $this->app->injectCSRFToken($response); } if ($this->Etag) { $response->setEtag(md5($response->getContent())); } return $response; } protected function get($name) { return $this->app->{$name}; } protected function jsValue($key, $value = null) { $this->template->jsValue($key, $value); } protected function returnJson($data, $status = 200, $headers = array()) { return $this->json($data, $status, $headers); } protected function json($data, $status = 200, $headers = array()) { return Response::json($data, $status, $headers, 'json'); } protected function stream($callback, $status = 200, $headers = array()) { return Response::stream($callback, $status, $headers, 'stream'); } public function actionCaller(Application $app, $method, $params) { $this->app = $app; $this->variablesAssign(); \Event::call('reborn.controller.process.starting', array($this, $method)); try { $this->init(); } catch (NotAuthException $e) { throw $e; } catch (NotAdminAccessException $e) { throw $e; } $this->before(); if (! method_exists($this, $method)) { return $this->notFound(); } try { $response = call_user_func_array(array($this, $method), (array) $params); } catch (\Exception $e) { if ($this->app['env'] == 'dev') { throw $e; } else { throw new HttpNotFoundException("Request params doesn't match for method!"); } } $response = $this->after($response); \Event::call('reborn.controller.process.ending', array($response)); return $response; } protected function param($name, $default = null) { if (isset($this->request->params[$name]) and $this->request->params[$name] != '') { return $this->request->params[$name]; } return $default; } protected function variablesAssign() { $app = $this->app; $this->request = $app['request']; $this->session = $app['session']; $this->template = $app['template']; $this->theme = $app['theme']; switch ($this->request->getRequestFormat()) { case 'json': $this->format = 'json'; break; case 'xml': $this->format = 'xml'; break; case 'csv': $this->format = 'csv'; break; case 'html': default: $this->format = 'html'; break; } } protected function setLayout($name) { $this->template->setLayout($name); } protected function flash($key, $value) { $this->session->getFlashBag()->set($key, $value); } protected function notFound($message = null) { return Response::clueless($message); } protected function parse($template, $data = array()) { $view = $this->app['view']; return $view->renderAsStr($template, $data); } protected function setHTTPstatus($code) { $realCode = Response::$statusTexts; if (isset($realCode[$code])) { $this->HTTPstatus = $code; } } } 

 namespace Reborn\MVC\Controller; use Auth, Flash, Module, Translate; use Reborn\Cores\Setting; use Reborn\Http\Redirect; use Reborn\MVC\Controller\Exception\NotAuthException; use Reborn\MVC\Controller\Exception\NotAdminAccessException; class AdminController extends Controller { protected $module; protected $menu; protected function init() { if (! defined('ADMIN')) { define('ADMIN', true); } if (! defined('ADMIN_URL')) { define('ADMIN_URL', $this->getAdminLink()); } $lang = $this->app->session->get('reborn_dashboard_language', 'en'); $this->app->setLocale($lang); Translate::load('label'); Translate::load('global'); Translate::load('navigation'); $this->template->rebornVersion = \Reborn\Cores\Version::FULL; $this->template->rebornUrl = \Reborn\Cores\Version::URL; $this->checkAuthentication(); $this->module = $this->request->module; $this->varSetter(); if (Auth::check()) { $user = Auth::getUser(); if (!$user->hasAccess(strtolower($this->request->module))) { throw new NotAuthException(); } } } public function after($response) { return parent::after($response); } protected function getAdminLink() { $db = Setting::get('adminpanel_url'); $config = $this->app['config']->get('app.adminpanel'); if ($db != $config) { $this->app['config']->set('app.adminpanel', $db); } return $this->app['config']->get('app.adminpanel'); } protected function checkAuthentication() { $allow = array(ADMIN_URL.'/login', ADMIN_URL.'/logout'); $current = rtrim(implode('/', \Uri::segments()), '/'); if (!Auth::check()) { if (in_array($current, $allow)) { return true; } throw new NotAuthException(); } else { $user = Auth::getUser(); if ( ! $user->hasAccess('admin')) { Auth::logout(); Flash::error(t('global.not_ap_access')); throw new NotAdminAccessException(); } return true; } return true; } protected function varSetter() { $this->template->adminUrl = ADMIN_URL; $this->template->adminMenus = $this->getMenu(); $lang = $this->app->session->get('reborn_dashboard_language', 'en'); $this->template->lang = $lang; $user = Auth::getUser(); $this->template->login_user = $user; $this->template->siteTitle = Setting::get('site_title'); $toolbar = Module::moduleToolbar($this->module); $this->template->set('modToolbar', $toolbar); $module = Module::get($this->module); $this->template->set('module', $module); $start_year = '2012'; $end_year = date('Y'); $cp_right = t('global.rb_copyright'); if ($start_year == $end_year) { $copyright = $cp_right.$end_year; } else { $copyright = $cp_right.$start_year.' - '.$end_year; } $this->template->copyRight = $copyright; } protected function getMenu() { $this->menu = new \Reborn\Util\Menu(); return $this->menu; } } 

 namespace Reborn\MVC\Controller; use Reborn\Cores\Version; use Reborn\Http\Uri; class PublicController extends Controller { protected function init() { if (! defined('PUBLIC')) { define('PUBLIC', true); } $module_layout = strtolower($this->request->module); if ($this->theme->hasLayout($module_layout)) { $this->setLayout($module_layout); } $this->template->metadata('canonical', Uri::current(), 'link'); $this->template->metadata('generator', Version::NAME.' - '.Version::FULL , 'meta'); } public function after($response) { return parent::after($response); } } 
Reborn\MVC\Controller\Controller::actionCaller( ) # Line No. 200
{{ CMS }} » storages/compile.php
 namespace Reborn\Routing; use Reborn\Cores\Facade; class RouteFacade extends Facade { public static function getInstance() { return static::$app['route_collection']; } public static function middleware($name, $callback) { Middleware::register($name, $callback); } } 

 namespace Reborn\Routing; use Reborn\Http\Request; use Reborn\Exception\NotImplementedException; class Middleware { protected static $middlwares = array(); public static function register($name, $callback) { static::$middlwares[$name] = $callback; } public static function run($name, Request $request, Route $route) { list($name, $param) = static::callbackAndParams($name); if (! isset(static::$middlwares[$name]) ) { return null; } $callback = static::$middlwares[$name]; if (is_string($callback)) { $ins = new $callback; if ( ! $ins instanceof MiddlewareInterface) { $msg = "Middleware instance [$callback] must be implement of MiddlewareInterface"; throw new NotImplementedException($msg); } return $ins->run($request, $route, $param); } return $callback($request, $route, $param); } protected static function callbackAndParams($name) { if (false === strpos($name, ':')) { return array($name, array()); } $lists = explode(':', $name, 2); $data = explode(',', $lists[1]); $params = array(); foreach ($data as $d) { list($k, $v) = explode('=', $d); $params[$k] = $v; } return array($lists[0], $params); } } 

 namespace Reborn\Routing; use Reborn\Cores\Application; use Reborn\Http\Response; use Reborn\Exception\HttpNotFoundException; class ControllerResolver { protected $app; protected $request; protected $route; public function __construct(Application $app, Route $route) { $this->app = $app; $this->request = $app->request; $this->route = $route; } public function resolve() { list($module, $controller, $action, $params) = $this->prepareFromRoute(); \Module::load($module); if (class_exists($controller)) { $response = $this->route->runBeforeMiddlewares($this->request); if ($response instanceof Response) { return $response; } $this->makeRequestBodyId(); return $this->callController($module, $controller, $action, $params); } else { throw new HttpNotFoundException("Request Class is not found!"); } } protected function makeRequestBodyId() { $module = $this->route->module; $ctrl = str_replace('\\', '-', $this->route->controller); $action = $this->route->action; $id = strtolower($module.'-'.$ctrl.'-'.$action); $this->app['var.body_id'] = $id; } protected function prepareFromRoute() { $module = $this->route->module; $controller = '\\'.$module.'\Controller\\'.$this->route->controller.'Controller'; $action = $this->route->action; $params = $this->route->params; $this->checkActionIsActionCaller($action); $this->setRequestParameters($module, $controller, $action, $params); return array($module, $controller, $action, $params); } protected function checkActionIsActionCaller($action) { if ('actionCaller' === $action) { throw new HttpNotFoundException("Request Method is not callable method!"); } } protected function setRequestParameters($module, $controller, $action, $params) { $this->request->module = $module; $this->request->controller = $controller; $this->request->action = $action; $this->request->params = $params; } protected function callController($module, $controller, $action, $params) { \Module::boot($module); $instance = $this->app->make($controller); $args = $this->makeRequestParameters($instance, $action, $params); return $instance->actionCaller($this->app, $action, $args); } protected function makeRequestParameters($obj, $method, $params) { try { $r = new \ReflectionMethod($obj, $method); } catch (\ReflectionException $e) { if ($this->app->runInDevelopment()) { throw $e; } else { throw new HttpNotFoundException($e->getMessage()); } } if (!$r->isPublic()) { throw new \BadMethodCallException("Request action [$method] is not callable!"); } $require = $r->getParameters(); if (empty($require)) return array(); $missing = $args = array(); foreach ($require as $r) { $name = $r->getName(); if (array_key_exists($name, $params)) { $args[$name] = $params[$name]; } elseif ($r->isDefaultValueAvailable()) { $args[$name] = $r->getDefaultValue(); } else { $missing[] = $name; } } if (count($require) !== count($args)) { $missing = implode(', ', $missing); throw new \InvalidArgumentException("Action [$method] required { $missing }' arguments."); } return $args; } } 

 namespace Reborn\Table; use MongoDate; use Carbon\Carbon; use Reborn\Form\Form; class Builder { protected $headers = array(); protected $use_tfoot = false; protected $cols = array(); protected $check_all = false; protected $actions = array(); protected $table_class; protected $table_id; protected $provider; protected $button_type = 'text'; public static function create($options = array()) { return new static($options); } public function __construct($options = array()) { if (isset($options['check_all'])) { $this->check_all = (boolean) $options['check_all']; } if (isset($options['actions'])) { $this->actions($options['actions']); } if (isset($options['class'])) { $this->tableClass($options['class']); } if (isset($options['id'])) { $this->tableId($options['id']); } if (isset($options['provider'])) { $this->provider($options['provider']); } if (isset($options['use_tfoot'])) { $this->use_tfoot = (boolean) $options['use_tfoot']; } if (isset($options['btn_type'])) { $this->actionType($options['btn_type']); } } public function provider($provider) { if (is_object($provider) || is_array($provider)) { $this->provider = $provider; } return $this; } public function tableClass($classes) { $this->table_class = $classes; return $this; } public function tableId($id) { $this->table_id = $id; return $this; } public function actionType($type) { if (in_array($type, array('text', 'icon-text', 'text-icon', 'icon', 'icons-bar'))) { $this->button_type = $type; } return $this; } public function actions($actions = array()) { foreach ($actions as $name => $action) { $this->prepareActionsLink($name, $action); } return $this; } public function action($name, $title, $url = null, $icon = null, $class = null) { $action = array('title' => $title); if (! is_null($url) ) { $action['url'] = $url; } if (! is_null($icon) ) { $action['icon'] = $icon; } if (! is_null($class) ) { $action['btn-class'] = $class; } $this->prepareActionsLink($name, $action); return $this; } protected function prepareActionsLink($name, $options) { $act = array(); $act['title'] = isset($options['title']) ? $options['title'] : ucfirst($name); $act['btn_class'] = isset($options['btn-class']) ? $options['btn-class'] : ''; $act['icon'] = isset($options['icon']) ? $options['icon'] : ''; if (isset($options['url'])) { $url = $options['url']; $act['url'] = $url; $act['key'] = array(); if (preg_match_all('/\[:(\w+)\]/', $url, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $act['key'][] = $match[1]; } } } $act['target'] = isset($options['new_window']) ? (boolean) $options['new_window'] : false; $this->actions[$name] = $act; } public function headers(array $headers) { $this->headers = $headers; return $this; } public function columns($cols = array()) { foreach ($cols as $name => $col) { if (is_array($cols[$name])) { $this->cols[$name]['key'] = isset($col['key']) ? $col['key'] : $name; $this->cols[$name]['type'] = $col['type']; if ($col['type'] == 'date') { $format = isset($col['format']) ? $col['format'] : 'Y-m-d'; $this->cols[$name]['format'] = $format; } } else { $this->cols[$col] = array('key' => $col); } } return $this; } public function isEmpty() { if (is_object($this->provider) and method_exists($this->provider, 'isEmpty')) { return $this->provider->isEmpty(); } return empty($this->provider); } public function build() { if ($this->isEmpty()) { return null; } $result = $this->renderTableOpen(); if (! empty($this->headers) ) { $result .= $this->renderTableHeader(); if ($this->use_tfoot) { $result .= $this->renderTableFooter(); } } $result .= $this->renderTableBody(); $result .= $this->renderTableClose(); return $result; } protected function renderTableOpen() { $id = !is_null($this->table_id) ? ' id="'.$this->table_id.'" ' : ''; $class = !is_null($this->table_class) ? 'class="'.$this->table_class.'"' : ''; return ''."\n"; } protected function renderTableClose() { return '
'."\n"; } protected function renderTableHeader() { $head_row = "\t\n\t\t"; if ($this->check_all) { $head_row .= "\n\t\t\t"; $head_row .= "\n\t\t\t\t"; $head_row .= ''; $head_row .= "\n\t\t\t"; } $head_row .= $this->renderTableTh(); $head_row .="\n\t\t\n\t"; return $head_row; } protected function renderTableFooter() { $foot_row = "\t\n\t\t"; if ($this->check_all) { $foot_row .= "\n\t\t\t"; $foot_row .= "\n\t\t\t\t"; $foot_row .= ''; $foot_row .= "\n\t\t\t"; } $foot_row .= $this->renderTableTh(); $foot_row .="\n\t\t\n\t"; return $foot_row; } protected function renderTableTh() { $total_head = count($this->headers); $total_cols = count($this->cols); $ths = ''; foreach ($this->headers as $key => $value) { if (is_array($value)) { $width = isset($value['width']) ? $value['width'] : 'auto'; $name = isset($value['name']) ? $value['name'] : ''; $ths .= "\n\t\t\t".$name.""; } else { $ths .= "\n\t\t\t".$value.""; } } if (! empty($this->actions) ) { if ($total_head <= $total_cols) { $multi = $total_cols - $total_head; if ($multi == 0) { $multi = 1; } $string = "\n\t\t\t"; $ths .= str_repeat($string, $multi); } } return $ths; } protected function renderTableBody() { $body = "\n\t"; foreach ($this->provider as $key => $data) { $body .= $this->renderTableRow($data, $key); } $body .= "\n\t\n"; return $body; } protected function renderTableRow($data, $key) { $no = $key + 1; $row = "\n\t\t"; if ($this->check_all) { $id = is_array($data) ? $data['id'] : $data->id; $row .= "\n\t\t\t".''; $row .= "\n\t\t\t\t"; $row .= Form::checkbox('action_to[]', $id, false, array('id' => 'action'.$no)); $row .= "\n\t\t\t"; } $row .= $this->renderTableColumn($data); if (! empty($this->actions) ) { $row .= $this->renderActionsColumn($data); } $row .= "\n\t\t"; return $row; } protected function renderTableColumn($data) { $cols = ''; foreach ($this->cols as $k => $col) { $cols .= "\n\t\t\t"; if (isset($col['type']) and ('date' == $col['type'])) { $cols .= $this->getObjectAttributeDateTime($data, $col['key'], $col['format']); } else { $cols .= $this->getObjectAttribute($data, $col['key']); } $cols .= ''; } return $cols; } protected function getObjectAttribute($data, $key) { if (false === strpos($key, '.')) { if (is_object($data)) { return $data->{$key}; } elseif (is_array($data)) { return $data[$key]; } else { return $data; } } $keys = explode('.', $key, 2); return $this->getObjectAttribute($data->{$keys[0]}, $keys[1]); } protected function getObjectAttributeDateTime($data, $key, $format) { $date = is_array($data) ? $data[$key] : $data->{$key}; if ($data instanceof \Eloquent) { return date_format($date, $format); } elseif ($date instanceof MongoDate) { return date($format, $date->sec); } return Carbon::createFromFormat($format, $date)->toDateTimeString(); } protected function renderActionsColumn($data) { $row = "\n\t\t\t"; if ('icons-bar' == $this->button_type) { $row .= '
'; } foreach ($this->actions as $action) { if (isset($action['url'])) { foreach ($action['key'] as $attr) { if (is_array($data)) { $replace = isset($data[$attr]) ? $data[$attr] : null; } else { $replace = $data->{$attr}; } $action['url'] = str_replace( '[:'.$attr.']', $replace, $action['url'] ); } } $row .= $this->getButton($action); } if ('icons-bar' == $this->button_type) { $row .= '
'; } $row .= "\n\t\t\t"; return $row; } protected function getButton($attrs) { $btn = "\n\t\t\t\t"; $btn .= ''; $btn .= "\n\t\t\t\t\t"; $btn .= $this->getButtonData($attrs); $btn .= "\n\t\t\t\t"; return $btn; } protected function getButtonData($attrs) { switch ($this->button_type) { case 'text': return $attrs['title']; break; case 'icon-text': return ''.$attrs['title']; case 'text-icon': return $attrs['title'].''; case 'icon': default: return ''; break; } } } namespace Reborn\Table; use Closure; use Reborn\Util\Str; use Reborn\Util\Html; use Reborn\Http\Input; class DataTable { protected $options = array(); protected $actions = array(); protected $action_prefix; protected $model; protected $custom_query = array(); protected $columns = array(); protected $column_width = array(); protected $column_lists = array(); protected $total; protected $filter_total = 0; protected $need_js = true; protected $css_file; protected $transformers = array(); protected $sort_disable = array(); public static function make($model, $columns = array()) { return new static($model, $columns); } public function __construct($model, $columns = array()) { if (is_string($model)) { $model = new $model(); } $this->model = $model; if (! empty($columns) ) { $this->columns($columns); } } public function query(Closure $callback) { $this->custom_query[] = $callback; return $this; } public function needDatatableJs() { return $this->need_js; } public function skipJsLoader() { $this->need_js = false; return $this; } public function customCss($url) { $this->css_file = $url; return $this; } public function getCustomCss() { return $this->css_file; } public function useCustomCss() { return (!is_null($this->css_file)); } public function columns(array $columns) { foreach ($columns as $name => $label) { $column = array(); $column['name'] = $name; $column['label'] = $label; $this->columns[] = $column; $this->column_lists[$name] = $label; } return $this; } public function unsortable(array $columns) { $this->sort_disable = $columns; return $this; } public function getUnsortable() { $results = array(); if (! empty($this->actions) ) { $results[] = count($this->columns); } foreach ($this->sort_disable as $name) { foreach ($this->columns as $k => $col) { if ($name == $col['name']) { $results[] = $k; break; } } } return json_encode($results); } public function columnWidth(array $width) { $this->column_width = $width; return $this; } public function getColumnWidth($key = null, $default = 'auto') { if (! is_null($key) and isset($this->column_width[$key])) { return $this->column_width[$key]; } if (is_null($key)) { return $this->column_width; } return $default; } public function columnCount() { $total = count($this->column_lists); if (! empty($this->actions) ) { $total = $total + 1; } return $total; } public function transformer($for, Closure $callback) { $this->transformers[$for] = $callback; return $this; } public function options(array $options = array()) { if (! empty($options) ) { $this->options = array_merge($this->options, $options); } return $this; } public function getOption($key = null, $default = null) { if (is_null($key)) { return $this->options; } return array_get($this->options, $key, $default); } public function actions($prefix, $actions) { $this->actions = $actions; $this->action_prefix = $prefix; return $this; } public function hasActions() { return (!empty($this->actions)); } public function getColumns() { return $this->column_lists; } public function isEmpty() { if (is_null($this->total)) { $this->resolveCustomQuery(); $this->total = $this->model->count(); } return ($this->total < 1); } public function build() { if (! empty($this->custom_query) ) { $this->resolveCustomQuery(); } $this->makeFiltering(); $this->makeCounting(); $this->makePaging(); $this->makeOrdering(); return $this->makeRendering(); } public function buildJson() { return json_encode($this->build()); } protected function makeFiltering() { $count = $this->getColumnCount(); if (Input::get('sSearch','') != '') { $this-> makeSearchFiltering($count); } $this->makeColumnFiltering($count); } protected function makeSearchFiltering($count) { $keyword = '%'.Input::get('sSearch').'%'; for ($i=0; $i < $count; $i++) { if (Input::get('bSearchable_'.$i) == "true") { $column = $this->getColumnKeyName($i); if (!is_null($column)) { if ($i === 0) { $this->model = $this->model->where($column, 'like', $keyword); } else { $this->model = $this->model->orWhere($column, 'like', $keyword); } } } } } protected function makeColumnFiltering($count) { for ($i=0; $i < $count; $i++) { if (Input::get('bSearchable_'.$i) == "true" && Input::get('sSearch_'.$i, '') != '') { $column = $this->getColumnKeyName($i); if (!is_null($column)) { if ($i === 0) { $this->model = $this->model->where($column, 'like', $keyword); } else { $this->model = $this->model->andWhere($column, 'like', $keyword); } } } } } protected function makeCounting() { $this->total = $this->model->count(); $model = $this->model; $this->filter_total = (int) $model->count(); } protected function makePaging() { if (!is_null(Input::get('iDisplayStart')) && Input::get('iDisplayLength') != -1) { $this->model = $this->model->skip(Input::get('iDisplayStart')) ->take(Input::get('iDisplayLength',10)); } } protected function makeOrdering() { if (! is_null(Input::get('iSortCol_0')) ) { $total = intval(Input::get('iSortingCols')); for ($i = 0; $i < $total; $i++) { if (Input::get('bSortable_'.intval(Input::get('iSortCol_'.$i))) == "true") { $column = $this->getColumnKeyName(Input::get('iSortCol_'.$i)); $sort_dir = Input::get('sSortDir_'.$i); if (false == strpos($column, '.')) { $this->model = $this->model ->orderBy($column, $sort_dir); } } } } } protected function makeRendering() { $results = $this->getResult(); $output = array( "sEcho" => intval(Input::get('sEcho')), "iTotalRecords" => $this->total, "iTotalDisplayRecords" => $this->filter_total, "aaData" => $results ); return $output; } protected function getResult() { $results = $this->model->get(); $data = array(); $columns = $this->getAllColumnName(); foreach ($results as $result) { $tmp = array(); foreach ($columns as $col) { $tmp[] = $this->getTransformValue($col, $result); } if (! empty($this->actions) ) { $tmp[] = $this->makeActionsColumn($result); } $data[] = $tmp; unset($tmp); } return $data; } protected function resolveCustomQuery() { foreach ($this->custom_query as $query) { $this->model = $query($this->model); } $this->custom_query = array(); } protected function getTransformValue($for, $model) { $list = explode('.', $for); $value = (count($list) == 2) ? $model->{$list[0]}->{$list[1]} : $model->{$list[0]}; if (isset($this->transformers[$for])) { $callback = $this->transformers[$for]; return $callback($value, $model); } return $value; } protected function makeActionsColumn($model) { $view = '
'; foreach ($this->actions as $action) { list($url, $icon, $attrs) = $this->parserActionData($action, $model); $view .= Html::a($url, $icon, $attrs); } return $view.'
'; } protected function parserActionData($action, $model) { $first = substr($action, 0, 1); $explode = explode(':', $action); if ('!' === $first) { $explode[0] = substr($explode[0], 1); $url = rbUrl($this->action_prefix.'/'.$explode[0]).$model->$explode[1]; } else { $url = adminUrl($this->action_prefix.'/'.$explode[0]).$model->$explode[1]; } $icon = isset($explode[2]) ? $explode[2] : $explode[0]; $attrs = array(); $attrs['class'] = ('delete' === $explode[0]) ? 'confirm_delete tipsy-tip' : 'tipsy-tip'; $attrs['title'] = isset($explode[3]) ? $explode[3] : Str::title($explode[0]); return array($url, '', $attrs); } protected function getColumnCount() { return count($this->columns); } protected function getColumnKeyName($key) { if (isset($this->columns[$key])) { return $this->columns[$key]['name']; } return null; } protected function getAllColumnName() { $names = array_map(function ($column) { return $column['name']; }, $this->columns); return $names; } public function __toString() { return $this->build(); } }
Reborn\Routing\ControllerResolver::callController( ) # Line No. 200
{{ CMS }} » storages/compile.php
 namespace Reborn\Routing; use Reborn\Cores\Facade; class RouteFacade extends Facade { public static function getInstance() { return static::$app['route_collection']; } public static function middleware($name, $callback) { Middleware::register($name, $callback); } } 

 namespace Reborn\Routing; use Reborn\Http\Request; use Reborn\Exception\NotImplementedException; class Middleware { protected static $middlwares = array(); public static function register($name, $callback) { static::$middlwares[$name] = $callback; } public static function run($name, Request $request, Route $route) { list($name, $param) = static::callbackAndParams($name); if (! isset(static::$middlwares[$name]) ) { return null; } $callback = static::$middlwares[$name]; if (is_string($callback)) { $ins = new $callback; if ( ! $ins instanceof MiddlewareInterface) { $msg = "Middleware instance [$callback] must be implement of MiddlewareInterface"; throw new NotImplementedException($msg); } return $ins->run($request, $route, $param); } return $callback($request, $route, $param); } protected static function callbackAndParams($name) { if (false === strpos($name, ':')) { return array($name, array()); } $lists = explode(':', $name, 2); $data = explode(',', $lists[1]); $params = array(); foreach ($data as $d) { list($k, $v) = explode('=', $d); $params[$k] = $v; } return array($lists[0], $params); } } 

 namespace Reborn\Routing; use Reborn\Cores\Application; use Reborn\Http\Response; use Reborn\Exception\HttpNotFoundException; class ControllerResolver { protected $app; protected $request; protected $route; public function __construct(Application $app, Route $route) { $this->app = $app; $this->request = $app->request; $this->route = $route; } public function resolve() { list($module, $controller, $action, $params) = $this->prepareFromRoute(); \Module::load($module); if (class_exists($controller)) { $response = $this->route->runBeforeMiddlewares($this->request); if ($response instanceof Response) { return $response; } $this->makeRequestBodyId(); return $this->callController($module, $controller, $action, $params); } else { throw new HttpNotFoundException("Request Class is not found!"); } } protected function makeRequestBodyId() { $module = $this->route->module; $ctrl = str_replace('\\', '-', $this->route->controller); $action = $this->route->action; $id = strtolower($module.'-'.$ctrl.'-'.$action); $this->app['var.body_id'] = $id; } protected function prepareFromRoute() { $module = $this->route->module; $controller = '\\'.$module.'\Controller\\'.$this->route->controller.'Controller'; $action = $this->route->action; $params = $this->route->params; $this->checkActionIsActionCaller($action); $this->setRequestParameters($module, $controller, $action, $params); return array($module, $controller, $action, $params); } protected function checkActionIsActionCaller($action) { if ('actionCaller' === $action) { throw new HttpNotFoundException("Request Method is not callable method!"); } } protected function setRequestParameters($module, $controller, $action, $params) { $this->request->module = $module; $this->request->controller = $controller; $this->request->action = $action; $this->request->params = $params; } protected function callController($module, $controller, $action, $params) { \Module::boot($module); $instance = $this->app->make($controller); $args = $this->makeRequestParameters($instance, $action, $params); return $instance->actionCaller($this->app, $action, $args); } protected function makeRequestParameters($obj, $method, $params) { try { $r = new \ReflectionMethod($obj, $method); } catch (\ReflectionException $e) { if ($this->app->runInDevelopment()) { throw $e; } else { throw new HttpNotFoundException($e->getMessage()); } } if (!$r->isPublic()) { throw new \BadMethodCallException("Request action [$method] is not callable!"); } $require = $r->getParameters(); if (empty($require)) return array(); $missing = $args = array(); foreach ($require as $r) { $name = $r->getName(); if (array_key_exists($name, $params)) { $args[$name] = $params[$name]; } elseif ($r->isDefaultValueAvailable()) { $args[$name] = $r->getDefaultValue(); } else { $missing[] = $name; } } if (count($require) !== count($args)) { $missing = implode(', ', $missing); throw new \InvalidArgumentException("Action [$method] required { $missing }' arguments."); } return $args; } } 

 namespace Reborn\Table; use MongoDate; use Carbon\Carbon; use Reborn\Form\Form; class Builder { protected $headers = array(); protected $use_tfoot = false; protected $cols = array(); protected $check_all = false; protected $actions = array(); protected $table_class; protected $table_id; protected $provider; protected $button_type = 'text'; public static function create($options = array()) { return new static($options); } public function __construct($options = array()) { if (isset($options['check_all'])) { $this->check_all = (boolean) $options['check_all']; } if (isset($options['actions'])) { $this->actions($options['actions']); } if (isset($options['class'])) { $this->tableClass($options['class']); } if (isset($options['id'])) { $this->tableId($options['id']); } if (isset($options['provider'])) { $this->provider($options['provider']); } if (isset($options['use_tfoot'])) { $this->use_tfoot = (boolean) $options['use_tfoot']; } if (isset($options['btn_type'])) { $this->actionType($options['btn_type']); } } public function provider($provider) { if (is_object($provider) || is_array($provider)) { $this->provider = $provider; } return $this; } public function tableClass($classes) { $this->table_class = $classes; return $this; } public function tableId($id) { $this->table_id = $id; return $this; } public function actionType($type) { if (in_array($type, array('text', 'icon-text', 'text-icon', 'icon', 'icons-bar'))) { $this->button_type = $type; } return $this; } public function actions($actions = array()) { foreach ($actions as $name => $action) { $this->prepareActionsLink($name, $action); } return $this; } public function action($name, $title, $url = null, $icon = null, $class = null) { $action = array('title' => $title); if (! is_null($url) ) { $action['url'] = $url; } if (! is_null($icon) ) { $action['icon'] = $icon; } if (! is_null($class) ) { $action['btn-class'] = $class; } $this->prepareActionsLink($name, $action); return $this; } protected function prepareActionsLink($name, $options) { $act = array(); $act['title'] = isset($options['title']) ? $options['title'] : ucfirst($name); $act['btn_class'] = isset($options['btn-class']) ? $options['btn-class'] : ''; $act['icon'] = isset($options['icon']) ? $options['icon'] : ''; if (isset($options['url'])) { $url = $options['url']; $act['url'] = $url; $act['key'] = array(); if (preg_match_all('/\[:(\w+)\]/', $url, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $act['key'][] = $match[1]; } } } $act['target'] = isset($options['new_window']) ? (boolean) $options['new_window'] : false; $this->actions[$name] = $act; } public function headers(array $headers) { $this->headers = $headers; return $this; } public function columns($cols = array()) { foreach ($cols as $name => $col) { if (is_array($cols[$name])) { $this->cols[$name]['key'] = isset($col['key']) ? $col['key'] : $name; $this->cols[$name]['type'] = $col['type']; if ($col['type'] == 'date') { $format = isset($col['format']) ? $col['format'] : 'Y-m-d'; $this->cols[$name]['format'] = $format; } } else { $this->cols[$col] = array('key' => $col); } } return $this; } public function isEmpty() { if (is_object($this->provider) and method_exists($this->provider, 'isEmpty')) { return $this->provider->isEmpty(); } return empty($this->provider); } public function build() { if ($this->isEmpty()) { return null; } $result = $this->renderTableOpen(); if (! empty($this->headers) ) { $result .= $this->renderTableHeader(); if ($this->use_tfoot) { $result .= $this->renderTableFooter(); } } $result .= $this->renderTableBody(); $result .= $this->renderTableClose(); return $result; } protected function renderTableOpen() { $id = !is_null($this->table_id) ? ' id="'.$this->table_id.'" ' : ''; $class = !is_null($this->table_class) ? 'class="'.$this->table_class.'"' : ''; return ''."\n"; } protected function renderTableClose() { return '
'."\n"; } protected function renderTableHeader() { $head_row = "\t\n\t\t"; if ($this->check_all) { $head_row .= "\n\t\t\t"; $head_row .= "\n\t\t\t\t"; $head_row .= ''; $head_row .= "\n\t\t\t"; } $head_row .= $this->renderTableTh(); $head_row .="\n\t\t\n\t"; return $head_row; } protected function renderTableFooter() { $foot_row = "\t\n\t\t"; if ($this->check_all) { $foot_row .= "\n\t\t\t"; $foot_row .= "\n\t\t\t\t"; $foot_row .= ''; $foot_row .= "\n\t\t\t"; } $foot_row .= $this->renderTableTh(); $foot_row .="\n\t\t\n\t"; return $foot_row; } protected function renderTableTh() { $total_head = count($this->headers); $total_cols = count($this->cols); $ths = ''; foreach ($this->headers as $key => $value) { if (is_array($value)) { $width = isset($value['width']) ? $value['width'] : 'auto'; $name = isset($value['name']) ? $value['name'] : ''; $ths .= "\n\t\t\t".$name.""; } else { $ths .= "\n\t\t\t".$value.""; } } if (! empty($this->actions) ) { if ($total_head <= $total_cols) { $multi = $total_cols - $total_head; if ($multi == 0) { $multi = 1; } $string = "\n\t\t\t"; $ths .= str_repeat($string, $multi); } } return $ths; } protected function renderTableBody() { $body = "\n\t"; foreach ($this->provider as $key => $data) { $body .= $this->renderTableRow($data, $key); } $body .= "\n\t\n"; return $body; } protected function renderTableRow($data, $key) { $no = $key + 1; $row = "\n\t\t"; if ($this->check_all) { $id = is_array($data) ? $data['id'] : $data->id; $row .= "\n\t\t\t".''; $row .= "\n\t\t\t\t"; $row .= Form::checkbox('action_to[]', $id, false, array('id' => 'action'.$no)); $row .= "\n\t\t\t"; } $row .= $this->renderTableColumn($data); if (! empty($this->actions) ) { $row .= $this->renderActionsColumn($data); } $row .= "\n\t\t"; return $row; } protected function renderTableColumn($data) { $cols = ''; foreach ($this->cols as $k => $col) { $cols .= "\n\t\t\t"; if (isset($col['type']) and ('date' == $col['type'])) { $cols .= $this->getObjectAttributeDateTime($data, $col['key'], $col['format']); } else { $cols .= $this->getObjectAttribute($data, $col['key']); } $cols .= ''; } return $cols; } protected function getObjectAttribute($data, $key) { if (false === strpos($key, '.')) { if (is_object($data)) { return $data->{$key}; } elseif (is_array($data)) { return $data[$key]; } else { return $data; } } $keys = explode('.', $key, 2); return $this->getObjectAttribute($data->{$keys[0]}, $keys[1]); } protected function getObjectAttributeDateTime($data, $key, $format) { $date = is_array($data) ? $data[$key] : $data->{$key}; if ($data instanceof \Eloquent) { return date_format($date, $format); } elseif ($date instanceof MongoDate) { return date($format, $date->sec); } return Carbon::createFromFormat($format, $date)->toDateTimeString(); } protected function renderActionsColumn($data) { $row = "\n\t\t\t"; if ('icons-bar' == $this->button_type) { $row .= '
'; } foreach ($this->actions as $action) { if (isset($action['url'])) { foreach ($action['key'] as $attr) { if (is_array($data)) { $replace = isset($data[$attr]) ? $data[$attr] : null; } else { $replace = $data->{$attr}; } $action['url'] = str_replace( '[:'.$attr.']', $replace, $action['url'] ); } } $row .= $this->getButton($action); } if ('icons-bar' == $this->button_type) { $row .= '
'; } $row .= "\n\t\t\t"; return $row; } protected function getButton($attrs) { $btn = "\n\t\t\t\t"; $btn .= ''; $btn .= "\n\t\t\t\t\t"; $btn .= $this->getButtonData($attrs); $btn .= "\n\t\t\t\t"; return $btn; } protected function getButtonData($attrs) { switch ($this->button_type) { case 'text': return $attrs['title']; break; case 'icon-text': return ''.$attrs['title']; case 'text-icon': return $attrs['title'].''; case 'icon': default: return ''; break; } } } namespace Reborn\Table; use Closure; use Reborn\Util\Str; use Reborn\Util\Html; use Reborn\Http\Input; class DataTable { protected $options = array(); protected $actions = array(); protected $action_prefix; protected $model; protected $custom_query = array(); protected $columns = array(); protected $column_width = array(); protected $column_lists = array(); protected $total; protected $filter_total = 0; protected $need_js = true; protected $css_file; protected $transformers = array(); protected $sort_disable = array(); public static function make($model, $columns = array()) { return new static($model, $columns); } public function __construct($model, $columns = array()) { if (is_string($model)) { $model = new $model(); } $this->model = $model; if (! empty($columns) ) { $this->columns($columns); } } public function query(Closure $callback) { $this->custom_query[] = $callback; return $this; } public function needDatatableJs() { return $this->need_js; } public function skipJsLoader() { $this->need_js = false; return $this; } public function customCss($url) { $this->css_file = $url; return $this; } public function getCustomCss() { return $this->css_file; } public function useCustomCss() { return (!is_null($this->css_file)); } public function columns(array $columns) { foreach ($columns as $name => $label) { $column = array(); $column['name'] = $name; $column['label'] = $label; $this->columns[] = $column; $this->column_lists[$name] = $label; } return $this; } public function unsortable(array $columns) { $this->sort_disable = $columns; return $this; } public function getUnsortable() { $results = array(); if (! empty($this->actions) ) { $results[] = count($this->columns); } foreach ($this->sort_disable as $name) { foreach ($this->columns as $k => $col) { if ($name == $col['name']) { $results[] = $k; break; } } } return json_encode($results); } public function columnWidth(array $width) { $this->column_width = $width; return $this; } public function getColumnWidth($key = null, $default = 'auto') { if (! is_null($key) and isset($this->column_width[$key])) { return $this->column_width[$key]; } if (is_null($key)) { return $this->column_width; } return $default; } public function columnCount() { $total = count($this->column_lists); if (! empty($this->actions) ) { $total = $total + 1; } return $total; } public function transformer($for, Closure $callback) { $this->transformers[$for] = $callback; return $this; } public function options(array $options = array()) { if (! empty($options) ) { $this->options = array_merge($this->options, $options); } return $this; } public function getOption($key = null, $default = null) { if (is_null($key)) { return $this->options; } return array_get($this->options, $key, $default); } public function actions($prefix, $actions) { $this->actions = $actions; $this->action_prefix = $prefix; return $this; } public function hasActions() { return (!empty($this->actions)); } public function getColumns() { return $this->column_lists; } public function isEmpty() { if (is_null($this->total)) { $this->resolveCustomQuery(); $this->total = $this->model->count(); } return ($this->total < 1); } public function build() { if (! empty($this->custom_query) ) { $this->resolveCustomQuery(); } $this->makeFiltering(); $this->makeCounting(); $this->makePaging(); $this->makeOrdering(); return $this->makeRendering(); } public function buildJson() { return json_encode($this->build()); } protected function makeFiltering() { $count = $this->getColumnCount(); if (Input::get('sSearch','') != '') { $this-> makeSearchFiltering($count); } $this->makeColumnFiltering($count); } protected function makeSearchFiltering($count) { $keyword = '%'.Input::get('sSearch').'%'; for ($i=0; $i < $count; $i++) { if (Input::get('bSearchable_'.$i) == "true") { $column = $this->getColumnKeyName($i); if (!is_null($column)) { if ($i === 0) { $this->model = $this->model->where($column, 'like', $keyword); } else { $this->model = $this->model->orWhere($column, 'like', $keyword); } } } } } protected function makeColumnFiltering($count) { for ($i=0; $i < $count; $i++) { if (Input::get('bSearchable_'.$i) == "true" && Input::get('sSearch_'.$i, '') != '') { $column = $this->getColumnKeyName($i); if (!is_null($column)) { if ($i === 0) { $this->model = $this->model->where($column, 'like', $keyword); } else { $this->model = $this->model->andWhere($column, 'like', $keyword); } } } } } protected function makeCounting() { $this->total = $this->model->count(); $model = $this->model; $this->filter_total = (int) $model->count(); } protected function makePaging() { if (!is_null(Input::get('iDisplayStart')) && Input::get('iDisplayLength') != -1) { $this->model = $this->model->skip(Input::get('iDisplayStart')) ->take(Input::get('iDisplayLength',10)); } } protected function makeOrdering() { if (! is_null(Input::get('iSortCol_0')) ) { $total = intval(Input::get('iSortingCols')); for ($i = 0; $i < $total; $i++) { if (Input::get('bSortable_'.intval(Input::get('iSortCol_'.$i))) == "true") { $column = $this->getColumnKeyName(Input::get('iSortCol_'.$i)); $sort_dir = Input::get('sSortDir_'.$i); if (false == strpos($column, '.')) { $this->model = $this->model ->orderBy($column, $sort_dir); } } } } } protected function makeRendering() { $results = $this->getResult(); $output = array( "sEcho" => intval(Input::get('sEcho')), "iTotalRecords" => $this->total, "iTotalDisplayRecords" => $this->filter_total, "aaData" => $results ); return $output; } protected function getResult() { $results = $this->model->get(); $data = array(); $columns = $this->getAllColumnName(); foreach ($results as $result) { $tmp = array(); foreach ($columns as $col) { $tmp[] = $this->getTransformValue($col, $result); } if (! empty($this->actions) ) { $tmp[] = $this->makeActionsColumn($result); } $data[] = $tmp; unset($tmp); } return $data; } protected function resolveCustomQuery() { foreach ($this->custom_query as $query) { $this->model = $query($this->model); } $this->custom_query = array(); } protected function getTransformValue($for, $model) { $list = explode('.', $for); $value = (count($list) == 2) ? $model->{$list[0]}->{$list[1]} : $model->{$list[0]}; if (isset($this->transformers[$for])) { $callback = $this->transformers[$for]; return $callback($value, $model); } return $value; } protected function makeActionsColumn($model) { $view = '
'; foreach ($this->actions as $action) { list($url, $icon, $attrs) = $this->parserActionData($action, $model); $view .= Html::a($url, $icon, $attrs); } return $view.'
'; } protected function parserActionData($action, $model) { $first = substr($action, 0, 1); $explode = explode(':', $action); if ('!' === $first) { $explode[0] = substr($explode[0], 1); $url = rbUrl($this->action_prefix.'/'.$explode[0]).$model->$explode[1]; } else { $url = adminUrl($this->action_prefix.'/'.$explode[0]).$model->$explode[1]; } $icon = isset($explode[2]) ? $explode[2] : $explode[0]; $attrs = array(); $attrs['class'] = ('delete' === $explode[0]) ? 'confirm_delete tipsy-tip' : 'tipsy-tip'; $attrs['title'] = isset($explode[3]) ? $explode[3] : Str::title($explode[0]); return array($url, '', $attrs); } protected function getColumnCount() { return count($this->columns); } protected function getColumnKeyName($key) { if (isset($this->columns[$key])) { return $this->columns[$key]['name']; } return null; } protected function getAllColumnName() { $names = array_map(function ($column) { return $column['name']; }, $this->columns); return $names; } public function __toString() { return $this->build(); } }
Reborn\Routing\ControllerResolver::resolve( ) # Line No. 190
{{ CMS }} » storages/compile.php
 namespace Reborn\Translate\Loader; interface LoaderInterface { public function load($resource, $locale); } 

 namespace Reborn\Translate\Loader; use Reborn\Cores\Application; class PHPFileLoader implements LoaderInterface { protected $app; public function __construct(Application $app) { $this->app = $app; } public function load($resource, $locale) { if (false !== strpos($resource, "::")) { return $this->moduleFileLoader($resource, $locale); } elseif ('theme@' === substr($resource, 0, 6)) { return $this->themeFileLoader($resource, $locale); } else { return $this->coreFileLoader($resource, $locale); } } protected function themeFileLoader($resource, $locale) { $theme = $this->app->theme->getThemePath(); $file = substr($resource, 6); $filepath = $theme.'lang'.DS.$locale.DS.$file.'.php'; if (file_exists($filepath)) { return require $filepath; } else { return false; } } protected function moduleFileLoader($resource, $locale) { list($module, $file) = explode('::', $resource); $mod = \Module::get($module); if (is_null($mod)) return false; $path = $mod->path.DS.'lang'.DS; if (file_exists($f = $path.$locale.DS.$file.EXT)) { return require $f; } else { return false; } } protected function coreFileLoader($resource, $locale) { if (is_dir($dir = APP.'lang'.DS.$locale.DS)) { $dirPath = $dir; } else { return false; } if (file_exists($f = $dirPath.$resource.EXT)) { return require $f; } else { return false; } } } 

 namespace Reborn\Routing; use Reborn\Cores\Application; use Reborn\Cores\Setting; use Reborn\Filesystem\File; use Reborn\Http\Uri; use Reborn\Http\Input; use Reborn\Util\Str; use Reborn\Util\Security; use Reborn\Module\ModuleManager as Module; use Reborn\Exception\HttpNotFoundException; use Reborn\Exception\TokenNotMatchException; use Reborn\Exception\MaintainanceModeException; class Router { protected $app; protected $request; protected $collection; protected $mapper; protected $admin; public function __construct(Application $app) { $this->app = $app; $this->request = $app->request; $this->admin = Setting::get('adminpanel_url', \Config::get('app.adminpanel')); $app->route_collection->setAdminPrefix($this->admin); $this->collection = $app->route_collection; $this->mapper = ControllerMap::create(); $this->loadRequiredFiles(); } public function getCollection() { return $this->collection; } public function dispatch() { \Event::call('reborn.app.startroute'); $uri = Uri::uriString(1, 1); $this->addModuleRoute($uri); $request_uri = implode('/', Uri::segments()); if ( $this->app['site_manager']->isMaintain() ) { $route = $this->findForMaintain(rawurldecode($request_uri)); if (! $route) { throw new MaintainanceModeException("Website is Under Maintainance!"); } } else { $route = $this->findForAll(rawurldecode($request_uri)); } if ($route) { if (! $route->skipCSRF()) { $this->checkCSRF(); } $module = Module::get($route->module); if (!is_null($module) and !$module->isEnabled()) { return $this->callMissing($request_uri); } if ($route->isClosure) { $params = $route->params; array_unshift($params, $this->app); return call_user_func_array($route->callback, $params); } return $this->callbackController($route); } if ($route = $this->detectController()) { $this->checkCSRF(); return $this->callbackController($route); } return $this->callMissing($request_uri); } protected function callMissing($request_uri) { if ($route = $this->collection->getMissing($request_uri, $this->request)) { $this->checkCSRF(); return $this->callbackController($route); } throw new HttpNotFoundException("Request URL is not found!"); } protected function findForMaintain($uri) { return $this->collection->matchForAsset($uri, $this->request); } protected function findForAll($uri) { return $this->collection->match($uri, $this->request); } protected function detectController() { if (Uri::segment(1) == $this->admin) { $moduleUri = Uri::segment(2); $controller = ucfirst(Str::camel(Uri::segment(3))); $admin = true; } else { $moduleUri = Uri::segment(1); $controller = ucfirst(Str::camel(Uri::segment(2))); $admin = false; } if (! $mod = Module::get($moduleUri)) { return false; } if (is_null($controller)) { $controller = ucfirst($mod['ns']); } $module = ucfirst($mod['ns']); if ($admin) { $file = 'Admin'.DS.$controller.'Controller'; $action_pos = 4; } else { $file ='Controller'.DS.$controller.'Controller'; $action_pos = 3; } $ctrl_file = $this->mapper->find($moduleUri, $file); if (is_null($ctrl_file)) { if ($admin) { $file = 'Admin'.DS.$module.'Controller'; $action_pos = 3; } else { $file ='Controller'.DS.$module.'Controller'; $action_pos = 2; } $controller = $module; $ctrl_file = $this->mapper->find($moduleUri, $file); } if (is_null($ctrl_file)) { return null; } $route = new Route('', ''); $route->module = $module; if ($admin) { $route->controller = 'Admin\\'.$controller; } else { $route->controller = $controller; } if (is_null(Uri::segment($action_pos))) { $route->action = 'index'; } else { $route->action = Str::camel(Uri::segment($action_pos)); } $segments = Uri::segments(); for ($i = 0; $i < $action_pos; $i++) { unset($segments[$i]); } $route->params = $segments; return $route; } protected function callbackController($route) { $module = Module::get($route->module); if (!is_null($module) and !$module->isEnabled()) { throw new HttpNotFoundException("Request URL is not found!"); } $resolver = new ControllerResolver($this->app, $route); return $resolver->resolve(); } protected function addModuleRoute($path) { if ($path == '') { $path = '/'; $module = Module::get(\Setting::get('default_module')); } else { if ($this->admin == $path) { $module = Module::get(Uri::segment(2)); } else { $module = Module::get($path); } } if (!is_null($module) and !Module::has($module->name)) { $module = Module::get(\Setting::get('default_module')); } if (!is_null($module)) { $path = $module->path; if (is_readable($path.DS.'routes.php')) { require $path.DS.'routes.php'; } } } protected function loadRequiredFiles() { require APP.'middlewares.php'; if (File::is(CONTENT.'routes.php')) { require CONTENT.'routes.php'; } if (File::is(BASE_CONTENT.'routes.php')) { require BASE_CONTENT.'routes.php'; } require APP.'routes.php'; } protected function checkCSRF() { if (Input::isPost()) { if ( Security::CSRFvalid() ) { return true; } else { throw new TokenNotMatchException('Request Token doesn\'t match!'); } } return true; } } 

 namespace Reborn\Routing; use Closure; use Reborn\Util\Str; use Reborn\Http\Request; class Route { const REGEX = '`(\\\?(?:/|\.|))\{((.*?):(.*?))?\}(\?|)`'; public $name; public $callback; public $isClosure = false; public $module; public $controller; public $action; public $params = array(); protected $path; protected $methods; protected $host; protected $defaults = array(); protected $skip_csrf = false; protected $is_asset = false; protected $before_middlewares = array(); public function __construct($path, $callback, $name = null, $methods = 'ALL') { $path = ($path == '/') ? $path : trim($path, '/'); if (false !== strpos($path, '@admin')) { $admin = \Setting::get('adminpanel_url', \Config::get('app.adminpanel')); $this->path = str_replace('@admin', $admin, $path); } else { $this->path = $path; } if ($callback instanceof Closure) { $this->isClosure = true; } $this->callback = $callback; $this->method($methods); $this->name = $this->generateName($name); } public function getPath() { return $this->path; } public function csrf($skip = true) { $this->skip_csrf = (boolean) $skip; return $this; } public function method($methods) { $this->methods = array(); foreach ((array) $methods as $method) { $this->methods[] = strtoupper($method); } return $this; } public function getMethod() { return $this->methods; } public function host($host) { $this->host = rtrim($host, '/').'/'; return $this; } public function getHost() { return $this->host; } public function defaults(array $param) { $this->defaults = $param; return $this; } public function skipCSRF() { return $this->skip_csrf; } public function isAsset($value = true) { $this->is_asset = (boolean) $value; return $this; } public function forAsset() { return $this->is_asset; } public function before($names) { $names = (array) $names; foreach ($names as $name) { $this->before_middlewares[] = $name; } return $this; } public function runBeforeMiddlewares(Request $request) { foreach ($this->before_middlewares as $mw) { $response = Middleware::run($mw, $request, $this); if (!is_null($response)) { return $response; } } } public function getUrl($data = array()) { preg_match_all(self::REGEX, $this->path, $matches, PREG_SET_ORDER); if (empty($matches)) return $this->path; $search = $replace = array(); foreach ($matches as $m) { $search[] = $m[0]; $optional = ('?' == $m[5]) ? true : false; $prefix = $m[1]; $key = $m[4]; if (!$optional and !isset($data[$key]) ) { return null; } if ($optional and !isset($data[$key])) { $replace[] = ''; } else { $replace[] = $prefix.$data[$key]; } } return str_replace($search, $replace, $this->path); } public function match($path, Request $request) { if ( ! is_null($this->host) ) { if ($request->baseUrl() != $this->host) { return false; } } if (! in_array('ALL', $this->methods)) { $verb = $request->getMethod(); if (! in_array($verb, $this->methods)) { return false; } } if ($this->path == $path || ($this->path == '/' and $path == '')) { $this->compiling(); return $this; } $pattern = $this->makeRegexPattern(); if (preg_match($pattern, $path, $match)) { $this->compiling($match); return $this; } return false; } public function compiling($match = null) { if (false === $this->isClosure) { $this->parseCallable(); } if (!is_null($match)) { $this->parseParameter($match); } return $this; } protected function parseCallable() { if (false != strpos($this->callback, '::')) { $arr = explode('::', $this->callback); $namespace = explode('\\', $arr[0], 2); $this->module = $namespace[0]; $this->controller = $namespace[1]; $this->action = Str::camel($arr[1]); } else { $namespace = explode('\\', $this->callback, 2); $this->module = $namespace[0]; $this->controller = $namespace[1]; $this->action = 'index'; } } protected function parseParameter($params) { foreach ($params as $key => $value) { if (!is_integer($key)) { $this->params[$key] = $value; } } $this->params = array_merge($this->defaults, $this->params); } protected function makeRegexPattern() { if (preg_match_all(self::REGEX, $this->path, $matches, PREG_SET_ORDER)) { $find = $replace = array(); foreach ($matches as $m) { $regex = $this->getPattern($m[3]); $key = $m[4]; $find[] = $m[0]; $optional = ($m[5] == '') ? null : '?'; $prefix = ($m[1] == '') ? null : $m[1]; $replace[] = '(?:'.$prefix.'(?P<'.$key.'>'.$regex.'))'.$optional; } $route = str_replace($find, $replace, $this->path); return '@^'.$route.'$@'; } return '@^'.$this->path.'$@'; } protected function getPattern($type) { if (false !== strpos($type, '@')) { return substr($type, 1); } $pattern = ''; switch (strtolower($type)) { case "int": case "num": $pattern = "[0-9]++"; break; case "hex": $pattern = "[0-9A-Fa-f]++"; break; case "str": $pattern = "[0-9a-zA-Z\-_]+"; break; case "alpha": $pattern = "[a-zA-Z]+"; break; case "alnum": $pattern = "[0-9a-zA-Z]+"; break; case "*": $pattern = ".+?"; break; case "p": $pattern = "(page-[0-9]++)"; break; default: $pattern = "[^/]+?"; break; } return $pattern; } protected function generateName($name) { if (!is_null($name)) return $name; $prefix = ''; if (!in_array('ALL', $this->methods)) { foreach ($this->methods as $method) { $prefix .= strtolower($method).'_'; } } $name = preg_replace('/({(.*)})/', '', $this->path); $name = str_replace(array('/', '|', '-'), '_', $name); $name = preg_replace('/[^a-z0-9A-Z_.]+/', '', $name); $name = rtrim($name, '_'); return $prefix.$name; } public function __toString() { return $this->name; } } 

 namespace Reborn\Routing; use Reborn\Http\Request; class RouteCollection { protected $admin; protected $routes = array(); protected $group; protected $missing; protected $current; public function setAdminPrefix($prefix) { $this->admin = $prefix; } public function add($path, $callback, $name = null, $method = 'ALL') { if (!is_null($this->group)) { if ($path == '') { $path = rtrim(implode('/', $this->group), '/'); } else { $path = \Str::endIs(implode('/', $this->group), '/').ltrim($path, '/'); } } $route = new Route($path, $callback, $name, $method); $this->addRoute($route, $route->name); return $route; } public function get($path, $callback, $name = null) { return $this->add($path, $callback, $name, 'GET'); } public function post($path, $callback, $name = null) { return $this->add($path, $callback, $name, 'POST'); } public function apiPost($path, $callback, $name = null) { $route = $this->add($path, $callback, $name, 'POST'); $route->csrf(true); return $route; } public function put($path, $callback, $name = null) { return $this->add($path, $callback, $name, 'PUT'); } public function delete($path, $callback, $name = null) { return $this->add($path, $callback, $name, 'DELETE'); } public function resources($resources, $controller) { $this->get($resources, $controller.'::index', $resources); $this->get($resources.'/add', $controller.'::add', $resources.'_add'); $this->post($resources, $controller.'::create', $resources.'_create'); $this->get($resources.'/{int:id}/edit', $controller.'::edit', $resources.'_edit'); $this->put($resources.'/{int:id}', $controller.'::update', $resources.'_update'); $this->delete($resources.'/{int:id}', $controller.'::delete', $resources.'_delete'); $this->get($resources.'/{int:id}', $controller.'::view', $resources.'_view'); } public function crud($path, $controller, $name_prefix, $middlewares = array(), $id_type = 'int') { if (false !== strpos($path, '@admin')) { $path = str_replace('@admin', $this->admin, $path); } $path = rtrim($path, '/'); $r = $this->add($path, $controller.'::index', $name_prefix.'_index', 'GET'); if ( isset($middlewares['index']) ) { $r->before($middlewares['index']); } $r = $this->add($path.'/create', $controller.'::create', $name_prefix.'_create', array('GET', 'POST')); if ( isset($middlewares['create']) ) { $r->before($middlewares['create']); } $r = $this->add($path.'/edit/{'.$id_type.':id}', $controller.'::edit', $name_prefix.'_edit', array('GET', 'POST')); if ( isset($middlewares['edit']) ) { $r->before($middlewares['edit']); } $r = $this->add($path.'/delete/{'.$id_type.':id}', $controller.'::delete', $name_prefix.'_delete', 'GET'); if ( isset($middlewares['delete']) ) { $r->before($middlewares['delete']); } } public function group($prefix, \Closure $callback) { if (false !== strpos($prefix, '@admin')) { $prefix = str_replace('@admin', $this->admin, $prefix); } $this->group[] = $prefix; $callback(); $this->group = null; return $this; } public function missing($callback, $name = null, $method = 'ALL', $pattern = null) { $pattern = is_null($pattern) ? '{*:slug}' : $pattern; $route = new Route($pattern, $callback, $name, $method); $this->missing = $route; return $route; } public function addRoute(Route $route, $name) { $this->routes[$name] = $route; } public function getRoute($name) { return isset($this->routes[$name]) ? $this->routes[$name] : null; } public function getUrlByRouteName($name, $data = array()) { $route = $this->getRoute($name); if( is_null($route) ) return null; return $route->getUrl($data); } public function all() { return $this->routes; } public function pathLists() { $paths = array(); foreach ($this->routes as $route) { $paths[$route->name] = $route->getPath(); } return $paths; } public function filter(\Closure $callback) { return array_filter($this->routes, $callback); } public function match($uri, Request $request) { foreach ($this->routes as $name => $route) { if ($match = $route->match($uri, $request)) { $this->current = $match; return $match; } } return false; } public function matchForAsset($uri, Request $request) { $routes = $this->filter(function ($route) { return $route->forAsset(); }); foreach ($routes as $name => $route) { if ($match = $route->match($uri, $request)) { return $match; } } return false; } public function getMissing($uri, Request $request) { if (!is_null($this->missing)) { return $this->missing->match($uri, $request); } return false; } public function current() { return $this->current; } } 
Reborn\Routing\Router::callbackController( ) # Line No. 190
{{ CMS }} » storages/compile.php
 namespace Reborn\Translate\Loader; interface LoaderInterface { public function load($resource, $locale); } 

 namespace Reborn\Translate\Loader; use Reborn\Cores\Application; class PHPFileLoader implements LoaderInterface { protected $app; public function __construct(Application $app) { $this->app = $app; } public function load($resource, $locale) { if (false !== strpos($resource, "::")) { return $this->moduleFileLoader($resource, $locale); } elseif ('theme@' === substr($resource, 0, 6)) { return $this->themeFileLoader($resource, $locale); } else { return $this->coreFileLoader($resource, $locale); } } protected function themeFileLoader($resource, $locale) { $theme = $this->app->theme->getThemePath(); $file = substr($resource, 6); $filepath = $theme.'lang'.DS.$locale.DS.$file.'.php'; if (file_exists($filepath)) { return require $filepath; } else { return false; } } protected function moduleFileLoader($resource, $locale) { list($module, $file) = explode('::', $resource); $mod = \Module::get($module); if (is_null($mod)) return false; $path = $mod->path.DS.'lang'.DS; if (file_exists($f = $path.$locale.DS.$file.EXT)) { return require $f; } else { return false; } } protected function coreFileLoader($resource, $locale) { if (is_dir($dir = APP.'lang'.DS.$locale.DS)) { $dirPath = $dir; } else { return false; } if (file_exists($f = $dirPath.$resource.EXT)) { return require $f; } else { return false; } } } 

 namespace Reborn\Routing; use Reborn\Cores\Application; use Reborn\Cores\Setting; use Reborn\Filesystem\File; use Reborn\Http\Uri; use Reborn\Http\Input; use Reborn\Util\Str; use Reborn\Util\Security; use Reborn\Module\ModuleManager as Module; use Reborn\Exception\HttpNotFoundException; use Reborn\Exception\TokenNotMatchException; use Reborn\Exception\MaintainanceModeException; class Router { protected $app; protected $request; protected $collection; protected $mapper; protected $admin; public function __construct(Application $app) { $this->app = $app; $this->request = $app->request; $this->admin = Setting::get('adminpanel_url', \Config::get('app.adminpanel')); $app->route_collection->setAdminPrefix($this->admin); $this->collection = $app->route_collection; $this->mapper = ControllerMap::create(); $this->loadRequiredFiles(); } public function getCollection() { return $this->collection; } public function dispatch() { \Event::call('reborn.app.startroute'); $uri = Uri::uriString(1, 1); $this->addModuleRoute($uri); $request_uri = implode('/', Uri::segments()); if ( $this->app['site_manager']->isMaintain() ) { $route = $this->findForMaintain(rawurldecode($request_uri)); if (! $route) { throw new MaintainanceModeException("Website is Under Maintainance!"); } } else { $route = $this->findForAll(rawurldecode($request_uri)); } if ($route) { if (! $route->skipCSRF()) { $this->checkCSRF(); } $module = Module::get($route->module); if (!is_null($module) and !$module->isEnabled()) { return $this->callMissing($request_uri); } if ($route->isClosure) { $params = $route->params; array_unshift($params, $this->app); return call_user_func_array($route->callback, $params); } return $this->callbackController($route); } if ($route = $this->detectController()) { $this->checkCSRF(); return $this->callbackController($route); } return $this->callMissing($request_uri); } protected function callMissing($request_uri) { if ($route = $this->collection->getMissing($request_uri, $this->request)) { $this->checkCSRF(); return $this->callbackController($route); } throw new HttpNotFoundException("Request URL is not found!"); } protected function findForMaintain($uri) { return $this->collection->matchForAsset($uri, $this->request); } protected function findForAll($uri) { return $this->collection->match($uri, $this->request); } protected function detectController() { if (Uri::segment(1) == $this->admin) { $moduleUri = Uri::segment(2); $controller = ucfirst(Str::camel(Uri::segment(3))); $admin = true; } else { $moduleUri = Uri::segment(1); $controller = ucfirst(Str::camel(Uri::segment(2))); $admin = false; } if (! $mod = Module::get($moduleUri)) { return false; } if (is_null($controller)) { $controller = ucfirst($mod['ns']); } $module = ucfirst($mod['ns']); if ($admin) { $file = 'Admin'.DS.$controller.'Controller'; $action_pos = 4; } else { $file ='Controller'.DS.$controller.'Controller'; $action_pos = 3; } $ctrl_file = $this->mapper->find($moduleUri, $file); if (is_null($ctrl_file)) { if ($admin) { $file = 'Admin'.DS.$module.'Controller'; $action_pos = 3; } else { $file ='Controller'.DS.$module.'Controller'; $action_pos = 2; } $controller = $module; $ctrl_file = $this->mapper->find($moduleUri, $file); } if (is_null($ctrl_file)) { return null; } $route = new Route('', ''); $route->module = $module; if ($admin) { $route->controller = 'Admin\\'.$controller; } else { $route->controller = $controller; } if (is_null(Uri::segment($action_pos))) { $route->action = 'index'; } else { $route->action = Str::camel(Uri::segment($action_pos)); } $segments = Uri::segments(); for ($i = 0; $i < $action_pos; $i++) { unset($segments[$i]); } $route->params = $segments; return $route; } protected function callbackController($route) { $module = Module::get($route->module); if (!is_null($module) and !$module->isEnabled()) { throw new HttpNotFoundException("Request URL is not found!"); } $resolver = new ControllerResolver($this->app, $route); return $resolver->resolve(); } protected function addModuleRoute($path) { if ($path == '') { $path = '/'; $module = Module::get(\Setting::get('default_module')); } else { if ($this->admin == $path) { $module = Module::get(Uri::segment(2)); } else { $module = Module::get($path); } } if (!is_null($module) and !Module::has($module->name)) { $module = Module::get(\Setting::get('default_module')); } if (!is_null($module)) { $path = $module->path; if (is_readable($path.DS.'routes.php')) { require $path.DS.'routes.php'; } } } protected function loadRequiredFiles() { require APP.'middlewares.php'; if (File::is(CONTENT.'routes.php')) { require CONTENT.'routes.php'; } if (File::is(BASE_CONTENT.'routes.php')) { require BASE_CONTENT.'routes.php'; } require APP.'routes.php'; } protected function checkCSRF() { if (Input::isPost()) { if ( Security::CSRFvalid() ) { return true; } else { throw new TokenNotMatchException('Request Token doesn\'t match!'); } } return true; } } 

 namespace Reborn\Routing; use Closure; use Reborn\Util\Str; use Reborn\Http\Request; class Route { const REGEX = '`(\\\?(?:/|\.|))\{((.*?):(.*?))?\}(\?|)`'; public $name; public $callback; public $isClosure = false; public $module; public $controller; public $action; public $params = array(); protected $path; protected $methods; protected $host; protected $defaults = array(); protected $skip_csrf = false; protected $is_asset = false; protected $before_middlewares = array(); public function __construct($path, $callback, $name = null, $methods = 'ALL') { $path = ($path == '/') ? $path : trim($path, '/'); if (false !== strpos($path, '@admin')) { $admin = \Setting::get('adminpanel_url', \Config::get('app.adminpanel')); $this->path = str_replace('@admin', $admin, $path); } else { $this->path = $path; } if ($callback instanceof Closure) { $this->isClosure = true; } $this->callback = $callback; $this->method($methods); $this->name = $this->generateName($name); } public function getPath() { return $this->path; } public function csrf($skip = true) { $this->skip_csrf = (boolean) $skip; return $this; } public function method($methods) { $this->methods = array(); foreach ((array) $methods as $method) { $this->methods[] = strtoupper($method); } return $this; } public function getMethod() { return $this->methods; } public function host($host) { $this->host = rtrim($host, '/').'/'; return $this; } public function getHost() { return $this->host; } public function defaults(array $param) { $this->defaults = $param; return $this; } public function skipCSRF() { return $this->skip_csrf; } public function isAsset($value = true) { $this->is_asset = (boolean) $value; return $this; } public function forAsset() { return $this->is_asset; } public function before($names) { $names = (array) $names; foreach ($names as $name) { $this->before_middlewares[] = $name; } return $this; } public function runBeforeMiddlewares(Request $request) { foreach ($this->before_middlewares as $mw) { $response = Middleware::run($mw, $request, $this); if (!is_null($response)) { return $response; } } } public function getUrl($data = array()) { preg_match_all(self::REGEX, $this->path, $matches, PREG_SET_ORDER); if (empty($matches)) return $this->path; $search = $replace = array(); foreach ($matches as $m) { $search[] = $m[0]; $optional = ('?' == $m[5]) ? true : false; $prefix = $m[1]; $key = $m[4]; if (!$optional and !isset($data[$key]) ) { return null; } if ($optional and !isset($data[$key])) { $replace[] = ''; } else { $replace[] = $prefix.$data[$key]; } } return str_replace($search, $replace, $this->path); } public function match($path, Request $request) { if ( ! is_null($this->host) ) { if ($request->baseUrl() != $this->host) { return false; } } if (! in_array('ALL', $this->methods)) { $verb = $request->getMethod(); if (! in_array($verb, $this->methods)) { return false; } } if ($this->path == $path || ($this->path == '/' and $path == '')) { $this->compiling(); return $this; } $pattern = $this->makeRegexPattern(); if (preg_match($pattern, $path, $match)) { $this->compiling($match); return $this; } return false; } public function compiling($match = null) { if (false === $this->isClosure) { $this->parseCallable(); } if (!is_null($match)) { $this->parseParameter($match); } return $this; } protected function parseCallable() { if (false != strpos($this->callback, '::')) { $arr = explode('::', $this->callback); $namespace = explode('\\', $arr[0], 2); $this->module = $namespace[0]; $this->controller = $namespace[1]; $this->action = Str::camel($arr[1]); } else { $namespace = explode('\\', $this->callback, 2); $this->module = $namespace[0]; $this->controller = $namespace[1]; $this->action = 'index'; } } protected function parseParameter($params) { foreach ($params as $key => $value) { if (!is_integer($key)) { $this->params[$key] = $value; } } $this->params = array_merge($this->defaults, $this->params); } protected function makeRegexPattern() { if (preg_match_all(self::REGEX, $this->path, $matches, PREG_SET_ORDER)) { $find = $replace = array(); foreach ($matches as $m) { $regex = $this->getPattern($m[3]); $key = $m[4]; $find[] = $m[0]; $optional = ($m[5] == '') ? null : '?'; $prefix = ($m[1] == '') ? null : $m[1]; $replace[] = '(?:'.$prefix.'(?P<'.$key.'>'.$regex.'))'.$optional; } $route = str_replace($find, $replace, $this->path); return '@^'.$route.'$@'; } return '@^'.$this->path.'$@'; } protected function getPattern($type) { if (false !== strpos($type, '@')) { return substr($type, 1); } $pattern = ''; switch (strtolower($type)) { case "int": case "num": $pattern = "[0-9]++"; break; case "hex": $pattern = "[0-9A-Fa-f]++"; break; case "str": $pattern = "[0-9a-zA-Z\-_]+"; break; case "alpha": $pattern = "[a-zA-Z]+"; break; case "alnum": $pattern = "[0-9a-zA-Z]+"; break; case "*": $pattern = ".+?"; break; case "p": $pattern = "(page-[0-9]++)"; break; default: $pattern = "[^/]+?"; break; } return $pattern; } protected function generateName($name) { if (!is_null($name)) return $name; $prefix = ''; if (!in_array('ALL', $this->methods)) { foreach ($this->methods as $method) { $prefix .= strtolower($method).'_'; } } $name = preg_replace('/({(.*)})/', '', $this->path); $name = str_replace(array('/', '|', '-'), '_', $name); $name = preg_replace('/[^a-z0-9A-Z_.]+/', '', $name); $name = rtrim($name, '_'); return $prefix.$name; } public function __toString() { return $this->name; } } 

 namespace Reborn\Routing; use Reborn\Http\Request; class RouteCollection { protected $admin; protected $routes = array(); protected $group; protected $missing; protected $current; public function setAdminPrefix($prefix) { $this->admin = $prefix; } public function add($path, $callback, $name = null, $method = 'ALL') { if (!is_null($this->group)) { if ($path == '') { $path = rtrim(implode('/', $this->group), '/'); } else { $path = \Str::endIs(implode('/', $this->group), '/').ltrim($path, '/'); } } $route = new Route($path, $callback, $name, $method); $this->addRoute($route, $route->name); return $route; } public function get($path, $callback, $name = null) { return $this->add($path, $callback, $name, 'GET'); } public function post($path, $callback, $name = null) { return $this->add($path, $callback, $name, 'POST'); } public function apiPost($path, $callback, $name = null) { $route = $this->add($path, $callback, $name, 'POST'); $route->csrf(true); return $route; } public function put($path, $callback, $name = null) { return $this->add($path, $callback, $name, 'PUT'); } public function delete($path, $callback, $name = null) { return $this->add($path, $callback, $name, 'DELETE'); } public function resources($resources, $controller) { $this->get($resources, $controller.'::index', $resources); $this->get($resources.'/add', $controller.'::add', $resources.'_add'); $this->post($resources, $controller.'::create', $resources.'_create'); $this->get($resources.'/{int:id}/edit', $controller.'::edit', $resources.'_edit'); $this->put($resources.'/{int:id}', $controller.'::update', $resources.'_update'); $this->delete($resources.'/{int:id}', $controller.'::delete', $resources.'_delete'); $this->get($resources.'/{int:id}', $controller.'::view', $resources.'_view'); } public function crud($path, $controller, $name_prefix, $middlewares = array(), $id_type = 'int') { if (false !== strpos($path, '@admin')) { $path = str_replace('@admin', $this->admin, $path); } $path = rtrim($path, '/'); $r = $this->add($path, $controller.'::index', $name_prefix.'_index', 'GET'); if ( isset($middlewares['index']) ) { $r->before($middlewares['index']); } $r = $this->add($path.'/create', $controller.'::create', $name_prefix.'_create', array('GET', 'POST')); if ( isset($middlewares['create']) ) { $r->before($middlewares['create']); } $r = $this->add($path.'/edit/{'.$id_type.':id}', $controller.'::edit', $name_prefix.'_edit', array('GET', 'POST')); if ( isset($middlewares['edit']) ) { $r->before($middlewares['edit']); } $r = $this->add($path.'/delete/{'.$id_type.':id}', $controller.'::delete', $name_prefix.'_delete', 'GET'); if ( isset($middlewares['delete']) ) { $r->before($middlewares['delete']); } } public function group($prefix, \Closure $callback) { if (false !== strpos($prefix, '@admin')) { $prefix = str_replace('@admin', $this->admin, $prefix); } $this->group[] = $prefix; $callback(); $this->group = null; return $this; } public function missing($callback, $name = null, $method = 'ALL', $pattern = null) { $pattern = is_null($pattern) ? '{*:slug}' : $pattern; $route = new Route($pattern, $callback, $name, $method); $this->missing = $route; return $route; } public function addRoute(Route $route, $name) { $this->routes[$name] = $route; } public function getRoute($name) { return isset($this->routes[$name]) ? $this->routes[$name] : null; } public function getUrlByRouteName($name, $data = array()) { $route = $this->getRoute($name); if( is_null($route) ) return null; return $route->getUrl($data); } public function all() { return $this->routes; } public function pathLists() { $paths = array(); foreach ($this->routes as $route) { $paths[$route->name] = $route->getPath(); } return $paths; } public function filter(\Closure $callback) { return array_filter($this->routes, $callback); } public function match($uri, Request $request) { foreach ($this->routes as $name => $route) { if ($match = $route->match($uri, $request)) { $this->current = $match; return $match; } } return false; } public function matchForAsset($uri, Request $request) { $routes = $this->filter(function ($route) { return $route->forAsset(); }); foreach ($routes as $name => $route) { if ($match = $route->match($uri, $request)) { return $match; } } return false; } public function getMissing($uri, Request $request) { if (!is_null($this->missing)) { return $this->missing->match($uri, $request); } return false; } public function current() { return $this->current; } } 
Reborn\Routing\Router::dispatch( ) # Line No. 31
{{ CMS }} » storages/compile.php
 namespace Illuminate\Database\Eloquent; use DateTime; use ArrayAccess; use Carbon\Carbon; use LogicException; use Illuminate\Events\Dispatcher; use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Support\Contracts\JsonableInterface; use Illuminate\Support\Contracts\ArrayableInterface; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\ConnectionResolverInterface as Resolver; abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterface { protected $connection; protected $table; protected $primaryKey = 'id'; protected $perPage = 15; public $incrementing = true; public $timestamps = true; protected $attributes = array(); protected $original = array(); protected $relations = array(); protected $hidden = array(); protected $visible = array(); protected $appends = array(); protected $fillable = array(); protected $guarded = array('*'); protected $dates = array(); protected $touches = array(); protected $observables = array(); protected $with = array(); protected $morphClass; public $exists = false; protected $softDelete = false; public static $snakeAttributes = true; protected static $resolver; protected static $dispatcher; protected static $booted = array(); protected static $unguarded = false; protected static $mutatorCache = array(); public static $manyMethods = array('belongsToMany', 'morphToMany', 'morphedByMany'); const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; const DELETED_AT = 'deleted_at'; public function __construct(array $attributes = array()) { $this->bootIfNotBooted(); $this->syncOriginal(); $this->fill($attributes); } protected function bootIfNotBooted() { if ( ! isset(static::$booted[get_class($this)])) { static::$booted[get_class($this)] = true; $this->fireModelEvent('booting', false); static::boot(); $this->fireModelEvent('booted', false); } } protected static function boot() { $class = get_called_class(); static::$mutatorCache[$class] = array(); foreach (get_class_methods($class) as $method) { if (preg_match('/^get(.+)Attribute$/', $method, $matches)) { if (static::$snakeAttributes) $matches[1] = snake_case($matches[1]); static::$mutatorCache[$class][] = lcfirst($matches[1]); } } } public static function observe($class) { $instance = new static; $className = get_class($class); foreach ($instance->getObservableEvents() as $event) { if (method_exists($class, $event)) { static::registerModelEvent($event, $className.'@'.$event); } } } public function fill(array $attributes) { $totallyGuarded = $this->totallyGuarded(); foreach ($this->fillableFromArray($attributes) as $key => $value) { $key = $this->removeTableFromKey($key); if ($this->isFillable($key)) { $this->setAttribute($key, $value); } elseif ($totallyGuarded) { throw new MassAssignmentException($key); } } return $this; } protected function fillableFromArray(array $attributes) { if (count($this->fillable) > 0 && ! static::$unguarded) { return array_intersect_key($attributes, array_flip($this->fillable)); } return $attributes; } public function newInstance($attributes = array(), $exists = false) { $model = new static((array) $attributes); $model->exists = $exists; return $model; } public function newFromBuilder($attributes = array()) { $instance = $this->newInstance(array(), true); $instance->setRawAttributes((array) $attributes, true); return $instance; } public static function hydrate(array $items, $connection = null) { $collection = with($instance = new static)->newCollection(); foreach ($items as $item) { $model = $instance->newFromBuilder($item); if ( ! is_null($connection)) { $model->setConnection($connection); } $collection->push($model); } return $collection; } public static function hydrateRaw($query, $bindings = array(), $connection = null) { $instance = new static; if ( ! is_null($connection)) { $instance->setConnection($connection); } $items = $instance->getConnection()->select($query, $bindings); return static::hydrate($items, $connection); } public static function create(array $attributes) { $model = new static($attributes); $model->save(); return $model; } public static function firstOrCreate(array $attributes) { if ( ! is_null($instance = static::firstByAttributes($attributes))) { return $instance; } return static::create($attributes); } public static function firstOrNew(array $attributes) { if ( ! is_null($instance = static::firstByAttributes($attributes))) { return $instance; } return new static($attributes); } protected static function firstByAttributes($attributes) { $query = static::query(); foreach ($attributes as $key => $value) { $query->where($key, $value); } return $query->first() ?: null; } public static function query() { return with(new static)->newQuery(); } public static function on($connection = null) { $instance = new static; $instance->setConnection($connection); return $instance->newQuery(); } public static function all($columns = array('*')) { $instance = new static; return $instance->newQuery()->get($columns); } public static function find($id, $columns = array('*')) { if (is_array($id) && empty($id)) return new Collection; $instance = new static; return $instance->newQuery()->find($id, $columns); } public static function findOrNew($id, $columns = array('*')) { if ( ! is_null($model = static::find($id, $columns))) return $model; return new static($columns); } public static function findOrFail($id, $columns = array('*')) { if ( ! is_null($model = static::find($id, $columns))) return $model; throw with(new ModelNotFoundException)->setModel(get_called_class()); } public function load($relations) { if (is_string($relations)) $relations = func_get_args(); $query = $this->newQuery()->with($relations); $query->eagerLoadRelations(array($this)); return $this; } public static function with($relations) { if (is_string($relations)) $relations = func_get_args(); $instance = new static; return $instance->newQuery()->with($relations); } public function hasOne($related, $foreignKey = null, $localKey = null) { $foreignKey = $foreignKey ?: $this->getForeignKey(); $instance = new $related; $localKey = $localKey ?: $this->getKeyName(); return new HasOne($instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey); } public function morphOne($related, $name, $type = null, $id = null, $localKey = null) { $instance = new $related; list($type, $id) = $this->getMorphs($name, $type, $id); $table = $instance->getTable(); $localKey = $localKey ?: $this->getKeyName(); return new MorphOne($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey); } public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null) { if (is_null($relation)) { list(, $caller) = debug_backtrace(false); $relation = $caller['function']; } if (is_null($foreignKey)) { $foreignKey = snake_case($relation).'_id'; } $instance = new $related; $query = $instance->newQuery(); $otherKey = $otherKey ?: $instance->getKeyName(); return new BelongsTo($query, $this, $foreignKey, $otherKey, $relation); } public function morphTo($name = null, $type = null, $id = null) { if (is_null($name)) { list(, $caller) = debug_backtrace(false); $name = snake_case($caller['function']); } list($type, $id) = $this->getMorphs($name, $type, $id); if (is_null($class = $this->$type)) { return new MorphTo( $this->newQuery(), $this, $id, null, $type, $name ); } else { $instance = new $class; return new MorphTo( with($instance)->newQuery(), $this, $id, $instance->getKeyName(), $type, $name ); } } public function hasMany($related, $foreignKey = null, $localKey = null) { $foreignKey = $foreignKey ?: $this->getForeignKey(); $instance = new $related; $localKey = $localKey ?: $this->getKeyName(); return new HasMany($instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey); } public function hasManyThrough($related, $through, $firstKey = null, $secondKey = null) { $through = new $through; $firstKey = $firstKey ?: $this->getForeignKey(); $secondKey = $secondKey ?: $through->getForeignKey(); return new HasManyThrough(with(new $related)->newQuery(), $this, $through, $firstKey, $secondKey); } public function morphMany($related, $name, $type = null, $id = null, $localKey = null) { $instance = new $related; list($type, $id) = $this->getMorphs($name, $type, $id); $table = $instance->getTable(); $localKey = $localKey ?: $this->getKeyName(); return new MorphMany($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey); } public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null) { if (is_null($relation)) { $relation = $this->getBelongsToManyCaller(); } $foreignKey = $foreignKey ?: $this->getForeignKey(); $instance = new $related; $otherKey = $otherKey ?: $instance->getForeignKey(); if (is_null($table)) { $table = $this->joiningTable($related); } $query = $instance->newQuery(); return new BelongsToMany($query, $this, $table, $foreignKey, $otherKey, $relation); } public function morphToMany($related, $name, $table = null, $foreignKey = null, $otherKey = null, $inverse = false) { $caller = $this->getBelongsToManyCaller(); $foreignKey = $foreignKey ?: $name.'_id'; $instance = new $related; $otherKey = $otherKey ?: $instance->getForeignKey(); $query = $instance->newQuery(); $table = $table ?: str_plural($name); return new MorphToMany( $query, $this, $name, $table, $foreignKey, $otherKey, $caller, $inverse ); } public function morphedByMany($related, $name, $table = null, $foreignKey = null, $otherKey = null) { $foreignKey = $foreignKey ?: $this->getForeignKey(); $otherKey = $otherKey ?: $name.'_id'; return $this->morphToMany($related, $name, $table, $foreignKey, $otherKey, true); } protected function getBelongsToManyCaller() { $self = __FUNCTION__; $caller = array_first(debug_backtrace(false), function($key, $trace) use ($self) { $caller = $trace['function']; return ( ! in_array($caller, Model::$manyMethods) && $caller != $self); }); return ! is_null($caller) ? $caller['function'] : null; } public function joiningTable($related) { $base = snake_case(class_basename($this)); $related = snake_case(class_basename($related)); $models = array($related, $base); sort($models); return strtolower(implode('_', $models)); } public static function destroy($ids) { $count = 0; $ids = is_array($ids) ? $ids : func_get_args(); $instance = new static; $key = $instance->getKeyName(); foreach ($instance->whereIn($key, $ids)->get() as $model) { if ($model->delete()) $count++; } return $count; } public function delete() { if (is_null($this->primaryKey)) { throw new \Exception("No primary key defined on model."); } if ($this->exists) { if ($this->fireModelEvent('deleting') === false) return false; $this->touchOwners(); $this->performDeleteOnModel(); $this->exists = false; $this->fireModelEvent('deleted', false); return true; } } public function forceDelete() { $softDelete = $this->softDelete; $this->softDelete = false; $this->delete(); $this->softDelete = $softDelete; } protected function performDeleteOnModel() { $query = $this->newQuery()->where($this->getKeyName(), $this->getKey()); if ($this->softDelete) { $this->{static::DELETED_AT} = $time = $this->freshTimestamp(); $query->update(array(static::DELETED_AT => $this->fromDateTime($time))); } else { $query->delete(); } } public function restore() { if ($this->softDelete) { if ($this->fireModelEvent('restoring') === false) { return false; } $this->{static::DELETED_AT} = null; $result = $this->save(); $this->fireModelEvent('restored', false); return $result; } } public static function saving($callback) { static::registerModelEvent('saving', $callback); } public static function saved($callback) { static::registerModelEvent('saved', $callback); } public static function updating($callback) { static::registerModelEvent('updating', $callback); } public static function updated($callback) { static::registerModelEvent('updated', $callback); } public static function creating($callback) { static::registerModelEvent('creating', $callback); } public static function created($callback) { static::registerModelEvent('created', $callback); } public static function deleting($callback) { static::registerModelEvent('deleting', $callback); } public static function deleted($callback) { static::registerModelEvent('deleted', $callback); } public static function restoring($callback) { static::registerModelEvent('restoring', $callback); } public static function restored($callback) { static::registerModelEvent('restored', $callback); } public static function flushEventListeners() { if ( ! isset(static::$dispatcher)) return; $instance = new static; foreach ($instance->getObservableEvents() as $event) { static::$dispatcher->forget("eloquent.{$event}: ".get_called_class()); } } protected static function registerModelEvent($event, $callback) { if (isset(static::$dispatcher)) { $name = get_called_class(); static::$dispatcher->listen("eloquent.{$event}: {$name}", $callback); } } public function getObservableEvents() { return array_merge( array( 'creating', 'created', 'updating', 'updated', 'deleting', 'deleted', 'saving', 'saved', 'restoring', 'restored', ), $this->observables ); } protected function increment($column, $amount = 1) { return $this->incrementOrDecrement($column, $amount, 'increment'); } protected function decrement($column, $amount = 1) { return $this->incrementOrDecrement($column, $amount, 'decrement'); } protected function incrementOrDecrement($column, $amount, $method) { $query = $this->newQuery(); if ( ! $this->exists) { return $query->{$method}($column, $amount); } return $query->where($this->getKeyName(), $this->getKey())->{$method}($column, $amount); } public function update(array $attributes = array()) { if ( ! $this->exists) { return $this->newQuery()->update($attributes); } return $this->fill($attributes)->save(); } public function push() { if ( ! $this->save()) return false; foreach ($this->relations as $models) { foreach (Collection::make($models) as $model) { if ( ! $model->push()) return false; } } return true; } public function save(array $options = array()) { $query = $this->newQueryWithDeleted(); if ($this->fireModelEvent('saving') === false) { return false; } if ($this->exists) { $saved = $this->performUpdate($query); } else { $saved = $this->performInsert($query); } if ($saved) $this->finishSave($options); return $saved; } protected function finishSave(array $options) { $this->syncOriginal(); $this->fireModelEvent('saved', false); if (array_get($options, 'touch', true)) $this->touchOwners(); } protected function performUpdate(Builder $query) { $dirty = $this->getDirty(); if (count($dirty) > 0) { if ($this->fireModelEvent('updating') === false) { return false; } if ($this->timestamps) { $this->updateTimestamps(); } $dirty = $this->getDirty(); if (count($dirty) > 0) { $this->setKeysForSaveQuery($query)->update($dirty); $this->fireModelEvent('updated', false); } } return true; } protected function performInsert(Builder $query) { if ($this->fireModelEvent('creating') === false) return false; if ($this->timestamps) { $this->updateTimestamps(); } $attributes = $this->attributes; if ($this->incrementing) { $this->insertAndSetId($query, $attributes); } else { $query->insert($attributes); } $this->exists = true; $this->fireModelEvent('created', false); return true; } protected function insertAndSetId(Builder $query, $attributes) { $id = $query->insertGetId($attributes, $keyName = $this->getKeyName()); $this->setAttribute($keyName, $id); } public function touchOwners() { foreach ($this->touches as $relation) { $this->$relation()->touch(); } } public function touches($relation) { return in_array($relation, $this->touches); } protected function fireModelEvent($event, $halt = true) { if ( ! isset(static::$dispatcher)) return true; $event = "eloquent.{$event}: ".get_class($this); $method = $halt ? 'until' : 'fire'; return static::$dispatcher->$method($event, $this); } protected function setKeysForSaveQuery(Builder $query) { $query->where($this->getKeyName(), '=', $this->getKeyForSaveQuery()); return $query; } protected function getKeyForSaveQuery() { if (isset($this->original[$this->getKeyName()])) { return $this->original[$this->getKeyName()]; } else { return $this->getAttribute($this->getKeyName()); } } public function touch() { $this->updateTimestamps(); return $this->save(); } protected function updateTimestamps() { $time = $this->freshTimestamp(); if ( ! $this->isDirty(static::UPDATED_AT)) { $this->setUpdatedAt($time); } if ( ! $this->exists && ! $this->isDirty(static::CREATED_AT)) { $this->setCreatedAt($time); } } public function setCreatedAt($value) { $this->{static::CREATED_AT} = $value; } public function setUpdatedAt($value) { $this->{static::UPDATED_AT} = $value; } public function getCreatedAtColumn() { return static::CREATED_AT; } public function getUpdatedAtColumn() { return static::UPDATED_AT; } public function getDeletedAtColumn() { return static::DELETED_AT; } public function getQualifiedDeletedAtColumn() { return $this->getTable().'.'.$this->getDeletedAtColumn(); } public function freshTimestamp() { return new Carbon; } public function freshTimestampString() { return $this->fromDateTime($this->freshTimestamp()); } public function newQuery($excludeDeleted = true) { $builder = $this->newEloquentBuilder($this->newBaseQueryBuilder()); $builder->setModel($this)->with($this->with); if ($excludeDeleted && $this->softDelete) { $builder->whereNull($this->getQualifiedDeletedAtColumn()); } return $builder; } public function newQueryWithDeleted() { return $this->newQuery(false); } public function newEloquentBuilder($query) { return new Builder($query); } public function trashed() { return $this->softDelete && ! is_null($this->{static::DELETED_AT}); } public static function withTrashed() { return with(new static)->newQueryWithDeleted(); } public static function onlyTrashed() { $instance = new static; $column = $instance->getQualifiedDeletedAtColumn(); return $instance->newQueryWithDeleted()->whereNotNull($column); } protected function newBaseQueryBuilder() { $conn = $this->getConnection(); $grammar = $conn->getQueryGrammar(); return new QueryBuilder($conn, $grammar, $conn->getPostProcessor()); } public function newCollection(array $models = array()) { return new Collection($models); } public function newPivot(Model $parent, array $attributes, $table, $exists) { return new Pivot($parent, $attributes, $table, $exists); } public function getTable() { if (isset($this->table)) return $this->table; return str_replace('\\', '', snake_case(str_plural(class_basename($this)))); } public function setTable($table) { $this->table = $table; } public function getKey() { return $this->getAttribute($this->getKeyName()); } public function getKeyName() { return $this->primaryKey; } public function getQualifiedKeyName() { return $this->getTable().'.'.$this->getKeyName(); } public function usesTimestamps() { return $this->timestamps; } public function isSoftDeleting() { return $this->softDelete; } public function setSoftDeleting($enabled) { $this->softDelete = $enabled; } protected function getMorphs($name, $type, $id) { $type = $type ?: $name.'_type'; $id = $id ?: $name.'_id'; return array($type, $id); } public function getMorphClass() { return $this->morphClass ?: get_class($this); } public function getPerPage() { return $this->perPage; } public function setPerPage($perPage) { $this->perPage = $perPage; } public function getForeignKey() { return snake_case(class_basename($this)).'_id'; } public function getHidden() { return $this->hidden; } public function setHidden(array $hidden) { $this->hidden = $hidden; } public function setVisible(array $visible) { $this->visible = $visible; } public function setAppends(array $appends) { $this->appends = $appends; } public function getFillable() { return $this->fillable; } public function fillable(array $fillable) { $this->fillable = $fillable; return $this; } public function guard(array $guarded) { $this->guarded = $guarded; return $this; } public static function unguard() { static::$unguarded = true; } public static function reguard() { static::$unguarded = false; } public static function setUnguardState($state) { static::$unguarded = $state; } public function isFillable($key) { if (static::$unguarded) return true; if (in_array($key, $this->fillable)) return true; if ($this->isGuarded($key)) return false; return empty($this->fillable) && ! starts_with($key, '_'); } public function isGuarded($key) { return in_array($key, $this->guarded) || $this->guarded == array('*'); } public function totallyGuarded() { return count($this->fillable) == 0 && $this->guarded == array('*'); } protected function removeTableFromKey($key) { if ( ! str_contains($key, '.')) return $key; return last(explode('.', $key)); } public function getTouchedRelations() { return $this->touches; } public function setTouchedRelations(array $touches) { $this->touches = $touches; } public function getIncrementing() { return $this->incrementing; } public function setIncrementing($value) { $this->incrementing = $value; } public function toJson($options = 0) { return json_encode($this->toArray(), $options); } public function toArray() { $attributes = $this->attributesToArray(); return array_merge($attributes, $this->relationsToArray()); } public function attributesToArray() { $attributes = $this->getArrayableAttributes(); foreach ($this->getDates() as $key) { if ( ! isset($attributes[$key])) continue; $attributes[$key] = (string) $this->asDateTime($attributes[$key]); } foreach ($this->getMutatedAttributes() as $key) { if ( ! array_key_exists($key, $attributes)) continue; $attributes[$key] = $this->mutateAttributeForArray( $key, $attributes[$key] ); } foreach ($this->appends as $key) { $attributes[$key] = $this->mutateAttributeForArray($key, null); } return $attributes; } protected function getArrayableAttributes() { return $this->getArrayableItems($this->attributes); } public function relationsToArray() { $attributes = array(); foreach ($this->getArrayableRelations() as $key => $value) { if (in_array($key, $this->hidden)) continue; if ($value instanceof ArrayableInterface) { $relation = $value->toArray(); } elseif (is_null($value)) { $relation = $value; } if (static::$snakeAttributes) { $key = snake_case($key); } if (isset($relation) || is_null($value)) { $attributes[$key] = $relation; } } return $attributes; } protected function getArrayableRelations() { return $this->getArrayableItems($this->relations); } protected function getArrayableItems(array $values) { if (count($this->visible) > 0) { return array_intersect_key($values, array_flip($this->visible)); } return array_diff_key($values, array_flip($this->hidden)); } public function getAttribute($key) { $inAttributes = array_key_exists($key, $this->attributes); if ($inAttributes || $this->hasGetMutator($key)) { return $this->getAttributeValue($key); } if (array_key_exists($key, $this->relations)) { return $this->relations[$key]; } $camelKey = camel_case($key); if (method_exists($this, $camelKey)) { return $this->getRelationshipFromMethod($key, $camelKey); } } protected function getAttributeValue($key) { $value = $this->getAttributeFromArray($key); if ($this->hasGetMutator($key)) { return $this->mutateAttribute($key, $value); } elseif (in_array($key, $this->getDates())) { if ($value) return $this->asDateTime($value); } return $value; } protected function getAttributeFromArray($key) { if (array_key_exists($key, $this->attributes)) { return $this->attributes[$key]; } } protected function getRelationshipFromMethod($key, $camelKey) { $relations = $this->$camelKey(); if ( ! $relations instanceof Relation) { throw new LogicException('Relationship method must return an object of type ' . 'Illuminate\Database\Eloquent\Relations\Relation'); } return $this->relations[$key] = $relations->getResults(); } public function hasGetMutator($key) { return method_exists($this, 'get'.studly_case($key).'Attribute'); } protected function mutateAttribute($key, $value) { return $this->{'get'.studly_case($key).'Attribute'}($value); } protected function mutateAttributeForArray($key, $value) { $value = $this->mutateAttribute($key, $value); return $value instanceof ArrayableInterface ? $value->toArray() : $value; } public function setAttribute($key, $value) { if ($this->hasSetMutator($key)) { $method = 'set'.studly_case($key).'Attribute'; return $this->{$method}($value); } elseif (in_array($key, $this->getDates())) { if ($value) { $value = $this->fromDateTime($value); } } $this->attributes[$key] = $value; } public function hasSetMutator($key) { return method_exists($this, 'set'.studly_case($key).'Attribute'); } public function getDates() { $defaults = array(static::CREATED_AT, static::UPDATED_AT, static::DELETED_AT); return array_merge($this->dates, $defaults); } public function fromDateTime($value) { $format = $this->getDateFormat(); if ($value instanceof DateTime) { } elseif (is_numeric($value)) { $value = Carbon::createFromTimestamp($value); } elseif (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $value)) { $value = Carbon::createFromFormat('Y-m-d', $value)->startOfDay(); } elseif ( ! $value instanceof DateTime) { $value = Carbon::createFromFormat($format, $value); } return $value->format($format); } protected function asDateTime($value) { if (is_numeric($value)) { return Carbon::createFromTimestamp($value); } elseif (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $value)) { return Carbon::createFromFormat('Y-m-d', $value)->startOfDay(); } elseif ( ! $value instanceof DateTime) { $format = $this->getDateFormat(); return Carbon::createFromFormat($format, $value); } return Carbon::instance($value); } protected function getDateFormat() { return $this->getConnection()->getQueryGrammar()->getDateFormat(); } public function replicate() { $attributes = array_except($this->attributes, array($this->getKeyName())); with($instance = new static)->setRawAttributes($attributes); return $instance->setRelations($this->relations); } public function getAttributes() { return $this->attributes; } public function setRawAttributes(array $attributes, $sync = false) { $this->attributes = $attributes; if ($sync) $this->syncOriginal(); } public function getOriginal($key = null, $default = null) { return array_get($this->original, $key, $default); } public function syncOriginal() { $this->original = $this->attributes; return $this; } public function isDirty($attribute) { return array_key_exists($attribute, $this->getDirty()); } public function getDirty() { $dirty = array(); foreach ($this->attributes as $key => $value) { if ( ! array_key_exists($key, $this->original)) { $dirty[$key] = $value; } elseif ($value !== $this->original[$key] && ! $this->originalIsNumericallyEquivalent($key)) { $dirty[$key] = $value; } } return $dirty; } protected function originalIsNumericallyEquivalent($key) { $current = $this->attributes[$key]; $original = $this->original[$key]; return is_numeric($current) && is_numeric($original) && strcmp((string) $current, (string) $original) === 0; } public function getRelations() { return $this->relations; } public function getRelation($relation) { return $this->relations[$relation]; } public function setRelation($relation, $value) { $this->relations[$relation] = $value; return $this; } public function setRelations(array $relations) { $this->relations = $relations; return $this; } public function getConnection() { return static::resolveConnection($this->connection); } public function getConnectionName() { return $this->connection; } public function setConnection($name) { $this->connection = $name; return $this; } public static function resolveConnection($connection = null) { return static::$resolver->connection($connection); } public static function getConnectionResolver() { return static::$resolver; } public static function setConnectionResolver(Resolver $resolver) { static::$resolver = $resolver; } public static function unsetConnectionResolver() { static::$resolver = null; } public static function getEventDispatcher() { return static::$dispatcher; } public static function setEventDispatcher(Dispatcher $dispatcher) { static::$dispatcher = $dispatcher; } public static function unsetEventDispatcher() { static::$dispatcher = null; } public function getMutatedAttributes() { $class = get_class($this); if (isset(static::$mutatorCache[$class])) { return static::$mutatorCache[get_class($this)]; } return array(); } public function __get($key) { return $this->getAttribute($key); } public function __set($key, $value) { $this->setAttribute($key, $value); } public function offsetExists($offset) { return isset($this->$offset); } public function offsetGet($offset) { return $this->$offset; } public function offsetSet($offset, $value) { $this->$offset = $value; } public function offsetUnset($offset) { unset($this->$offset); } public function __isset($key) { return ((isset($this->attributes[$key]) || isset($this->relations[$key])) || ($this->hasGetMutator($key) && ! is_null($this->getAttributeValue($key)))); } public function __unset($key) { unset($this->attributes[$key]); unset($this->relations[$key]); } public function __call($method, $parameters) { if (in_array($method, array('increment', 'decrement'))) { return call_user_func_array(array($this, $method), $parameters); } $query = $this->newQuery(); return call_user_func_array(array($query, $method), $parameters); } public static function __callStatic($method, $parameters) { $instance = new static; return call_user_func_array(array($instance, $method), $parameters); } public function __toString() { return $this->toJson(); } public function __wakeup() { $this->bootIfNotBooted(); } } 
 namespace Illuminate\Database; use Illuminate\Database\Connectors\ConnectionFactory; class DatabaseManager implements ConnectionResolverInterface { protected $app; protected $factory; protected $connections = array(); protected $extensions = array(); public function __construct($app, ConnectionFactory $factory) { $this->app = $app; $this->factory = $factory; } public function connection($name = null) { $name = $name ?: $this->getDefaultConnection(); if ( ! isset($this->connections[$name])) { $connection = $this->makeConnection($name); $this->connections[$name] = $this->prepare($connection); } return $this->connections[$name]; } public function reconnect($name = null) { $name = $name ?: $this->getDefaultConnection(); $this->disconnect($name); return $this->connection($name); } public function disconnect($name = null) { $name = $name ?: $this->getDefaultConnection(); unset($this->connections[$name]); } protected function makeConnection($name) { $config = $this->getConfig($name); if (isset($this->extensions[$name])) { return call_user_func($this->extensions[$name], $config, $name); } $driver = $config['driver']; if (isset($this->extensions[$driver])) { return call_user_func($this->extensions[$driver], $config, $name); } return $this->factory->make($config, $name); } protected function prepare(Connection $connection) { $connection->setFetchMode($this->app['config']['database.fetch']); if ($this->app->bound('events')) { $connection->setEventDispatcher($this->app['events']); } $app = $this->app; $connection->setCacheManager(function() use ($app) { return $app['cache']; }); $connection->setPaginator(function() use ($app) { return $app['paginator']; }); return $connection; } protected function getConfig($name) { $name = $name ?: $this->getDefaultConnection(); $connections = $this->app['config']['database.connections']; if (is_null($config = array_get($connections, $name))) { throw new \InvalidArgumentException("Database [$name] not configured."); } return $config; } public function getDefaultConnection() { return $this->app['config']['database.default']; } public function setDefaultConnection($name) { $this->app['config']['database.default'] = $name; } public function extend($name, $resolver) { $this->extensions[$name] = $resolver; } public function getConnections() { return $this->connections; } public function __call($method, $parameters) { return call_user_func_array(array($this->connection(), $method), $parameters); } } 
 namespace Illuminate\Database; interface ConnectionResolverInterface { public function connection($name = null); public function getDefaultConnection(); public function setDefaultConnection($name); } 
 namespace Illuminate\Database\Connectors; use PDO; use Illuminate\Container\Container; use Illuminate\Database\MySqlConnection; use Illuminate\Database\SQLiteConnection; use Illuminate\Database\PostgresConnection; use Illuminate\Database\SqlServerConnection; class ConnectionFactory { protected $container; public function __construct(Container $container) { $this->container = $container; } public function make(array $config, $name = null) { $config = $this->parseConfig($config, $name); if (isset($config['read'])) { return $this->createReadWriteConnection($config); } else { return $this->createSingleConnection($config); } } protected function createSingleConnection(array $config) { $pdo = $this->createConnector($config)->connect($config); return $this->createConnection($config['driver'], $pdo, $config['database'], $config['prefix'], $config); } protected function createReadWriteConnection(array $config) { $connection = $this->createSingleConnection($this->getWriteConfig($config)); return $connection->setReadPdo($this->createReadPdo($config)); } protected function createReadPdo(array $config) { $readConfig = $this->getReadConfig($config); return $this->createConnector($readConfig)->connect($readConfig); } protected function getReadConfig(array $config) { $readConfig = $this->getReadWriteConfig($config, 'read'); return $this->mergeReadWriteConfig($config, $readConfig); } protected function getWriteConfig(array $config) { $writeConfig = $this->getReadWriteConfig($config, 'write'); return $this->mergeReadWriteConfig($config, $writeConfig); } protected function getReadWriteConfig(array $config, $type) { if (isset($config[$type][0])) { return $config[$type][array_rand($config[$type])]; } else { return $config[$type]; } } protected function mergeReadWriteConfig(array $config, array $merge) { return array_except(array_merge($config, $merge), array('read', 'write')); } protected function parseConfig(array $config, $name) { return array_add(array_add($config, 'prefix', ''), 'name', $name); } public function createConnector(array $config) { if ( ! isset($config['driver'])) { throw new \InvalidArgumentException("A driver must be specified."); } if ($this->container->bound($key = "db.connector.{$config['driver']}")) { return $this->container->make($key); } switch ($config['driver']) { case 'mysql': return new MySqlConnector; case 'pgsql': return new PostgresConnector; case 'sqlite': return new SQLiteConnector; case 'sqlsrv': return new SqlServerConnector; } throw new \InvalidArgumentException("Unsupported driver [{$config['driver']}]"); } protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = array()) { if ($this->container->bound($key = "db.connection.{$driver}")) { return $this->container->make($key, array($connection, $database, $prefix, $config)); } switch ($driver) { case 'mysql': return new MySqlConnection($connection, $database, $prefix, $config); case 'pgsql': return new PostgresConnection($connection, $database, $prefix, $config); case 'sqlite': return new SQLiteConnection($connection, $database, $prefix, $config); case 'sqlsrv': return new SqlServerConnection($connection, $database, $prefix, $config); } throw new \InvalidArgumentException("Unsupported driver [$driver]"); } } 

 namespace Reborn\Cores; use Reborn\Http\Request; use Reborn\Http\Response; use Reborn\Http\Uri; use Reborn\Routing\Router; use Reborn\Routing\RouteCollection; use Reborn\MVC\View\ViewManager; use Reborn\Parser\InfoParser; use Reborn\Config\Config; use Reborn\Filesystem\File; use Reborn\Widget\Widget; use Reborn\Util\Security; use Reborn\Translate\Loader\PHPFileLoader; use Reborn\Event\EventManager as Event; use Reborn\Cache\CacheManager; use Reborn\Connector\Log\LogManager; use Reborn\Connector\DB\DBManager as DB; use Reborn\Module\ModuleManager as Module; use Reborn\Exception\RbException; use Reborn\Exception\TokenNotMatchException; use Reborn\Exception\MaintainanceModeException; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler; class Application extends \Illuminate\Container\Container { protected $started = false; public function __construct() { $this['error_handler'] = new ErrorHandler($this); $this['request'] = $this->solveRequest(); Request::enableHttpMethodParameterOverride(); Registry::set('app', $this); } public function solveRequest() { if ($this->runInCli()) { return Request::create('http://localhost/', 'GET', array(), array(), array(), $_SERVER); } return Request::createFromGlobals(); } public function solveSession() { if ($this->runInCli()) { return new Session(new MockArraySessionStorage('reborn_session')); } else { $lifetime = $this['config']->get('app.session_lifetime', 60) * 60; $options = array('gc_maxlifetime' => $lifetime); $h = new NativeFileSessionHandler($this['config']->get('app.session_path', null)); return new Session(new NativeSessionStorage($options, $h)); } } public function setAppEnvironment($env) { $accept_envs = array('dev', 'test', 'production'); $this['env'] = in_array($env, $accept_envs) ? $env : 'production'; } public function getAppEnvironment() { return $this['env']; } public function runInDevelopment() { return ($this['env'] === 'dev'); } public function runInProduction() { return ($this['env'] === 'production'); } public function runInTesting() { return ($this['env'] === 'test'); } public function runInCli() { return (php_sapi_name() === 'cli'); } public function installed() { if (! File::is(APP.'config'.DS.'db.php')) { if (!\Reborn\Filesystem\Directory::is(BASE.'installer')) { throw new RbException("Can't find db.php at config folder"); } return false; } return true; } public function install() { if (File::is(APP.'config'.DS.'db.php')) { throw new RbException("Reborn CMS is already installed!"); } require BASE.'installer'.DS.'Installer.php'; \Installer::init($this); \Installer::start(); exit; } public function start($session_is_started = false) { if ($this->started) { throw new RbException("Reborn CMS Application is already started!"); } $this->registerToContainer(); $this->setErrorHandler(); $this->appInitialize($session_is_started); $this->authProviderRegister(); Event::call('reborn.app.starting'); $this->setTimezone(\Setting::get('timezone', 'UTC')); } public function run() { try { $response = $this['router']->dispatch(); $this->started = true; if (!$response instanceof SymfonyResponse) { $response = new Response($response); } $this->end($response); } catch (TokenNotMatchException $e) { \Translate::load('global'); \Flash::error(t('global.csrf_fail')); $basepath = $this['request']->getBasePath(); $redirect_url = str_replace($basepath, '', \Input::server('REDIRECT_URL')); return \Redirect::to($redirect_url); } catch (MaintainanceModeException $e) { $this->end(Response::maintain()); exit(1); } } protected function registerToContainer() { $this['config'] = $this->share(function ($app) { return new Config($app); }); $this['site_manager'] = $this->share(function ($app) { return new SiteManager($app); }); $this['cache'] = $this->share( function ($app) { return new CacheManager($app); }); $this['route_collection'] = $this->share(function ($app) { return new RouteCollection(); }); $this['router'] = $this->share(function ($app) { return new Router($app); }); $this['log'] = $this->share(function ($app) { return new LogManager($app); }); $this['view_manager'] = $this->share( function ($app) { return new ViewManager($app); }); $this['view'] = $this->share( function ($app) { return $app['view_manager']->getView(); }); $this['info_parser'] = $this->share( function ($app) { return new InfoParser(); }); $this['theme'] = $this->share( function ($app) { return $app['view_manager']->getTheme(); }); $this['template'] = $this->share( function ($app) { return $app['view_manager']->getTemplate(); }); $this['session'] = $this->solveSession(); $this['widget'] = $this->share( function ($app) { return new Widget($app); }); $this['profiler'] = $this->share( function () { return new Profiler(); }); $this['translate_loader'] = $this->share( function ($app) { return new PHPFileLoader($app); }); } public function appInitialize($session_is_started) { if ($this->started) { return true; } if (isset($this['session'])) { if (! $session_is_started) { $this['session']->start(); } \Security::setApplication($this); $csrf = $this['config']->get('app.security.csrf_key'); if ( ! $this['session']->has($csrf)) { \Security::makeCSRFToken(); } } if (('dev' == $this['env']) and $this['config']->get('app.profiler')) { $this['profiler']->start(); } Event::initialize($this); DB::initialize($this); Setting::initialize($this); Uri::initialize($this->request); Module::initialize($this); $this['widget']->initialize(); } public function end(SymfonyResponse $response) { if (('dev' == $this['env']) and $this['config']->get('app.profiler')) { $this['profiler']->stop(); if (!$response instanceof JsonResponse || !$response instanceof StreamedResponse) { if (Event::has('reborn.app.profiling')) { $result = Event::call('reborn.app.profiling', $response->getContent()); $response->setContent($result[0]); } } } if (!$response instanceof JsonResponse || !$response instanceof StreamedResponse) { if (Event::has('reborn.responsecontent.final')) { $content = $response->getContent(); $content = Event::first('reborn.responsecontent.final', array($content)); $response->setContent($content); } } Event::call('reborn.app.ending', array($response)); return $response->send(); } public function authProviderRegister(\Closure $callback = null) { $this['auth_provider'] = $this->share( function ($app) use ($callback) { $provider = null; if (! is_null($callback) ) { $provider = $callback($app); } if (! $provider instanceof \Reborn\Auth\AuthProviderInterface) { $provider = new \Reborn\Auth\AuthSentryProvider($app); } return $provider; }); $this['user_provider'] = $this->share( function ($app) { return $app['auth_provider']->getUserProvider(); }); $this['usergroup_provider'] = $this->share( function ($app) { return $app['auth_provider']->getGroupProvider(); }); } public function setLocale($locale = 'en') { $this['locale'] = $locale; \Translate::setLocale($locale); Event::call('reborn.app.locale_change', array($locale)); } public function setTimezone($tz = 'UTC') { date_default_timezone_set($tz); } public function setErrorHandler() { $this['error_handler']->register(); } public function __set($key, $value) { $this[$key] = $value; } public function __get($key) { return isset($this[$key]) ? $this[$key] : null; } public function injectCSRFToken($response) { $token = Security::CSRField(); preg_match('/(value\s*=\s*"(.*)")/', $token, $m); $meta = \Html::meta('csrf-token', $m[2]); $body = $response->getContent(); preg_match('/(<\/(head|HEAD)>)/', $body, $m); $body = preg_replace('/(<\/(head|HEAD)>)/', $meta."\n".'$0', $body); $pattern = '/(<(form|FORM)[^>]*(method|METHOD)="(post|POST)"[^>]*>)/'; preg_match_all($pattern, $body, $matches, PREG_SET_ORDER); if (is_array($matches)) { foreach ($matches as $match) { if (false == strpos($match[0], 'nocsrf')) { $body = str_replace($match[0], $match[0]."\n\t" .$token, $body); } } } $response->setContent($body); return $response; } } 

 namespace Reborn\Cores; use Reborn\Exception\RbException; class Alias { protected static $coreIsAlias = false; protected static $coreClasses = array( 'Auth' => 'Reborn\Auth\AuthFacade', 'User' => 'Reborn\Auth\UserFacade', 'UserGroup' => 'Reborn\Auth\GroupFacade', 'Facade' => 'Reborn\Cores\Facade', 'Cache' => 'Reborn\Cache\CacheFacade', 'Config' => 'Reborn\Config\ConfigFacade', 'NotAuthException' => 'Reborn\MVC\Controller\Exception\NotAuthException', 'NotAdminAccessException' => 'Reborn\MVC\Controller\Exception\NotAdminAccessException', 'AdminController' => 'Reborn\MVC\Controller\AdminController', 'PublicController' => 'Reborn\MVC\Controller\PublicController', 'PrivateController' => 'Reborn\MVC\Controller\PrivateController', 'Controller' => 'Reborn\MVC\Controller\Controller', 'DB' => 'Reborn\Connector\DB\DBManager', 'Dir' => 'Reborn\Filesystem\Directory', 'Dummy' => 'Reborn\Dummy\Generator', 'Eloquent' => 'Reborn\MVC\Model\Model', 'Event' => 'Reborn\Event\EventManager', 'Error' => 'Reborn\Cores\ErrorFacade', 'File' => 'Reborn\Filesystem\File', 'Flash' => 'Reborn\Util\Flash', 'Hash' => 'Reborn\Util\Hash', 'Html' => 'Reborn\Util\Html', 'HttpNotFoundException' => 'Reborn\Exception\HttpNotFoundException', 'Mailer' => '\Reborn\Mail\Mailer', 'Pagination' => 'Reborn\Pagination\PaginationFacade', 'RbException' => 'Reborn\Exception\RbException', 'Request' => 'Reborn\Http\Request', 'Redirect' => 'Reborn\Http\Redirect', 'Response' => 'Reborn\Http\Response', 'Form' => 'Reborn\Form\UIForm', 'FormBuilder' => 'Reborn\Form\AbstractFormBuilder', 'Input' => 'Reborn\Http\Input', 'Log' => 'Reborn\Connector\Log\LoggerFacade', 'Module' => 'Reborn\Module\ModuleManager', 'Presenter' => 'Reborn\Presenter\Presentation', 'PresenterCollection' => 'Reborn\Presenter\Collection', 'Registry' => 'Reborn\Cores\Registry', 'Route' => 'Reborn\Routing\RouteFacade', 'Router' => 'Reborn\Routing\Router', 'Schema' => 'Reborn\Connector\DB\Schema', 'Security' => 'Reborn\Util\Security', 'Setting' => 'Reborn\Cores\Setting', 'Str' => 'Reborn\Util\Str', 'Table' => 'Reborn\Table\Builder', 'DataTable' => 'Reborn\Table\DataTable', 'DataTableBuilder' => 'Reborn\Table\DataTable\UI', 'ToolKit' => 'Reborn\Util\ToolKit', 'Translate' => 'Reborn\Translate\TranslateManager', 'Uri' => 'Reborn\Http\Uri', 'Validation' => 'Reborn\Form\Validation', 'ViewData' => 'Reborn\MVC\View\ViewData', 'Widget' => 'Reborn\Widget\Widget', 'AbstractWidget' => 'Reborn\Widget\AbstractWidget' ); final public function __construct() {} public static function coreClassAlias() { if (! static::$coreIsAlias) { static::aliasRegister(static::$coreClasses); static::$coreIsAlias = true; } } public static function aliasRegister($classes = array()) { foreach ($classes as $alias => $class) { if (static::$coreIsAlias) { if (array_key_exists($alias, static::$coreClasses) and $class == static::$coreClasses[$alias]) { throw new RbException("$alias is already exists!"); } } class_alias($class, $alias); } } } 

 namespace Reborn\Cores; class ErrorFacade extends Facade { protected static function getInstance() { return static::$app['error_handler']; } } 
Reborn\Cores\Application::run( ) # Line No. 189
{{ CMS }} » index.php
 *
 */
if ($app->installed()) {
    $app->start();

    $app->run();
} else {
	$app->install();
}
1