public function run() { $a = explode('/', preg_replace('/^\\//', '', $_SERVER['PATH_INFO'], 1)); // var_dump($a);exit; $action_num = count($a); if ($action_num == 1) { //对内api接口 //访问例如:http://framework.mytest.com/add_folder?a=bb $this->folder = 'api'; $action = $a[0]; $action = strtolower(str_replace('_', '', trim($action))); } elseif ($action_num == 2) { //web应用程序 //访问例如:http://framework.mytest.com/index/index?a=bb $this->folder = 'app'; $action = implode('\\', $a); $action = strtolower(trim($action)); } else { header('HTTP/1.1 404 Not Found'); exit; } $actionsMap = \TeoPHP\Application::getConfig($this->folder, $this->config_path); if (!array_key_exists($action, $actionsMap)) { header('HTTP/1.1 404 Not Found'); exit; } // var_dump($actionsMap[$action]);exit; //从actionMap获得的路由地址 即configs/route里的action地址 例如: array('index\\Index', true) $this->route_address = $actionsMap[$action]; return $this; }
/** * 输出jsonp * @param string $js_callback */ public function returnJsonp($js_callback = 'callback') { //为了支持跨域操作 if (Application::getRequest()->checkIEByUserAgent()) { //IE header('Content-type: text/javascript;charset=utf-8'); //解决jsonp种cookie在ie浏览器下被拦截 header("P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"); } else { header('Content-type: application/javascript;charset=utf-8'); } echo $js_callback . "(" . json_encode($this->json_format) . ");"; exit; }
/** * 唯一单例入口 * 数据库的名字 * @param $db * 数据库类型 主库还是副库 master or slave * @param $db_type * 是否长连接 true or false * @param bool $p_connect * @param null $timeout * @param null $charset * @return mixed */ public static function connect($db, $db_type, $p_connect = false, $timeout = null, $charset = null) { if (empty(self::$connects[$db][$db_type])) { //获得配置文件 self::$config = \TeoPHP\Application::getConfig('resource'); self::$db = $db; self::$db_type = $db_type; self::$p_connect = $p_connect; self::$timeout = $timeout; self::$charset = $charset; self::$charset = $charset; self::$charset = $charset; self::$connects[$db][$db_type] = new self(); } return self::$connects[$db][$db_type]; }
public function doAction() { $data = Application::verifyParam($_REQUEST, $this->params); if ($data->getErrorCode()) { Application::getLogger(__CLASS__ . ':' . __LINE__)->addError('Parameter error', $data->getErrorData()); #TODO 返回 die('welcome1'); // $this->writeLog('test', false, '测试1111', $encode, 'debug'); // $noticeMsg = $this->getNoticeMsg($returnArr[1]['code']); // $this->writeLog('mail', false, $noticeMsg, array($post, $returnArr[1]['data']), 'warning', 'lognum1'); // data_return($returnArr[1]['code'], $returnArr[1]['data']); } $data = $data->getData(); //$data为过滤后的数据 // $data // Application::getMysql('test', 'slave')->prepare('SELECT * FROM `test`'); // die('welcome'); return $data; }
function afterRequest($return_value) { if (!empty($return_value)) { //如果存在return $output = ''; if (isset($_GET['return'])) { $output = $_GET['return']; } $json = Application::getJson($return_value); switch ($output) { case 'jsonp': //为了支持跨域操作 $js_callback = "callback"; $json->returnJsonp($js_callback); break; default: //默认api都返回json格式 $json->returnJson(); break; } } }
public function doAction() { $a = Application::getConfig('resource'); var_dump($a); }
public function afterRequest($return_value) { if (!empty($return_value)) { Application::getTemplate($this->address)->display('', $return_value); } }
<?php define('BASEDIR', __DIR__); require BASEDIR . '/TeoPHP/Loader.php'; spl_autoload_register('\\TeoPHP\\Loader::autoload'); if (!is_readable('vendor')) { die('please run `composer install` first'); } require 'vendor/autoload.php'; require 'tools/helper.php'; $route = new \TeoPHP\lib\Route(); $route_lib = $route->run(); if ($route_lib->getFolder() == 'app') { $return = new \configs\decorator\Template(); } else { $return = new \configs\decorator\Json(); } $return->beforeRequest($route_lib->getRouteAddress()); $return_value = \TeoPHP\Application::run($route_lib->getRouteAddress(), $route_lib->getFolder()); $return->afterRequest($return_value);
<?php //接口 define('BASEDIR', __DIR__); require BASEDIR . '/TeoPHP/Loader.php'; spl_autoload_register('\\TeoPHP\\Loader::autoload'); if (!is_readable('vendor')) { die; } require 'vendor/autoload.php'; $a = explode('/', preg_replace('/^\\//', '', $_SERVER['PATH_INFO'], 1)); $action = implode('\\', $a); $action = strtolower(trim($action)); $actionsMap = \TeoPHP\Application::getConfig('route_interface'); if (!array_key_exists($action, $actionsMap)) { header('HTTP/1.1 404 Not Found'); exit; } \TeoPHP\Application::run($actionsMap[$action][0], $folder);