public function render($content_view, $data = null) { if (is_array($data)) { extract($data); } ob_start(); include 'application/views/' . mb_strtolower($this->controller) . '/' . $content_view . '.php'; $content = ob_get_contents(); ob_end_clean(); include 'application/views/layouts/' . $this->layout . '.php'; Mi::app()->log->draw(); }
function __construct() { $path = explode('?', $_SERVER['REQUEST_URI'])[0]; $routes = explode('/', $path); if (!empty($routes[1])) { $this->controller = ucfirst($routes[1]); } if (!empty($routes[2])) { $this->action = $routes[2]; } $this->controller = $this->controller . 'Controller'; $this->action = 'action' . ucfirst($this->action); $rules = Mi::app()->urlRules(); if (isset($rules[$path])) { $routes = explode('/', $rules[$path]); $this->controller = ucfirst($routes[0]) . 'Controller'; $this->action = 'action' . ucfirst($routes[1]); } }
public function draw() { if (!LOG) { return false; } $find = ['select', 'from', 'where', 'order by', 'limit', 'offset', '(', ')']; $replace = ['<span class="op">select</span>', '<span class="op">from</span>', '<span class="op">where</span>', '<span class="op">order by</span>', '<span class="op">limit</span>', '<span class="op">offset</span>', '<span class="op">(</span>', '<span class="op">)']; $querys = $this->mysql(); $data = []; $i = 0; foreach ($querys as $query) { $data[$i]['sql'] = str_replace($find, $replace, strtolower($query['sql'])); $data[$i]['time'] = $query['time']; $i++; } if (!isset($querys[Mi::app()->session->get('log_sql_session_id')])) { $data = []; } include 'views/log.php'; }
/** * cakeVersion method * * @return void * @access protected */ protected static function cakeVersion() { if (Mi::$cakeVersion) { return Mi::$cakeVersion; } return Mi::$cakeVersion = substr(Configure::version(), 0, 3); }
/** * exec method * * @param mixed $cmd * @param mixed $out null * @return true on success, false on failure * @access protected */ protected function _exec($cmd, &$out = null) { if (!class_exists('Mi')) { APP::import('Vendor', 'Mi.Mi'); } return Mi::exec($cmd, $out); }
public function actionIndex() { $this->pageTitle = 'Главная страница'; $this->render('index', ['time' => Mi::app()->timeRequest, 'data' => User::model()->findByPk(1)]); }
function __construct($class_name) { $this->model = new $class_name(); $this->db = Mi::app()->db; }
<?php // Показываем все ошибки ini_set('display_errors', 1); // Корневая директория define('ROOT', $_SERVER['DOCUMENT_ROOT']); // Логировать запросы и прочее? define('LOG', TRUE); // Ядро require_once 'core/mi.php'; // Запускаем Micros Mi::init(); // Загружаем роутер $router = new Router(); // Запускаем роутер $router->start();
public function timeRequest() { $time = microtime(true) - Mi::app()->session->get('microtime'); return sprintf('%.4F сек.', $time); }
private function prepareQuery($args) { $query = ''; $raw = array_shift($args); $array = preg_split('~(\\?[nsiuap])~u', $raw, null, PREG_SPLIT_DELIM_CAPTURE); $anum = count($args); $pnum = floor(count($array) / 2); if ($pnum != $anum) { $this->error("Number of args ({$anum}) doesn't match number of placeholders ({$pnum}) in [{$raw}]"); } foreach ($array as $i => $part) { if ($i % 2 == 0) { $query .= $part; continue; } $value = array_shift($args); switch ($part) { case '?n': $part = $this->escapeIdent($value); break; case '?s': $part = $this->escapeString($value); break; case '?i': $part = $this->escapeInt($value); break; case '?a': $part = $this->createIN($value); break; case '?u': $part = $this->createSET($value); break; case '?p': $part = $value; break; } $query .= $part; } Mi::app()->log->query($query); return $query; }
/** * exec method * * @param mixed $cmd * @param mixed $out null * @return void * @access protected */ protected function _exec($cmd, &$out = array()) { MiInstall::_progress($cmd, ' '); if (defined('CAKE_SHELL') && CAKE_SHELL) { system($cmd, $return); return $return; } MiInstall::_progress($out, ' '); if (!class_exists('Mi')) { App::import('Vendor', 'Mi.Mi'); } Mi::exec($cmd, $out); }
/** * exec method * * @param mixed $cmd * @param mixed $out null * @return void * @access protected */ protected static function _exec($cmd, &$out = null) { if (!class_exists('Mi')) { App::uses('Mi', 'Mi.Vendor'); } return Mi::exec($cmd, $out); }
/** * populateVendorMap method * * @param bool $reset false * @static * @return void * @access protected */ protected static function _populateVendorMap($reset = false) { if ($reset || !self::$vendorMap) { App::import('Vendor', 'Mi.MiCache'); $plugins = MiCache::mi('plugins'); foreach ($plugins as $path => $plugin) { if (is_dir($path . DS . 'webroot')) { if (!class_exists('Mi')) { APP::import('Vendor', 'Mi.Mi'); } $files = Mi::files($path . DS . 'webroot', null, '.*\\.(css|js)$'); foreach ($files as $fPath) { $fPath = realpath($fPath); self::$vendorMap[str_replace(realpath($path . DS . 'webroot') . DS, $plugin . DS, $fPath)] = $fPath; } } } self::log("Populating Vendor Map"); if (!class_exists('MiCache')) { self::log("\tMiCache doesn't exist. Skipping."); return; } self::$vendorMap = am(self::$vendorMap, MiCache::mi('vendors', null, array('shells'), array('excludeFolders' => array('shells', 'simpletest'), 'extension' => array('css', 'js'), 'excludePattern' => false))); self::log("\tDone."); } }
<?php spl_autoload_register(function ($class) { if (file_exists(ROOT . '/application/models/' . $class . '.php')) { include ROOT . '/application/models/' . $class . '.php'; } else { $map = Mi::app()->map; if (count($map) > 0) { foreach ($map as $path) { if (file_exists(ROOT . $path . $class . '.php')) { include ROOT . $path . $class . '.php'; } } } } });