function render($template = null) { ob_start(); if ($this->renderer) { call_user_func($this->renderer, $this); } else { if ($template == null) { $template = $this->template; } $env = \Phlex\Env\Environment::instance(); $file = $env['kraft']['template'] . $template . '.' . $env['kraft']['ext']; if (file_exists($file)) { include $file; } else { trigger_error('Template not found: "' . $file . '""', E_USER_ERROR); } } return ob_get_clean(); }
function parse($source = null, $destination = null, $force = false) { $env = Environment::instance(); if ($source == null) { $source = $env['kraft']['template-source']; } if ($destination == null) { $destination = $env['kraft']['template']; } if (!$source or !$destination) { return; } $source = $source . '/'; $destination = $destination . '/'; $src = array_diff(scandir($source), array('.', '..')); if (!is_dir($destination)) { mkdir($destination); } $dest = array_diff(scandir($destination), array('.', '..')); $dest = array_fill_keys($dest, false); foreach ($src as $item) { if (is_dir($source . $item)) { $this->parse($source . $item, $destination . $item, $force); } else { if ($force || !file_exists($destination . $item) || filemtime($source . $item) > filemtime($destination . $item)) { $this->parseFile($source . $item, $destination . $item); } } $dest[$item] = true; } foreach ($dest as $item => $state) { if (!$state) { is_dir($destination . $item) ? static::delTree($destination . $item) : unlink($destination . $item); } } }
<?php ob_start(); //$GLOBALS['__time'] = microtime(true); register_shutdown_function(function(){ echo('X-Run Time: '.(microtime(true) - $GLOBALS['__time'])); }); require_once '../modules/autoload.php'; require_once '../application/autoload.php'; $env = \Phlex\Env\Environment::instance(); if ($env['dev-mode']) { // system('php '.$env['root'].'phlex.php config -q'); system('php ' . $env['root'] . 'phlex.php build -q -f'); } $dispatcher = new Phlex\Routing\Dispatcher(\Phlex\Request\Request::getCurrent()); $dispatcher('www.*', function () { $app = new \App\www\App(); $app->route(); }); $dispatcher('admin.*', function () { /*dummy*/ }); $dispatcher('*', function () { header('Request Method: GET'); header('Location:' . 'http://www.' . $_SERVER['SERVER_NAME']); die; });