public function init($yaf_app) { static $initialized = false; if (!$initialized) { $initialized = true; \Yaf\Loader::import(YK_CORE_ROOT . '/func.php'); $config = $yaf_app->getConfig()->toArray(); \Yaf\Registry::set('_config', $config); $level = $config['debug'] ? $config['debug'] == 1 ? E_ERROR : E_ALL : 0; define('MAIN_DEBUG', $config['debug']); if (MAIN_DEBUG) { ini_set('display_error', 'On'); } error_reporting($level); define('TIMESTAMP', time()); \Yaf\Registry::set('_clientip', isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'N/A'); \Yaf\Registry::set('_clientport', isset($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : 0); \Yaf\Registry::set('_gzip', !isset($_SERVER['HTTP_ACCEPT_ENCODING']) || strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === false || !function_exists('ob_gzhandler') ? false : true); set_timeoffset($config['timeoffset']); //重置视图 $view = new view(); \Yaf\Registry::set('_view', $view); $yaf_app->getDispatcher()->setView($view); define('CHARSET', 'utf-8'); //end } }
<?php define('PATH', dirname(dirname(__FILE__))); function set_timeoffset($offset = 0) { date_default_timezone_set('Etc/GMT' . ($offset > 0 ? '-' : '+') . abs($offset)); } set_timeoffset(8); if (!empty($argv)) { $app = null; switch ($argc) { case 3: $app = $argv[2]; case 2: $table = $argv[1]; break; case 1: echo "\$1 table name, \$2 app name", PHP_EOL; exit; break; } } else { exit('only support cli mode'); } if (strpos($table, '_') !== false) { $path = explode('_', $table); $file = array_pop($path); $dir = implode('/', $path); @mkdir(PATH . '/models/' . $dir, 0755, true); mkfile('\\yk\\mysql\\database', $table, PATH . '/models/' . $dir . '/' . $file . '.php', false); if ($app) {