function _pi_autoloader_core($class) { if (($pos = strpos($class, '_')) !== false) { $class = explode('_', $class); if (empty($class)) { return false; } $first_dir = strtolower($class[0]); $fileName = array_pop($class); $class = array_map('strtolower', $class); $root = $first_dir == 'util' ? PI_ROOT : COM_ROOT; $file = $root . implode(DOT, $class) . DOT . $fileName . '.php'; if (is_readable($file)) { Pi::inc($file); } } else { //优先加载工程中的lib,其次加载框架中的util if (is_readable(PI_UTIl . $class . '.php')) { Pi::inc(PI_UTIl . $class . '.php'); } else { if (is_readable(COM_ROOT . 'lib/' . $class . '.php')) { Pi::inc(COM_ROOT . 'lib/' . $class . '.php'); } } } }
public function __construct() { $dispatcher = Conf::get('global.dispatcher_path', PI_CORE . 'RouteDispatcher.php'); if (!is_readable($dispatcher) || !Pi::inc($dispatcher)) { throw new Exception('can not find the dispatcher config : global.dispatcher_path', 1032); } }
public function index() { //$this->jump('/login',true); echo "<br>"; echo "in index"; echo "<br>"; $xz = new Xcrypt(); $num = rand(10000, 20000) . rand(10000, 20000) . rand(10000, 20000); $res = $xz->encode($num); echo $res; echo '<br>'; $login = Pi::com('login'); $res = $login->dologin(array('111' => 1241, 'hihu' => 1241)); print_r($res); // $q = new Queue("hihu",'users',600); // $q->push(array("queue"=>'真的')); // $q->push(array("queue"=>'真的')); // $q->push(array("queue"=>'真的')); // var_dump($q->getSize()); // var_dump($q->pop()); // var_dump($q->pop()); // var_dump($q->getSize()); // var_dump($q->clear()); // var_dump($q->pop()); }
public function __construct() { parent::__construct(); $this->load->model('product_catalog_model'); $this->load->model('product_packing_model'); $this->load->library('form_validation'); }
public function __construct() { parent::__construct(); $this->load->model('product_model'); $this->load->model('permission_block_model'); $this->load->model('product_permission_model'); }
public function __construct() { $dispatcher = Pcf::get('global.dispatcher_path', PIPE_HELPER . 'RouteDispatcher.php'); if (!Pi::inc($dispatcher)) { throw new Exception('can not find the dispatcher config : global.dispatcher_path', 1032); } }
public function execute(App $app) { $argv = $app->argv; $script = $app->task_name; $script = explode('_', $script); $cls_file = ucfirst(strtolower(array_pop($script))); if (empty($cls_file)) { throw new Exception('task.err for run the task for :' . $this->task_name, 1033); } $path = ''; $class = ''; if (!empty($script)) { foreach ($script as $p) { $p = strtolower($p); $path .= $p . DOT; $class .= ucfirst($p); } } $class .= $cls_file; $path = TASK_PATH . $path; $file = $path . $cls_file . '.php'; Pi::inc(PI_CORE . 'BaseTask.php'); if (!Pi::inc($file)) { throw new Exception('task.err can not load the file :' . $file, 1034); } if (!class_exists($class)) { throw new Exception('task.err can not find the class :' . $class, 1035); } $cls = new $class(); if (!is_subclass_of($cls, 'BaseTask')) { throw new Exception('task.err the class ' . $class . ' is not the subclass of BaseTask ', 1036); } $cls->execute($argv); }
/** * Invoke as a functor * * @return CacheAdapter */ public function __invoke() { if (!$this->cache) { $this->cache = clone Pi::service('cache')->storage(); $this->cache->getOptions()->setNamespace($this->getEvent()->getRouteMatch()->getParam('module') . 'action'); } return $this->cache; }
/** * @link http://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/ */ public function __construct() { $raspi = new Pi(); if ($raspi->getVersion() < 4) { $this->pins = array(0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25); $this->hackablePins = array(4, 7, 8, 9, 10, 11, 17, 18, 21, 22, 23, 24, 25); } else { if ($raspi->getVersion() < 16) { # new GPIO layout (REV2) $this->pins = array(2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 22, 23, 24, 25, 27); $this->hackablePins = array(4, 7, 8, 9, 10, 11, 17, 18, 22, 23, 24, 25, 27); } else { # new GPIO layout (B+) $this->pins = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); $this->hackablePins = array(4, 5, 6, 12, 13, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); } } }
public function __construct() { $dispatcher = Conf::get('global.dispatcher_path', PI_CORE . 'RouteDispatcher.php'); if (file_exists($dispatcher)) { Pi::inc($dispatcher); } else { throw new Exception('can not find the dispatcher config : global.dispatcher_path', 1032); } }
public function __construct() { try { $url = isset($_GET['url']) ? explode('/', rtrim($_GET['url'], '/')) : null; if (empty($url[0])) { $url[0] = 'index'; } require 'lib/controllers/pi.controller.php'; $controller = new Pi(); $controller->load_model('pi'); if (!method_exists($controller, $url[0])) { throw new Exception('Invalid method', 404); } $params = array_slice($url, 1); call_user_func_array(array($controller, $url[0]), $params); } catch (Exception $e) { $this->error($e); } }
public function run() { //初始化pipe $default_pipe = array('WebReqPipe' => 'default', 'WebRouterPipe' => 'default'); $pipes = Pi::get('global.pipes', array()); if (empty($pipes)) { $pipes = $default_pipe; } $this->pipeLoadContainer = $pipes; parent::run(); }
public function __construct() { parent::__construct(); $this->load->model('product_model'); $this->load->model('shipping_code_model'); $this->load->model('product_catalog_model'); $this->load->model('product_packing_model'); $this->load->model('purchase_model'); $this->load->library('form_validation'); $this->load->library('excel'); $this->load->helper('product_permission'); }
public static function getConfig($name) { $conf = Pi::get('cache.' . $name, array()); if (empty($conf)) { return null; } foreach ($conf as $server) { if (!isset($server['host']) || !isset($server['port']) || !isset($server['port']) || !isset($server['pconnect'])) { return null; } } return $conf; }
public function dispatch() { if (!$this->checkSign()) { $this->output('api.err sign', 7099); } $mod_name = Pcf::get("global.mod", 'mod'); $func_name = Pcf::get("global.func", 'func'); $mod_seg = Pcf::get("global.mod_seg", '/'); $api_path = Pcf::get("global.base_path", PI_APP_ROOT . PI_APP_NAME . DOT . 'logic' . DOT); $mod = Comm::Req($mod_name); $func = Comm::Req($func_name); $mod = explode($mod_seg, $mod); $pattern = '/^[0-9a-zA-Z\\/]*$/'; $class = ''; if (!empty($mod)) { foreach ($mod as $k => $m) { if (empty($m) || !is_string($m)) { if (!preg_match($pattern, $m)) { $this->output('api.err error format mod:' . $m, 1005); } unset($mod[$k]); } $mod[$k] = strtolower($m); $class .= ucfirst($mod[$k]); } } if (empty($mod)) { $this->output('api.err empty api mod:' . $mod, 1006); } if (empty($func) || !is_string($func) || !preg_match($pattern, $func)) { $this->output('api.err empty or error api func:' . $func, 1007); } Pi::inc(PI_CORE . 'BaseApi.php'); $file = $api_path . implode(DOT, $mod) . DOT . $class . '.api.php'; if (!Pi::inc($file)) { $this->output('api.err api router can not load file:' . $file, 1008); } if (!class_exists($class)) { $this->output('api.err api router not find class:' . $class, 1009); } $cls = new $class(); if (!is_subclass_of($cls, 'PiBaseApi')) { $this->output('api.err is not the subclass of BaseApi', 1010); } if (!is_callable(array($cls, $func))) { $this->output('api.err api class:' . $class . ' can not call method:' . $func, 1011); } $res = Pi::piCallMethod($cls, $func); return $res; }
public function dispatch() { $mod_name = Conf::get("global.mod", 'mod'); $func_name = Conf::get("global.func", 'func'); $mod_seg = Conf::get("global.mod_seg", '/'); $api_path = Conf::get("global.base_path", APP_ROOT . APP_NAME . DOT . 'logic' . DOT); $mod = Comm::Req($mod_name); $func = Comm::Req($func_name); $mod = explode($mod_seg, $mod); $pattern = '/^[0-9a-zA-Z\\/]*$/'; $class = ''; if (!empty($mod)) { foreach ($mod as $k => $m) { if (empty($m) || !is_string($m)) { if (!preg_match($pattern, $m)) { throw new Exception('error format mod:' . $m, 1005); } unset($mod[$k]); } $mod[$k] = strtolower($m); $class .= ucfirst($mod[$k]); } } if (empty($mod)) { throw new Exception('empty api mod:' . $mod, 1006); } if (empty($func) || !is_string($func) || !preg_match($pattern, $func)) { throw new Exception("empty api func:" . $func, 1007); } $file = $api_path . implode(DOT, $mod) . DOT . $class . '.api.php'; if (!is_readable($file)) { throw new Exception('api router can not load file:' . $file, 1008); } Pi::inc(PI_CORE . 'BaseApi.php'); Pi::inc($file); if (!class_exists($class)) { throw new Exception('api router not find class:' . $class, 1009); } $cls = new $class(); if (!is_subclass_of($cls, 'BaseApi')) { throw new Exception('api.err is not the subclass of BaseApi ', 1010); } $res = $this->_call_method($cls, $func); if ($res === false) { throw new Exception('api class:' . $class . ' call method ' . $func . ' err ', 1011); } }
public function execute(PiApp $app) { $this->app = $app; $router = Conf::get('global.router_file', 'ApiRouter.php'); $router_class = Conf::get('global.router_class', 'PiApiRouter'); if (is_readable(PI_CORE . $router)) { Pi::inc(PI_CORE . $router); } else { throw new Exception('api.router can not find the api router : ' . $router, 1030); } if (class_exists($router_class)) { $cls = new $router_class($app); $cls->dispatch(); } else { throw new Exception('api.router can not find the router class : ' . $router_class, 1031); } }
protected function _initLogger() { //获得log path if (!defined("LOG_PATH")) { define("LOG_PATH", Pi::get('log.path', '')); } if (!is_dir(LOG_PATH)) { die('pi.err can not find the log path'); } Pi::inc(Pi::get('LogLib')); $logFile = $this->task_name; $logLevel = $this->debug === true ? Logger::LOG_DEBUG : Pi::get('log.level', Logger::LOG_TRACE); $roll = Pi::get('log.roll', Logger::DAY_ROLLING); $basic = array('logid' => $this->appId); Logger::init(LOG_PATH, $logFile, $logLevel, array(), $roll); Logger::addBasic($basic); }
public function execute(PiApp $app) { $this->app = $app; $router = Pcf::get('global.router_file', 'ApiRouter.php'); $router_class = Pcf::get('global.router_class', 'PiApiRouter'); if (!Pi::inc(PIPE_HELPER . $router)) { throw new Exception('api.router can not find the api router : ' . $router, 1030); } if (class_exists($router_class)) { $cls = new $router_class($app); $res = $cls->dispatch(); //线上环境请处理输出做加密 $cls->output($res); } else { throw new Exception('api.router can not find the router class : ' . $router_class, 1031); } }
private static function getConfig($name) { $c = Pi::get('db.' . $name, null); $conf = array(); if (empty($c) || !is_array($c)) { return null; } if (!isset($c['master']) && isset($c['slave'])) { $conf['master'] = $c['slave']; } else { if (!isset($c['master']) && !isset($c['slave'])) { $conf['master'] = $c; } else { $conf = $c; } } foreach ($conf as $k => $v) { if ($k != 'master' && $k != 'slave') { unset($conf[$k]); continue; } //端口默认 3306 if (!isset($conf[$k]['port'])) { $conf[$k]['port'] = 3306; } //类型默认 mysql if (!isset($conf[$k]['database_type'])) { $conf[$k]['database_type'] = 'mysql'; } //默认字符集 if (!isset($conf[$k]['charset'])) { $conf[$k]['charset'] = 'utf8'; } if (!isset($conf[$k]['prefix'])) { $conf[$k]['prefix'] = ''; } } if (empty($conf)) { return null; } return $conf; }
public function run() { //内网api调用 if ($this->checkInnerApi()) { //如果有其他调试输出忽略 ob_start(); define("USE_INNER_API", 1); Pi::inc(PI_CORE . 'Proxy.php'); PiProxyServer::Server(); } else { //初始化pipe $default_pipe = array('ApiReqPipe' => 'default', 'ApiHttpRouterPipe' => 'default'); $pipes = Pi::get('global.pipes', array()); if (empty($pipes)) { $pipes = $default_pipe; } $this->pipeLoadContainer = $pipes; parent::run(); } }
function loadPipes($pipes = null, $root = null) { //pipe 数组格式 path => class_name //加载默认的处理管道 if ($pipes == null) { $pipes = array(); $input = Pi::get('DefaultInputPipe'); $output = Pi::get('DefaultOutputPipe'); $pipes = array($input => PI_PIPE . $input . '.php', $output => PI_PIPE . $output . '.php'); } else { if (is_string($pipes)) { $pipes = array($pipes); } if (empty($pipes)) { return false; } //加载管道位置 $root = $root == 'default' ? PI_ROOT : COM_ROOT; foreach ($pipes as $k => $cls) { $pipes[$cls] = $root . 'pipe' . DOT . $cls . '.php'; unset($pipes[$k]); } } foreach ($pipes as $cls => $path) { if (isset($this->arr_pipe[$cls])) { continue; } if (is_readable($path)) { Pi::inc($path); if (class_exists($cls)) { $this->arr_pipe[$cls] = new $cls(); } } else { throw new Exception('the pipe ' . $cls . ' can not load,check pipe file', 1020); } } }
<?php /** * Pi Engine (http://pialog.org) * * @link http://code.pialog.org for the Pi Engine source repository * @copyright Copyright (c) Pi Engine http://pialog.org * @license http://pialog.org/license.txt New BSD License */ /** * @author Hossein Azizabadi <*****@*****.**> */ return array('category' => array(array('title' => _a('Admin'), 'name' => 'admin'), array('title' => _a('News module'), 'name' => 'news'), array('title' => _a('Guide module'), 'name' => 'guide'), array('title' => _a('View'), 'name' => 'view'), array('title' => _a('Social'), 'name' => 'social'), array('title' => _a('Manage'), 'name' => 'manage'), array('title' => _a('Order'), 'name' => 'order')), 'item' => array('admin_perpage' => array('category' => 'admin', 'title' => _a('Perpage'), 'description' => '', 'edit' => 'text', 'filter' => 'number_int', 'value' => 10), 'use_news_topic' => array('category' => 'news', 'title' => _a('Use news topics'), 'description' => '', 'edit' => 'checkbox', 'filter' => 'number_int', 'value' => 1), 'use_guide_category' => array('category' => 'guide', 'title' => _a('Use guide category'), 'description' => '', 'edit' => 'checkbox', 'filter' => 'number_int', 'value' => 1), 'use_guide_location' => array('category' => 'guide', 'title' => _a('Use guide location'), 'description' => '', 'edit' => 'checkbox', 'filter' => 'number_int', 'value' => 1), 'filter_location_level' => array('title' => _a('Select location level for show on filter form'), 'description' => '', 'edit' => array('type' => 'select', 'options' => array('options' => array(1 => _a('level 1'), 2 => _a('level 2'), 3 => _a('level 3'), 4 => _a('level 4'), 5 => _a('level 5')))), 'filter' => 'number_int', 'value' => 1, 'category' => 'guide'), 'view_list_type' => array('title' => _a('Event list type'), 'description' => '', 'edit' => array('type' => 'select', 'options' => array('options' => array('line' => _a('Line : each event on one line'), 'box' => _a('Box : each event as box and 3 box on one line')))), 'filter' => 'text', 'value' => 'event', 'category' => 'view'), 'view_perpage' => array('category' => 'view', 'title' => _a('Perpage'), 'description' => '', 'edit' => 'text', 'filter' => 'number_int', 'value' => 10), 'related_event' => array('category' => 'view', 'title' => _a('Show related event'), 'description' => '', 'edit' => 'checkbox', 'filter' => 'number_int', 'value' => 1), 'related_event_type' => array('title' => _a('Related event type'), 'description' => '', 'edit' => array('type' => 'select', 'options' => array('options' => array('event' => _a('By event module topics'), 'guide' => _a('By guide module categories')))), 'filter' => 'text', 'value' => 'event', 'category' => 'view'), 'image_homepage' => array('category' => 'view', 'title' => _a('Set wide image for homepage'), 'description' => '', 'edit' => 'text', 'filter' => 'string', 'value' => ''), 'price_filter' => array('category' => 'view', 'title' => _a('Price filter'), 'description' => _a('Input method : 100-200,Between 100 to 200|200-300,Between 200 to 300|'), 'edit' => 'textarea', 'filter' => 'string', 'value' => ''), 'social_sharing' => array('title' => _t('Social sharing items'), 'description' => '', 'edit' => array('type' => 'multi_checkbox', 'options' => array('options' => Pi::service('social_sharing')->getList())), 'filter' => 'array', 'category' => 'social'), 'manage_active' => array('category' => 'manage', 'title' => _a('Manage event by users'), 'description' => '', 'edit' => 'checkbox', 'filter' => 'number_int', 'value' => 1), 'manage_approval' => array('category' => 'manage', 'title' => _a('Auto approval user events'), 'description' => '', 'edit' => 'checkbox', 'filter' => 'number_int', 'value' => 1), 'order_active' => array('category' => 'order', 'title' => _a('Active order'), 'description' => _a('Manage event registration, ticket stock and activate orders'), 'edit' => 'checkbox', 'filter' => 'number_int', 'value' => 1), 'order_free' => array('category' => 'order', 'title' => _a('Show free word for free events'), 'description' => '', 'edit' => 'checkbox', 'filter' => 'number_int', 'value' => 1), 'order_discount' => array('category' => 'order', 'title' => _a('Active discount system'), 'description' => _a('Discount percent for each rule on each event'), 'edit' => 'checkbox', 'filter' => 'number_int', 'value' => 1), 'text_description_index' => array('category' => 'head_meta', 'title' => _a('Description for index page'), 'description' => '', 'edit' => 'textarea', 'filter' => 'string', 'value' => '')));
<?php define('APP_NAME', 'api'); define('PI_ROOT', dirname(dirname(dirname(__FILE__))) . '/pi/'); define('APP_ROOT', dirname(dirname(__FILE__)) . '/'); define('LOG_PATH', dirname(dirname(dirname(__FILE__))) . '/logs'); define('COM_ROOT', APP_ROOT . 'com/'); define("__PI_EN_DEBUG", 1); include PI_ROOT . 'Api.php'; //api项目需要的框架配置 Pi::set('global.logFile', 'api'); //代码环境 Pi::set('com_env', 'dev'); Pi::set('app_env', 'dev'); //自定义类可以重构提供的基础ApiApp功能 class PApiApp extends ApiApp { } $app = new PApiApp($argv); $app->run();
protected function needToLog($code) { $core_no_need_log_code = Conf::get('global.nolog_exception', array()); $app_no_need_log_code = Pi::get('global.nolog_exception', array()); if (isset($core_no_need_log_code[$code]) || isset($app_no_need_log_code[$code])) { return false; } return true; }
public function call($method, $params, $mod, $add, $conf) { $sign = Pi::get('global.innerapi_sign', ''); $sign_name = Pi::get('global.innerapi_sign_name', '_pi_inner_nm'); if (isset($conf['ip']) && isset($conf['net']) && $conf['net'] == 'http') { $args = array(); $args['mod'] = $mod; $args['add'] = $add; $args['method'] = $method; $args['param'] = $params; $args[$sign_name] = $sign; try { $curl = new HttpClient(); $timeout = isset($conf['timeout']) ? intval($conf['timeout']) : 10; $res = $curl->sendPostData($conf['ip'], $args, $timeout); if ($curl->hasError() === false) { $data = unserialize($res); $data = isset($data[INNER_RES_PACK]) ? $data[INNER_RES_PACK] : $data; return $data; } else { throw new Exception('curl error', 5011); } } catch (Exception $e) { return array(INNER_ERR => 5011, 'msg' => $curl->getErrorMsg()); } } throw new Exception('inner api err conf : ' . var_export($conf), 5004); }
<?php //最低配置,几乎不修改 define("DOT", DIRECTORY_SEPARATOR); define("TIMEZONE", 'Asia/Shanghai'); define("ENCODE", 'UTF-8'); define("PI_CORE", PI_ROOT . 'core' . DOT); define("PI_UTIl", PI_ROOT . 'util' . DOT); define("PI_PIPE", PI_ROOT . 'pipe' . DOT); Pi::set('MUST_CONST', array('PI_ROOT', 'APP_ROOT', 'COM_ROOT')); Pi::set('COM_DIR', array('export', 'lib', 'logic', 'model', 'conf')); Pi::set('DefaultInputPipe', 'InputPipe'); Pi::set('DefaultOutputPipe', 'OutputPipe'); Pi::set('DbLib', PI_CORE . 'db' . DOT . 'medoo.php'); Pi::set('MemcacheLib', PI_CORE . 'cache' . DOT . 'Memcache.php'); Pi::set('RedisLib', PI_CORE . 'cache' . DOT . 'Redis.php'); Pi::set('LogLib', PI_CORE . 'log' . DOT . 'Log.php'); Pi::set('LoaderLib', PI_CORE . 'Loader.php'); Pi::set('PipeExe', PI_CORE . 'PipeExecutor.php'); Pi::set('PageCtr', PI_CORE . 'PageCtr.php'); //其他配置
public function __construct() { parent::__construct(); $this->load->model('product_shelf_code_model'); }
<?php Pi::inc(dirname(__FILE__) . DOT . 'PICacheAbstract.php'); class PRedis extends PICacheAbstract { public $options = array('persistent' => true, 'host' => '127.0.0.1', 'port' => 6379, 'timeout' => 3, 'ttl' => 0); public $optionKeys = array(Redis::OPT_SERIALIZER, Redis::OPT_PREFIX); /** * Constructor * * @param array $options */ public function __construct($options = array()) { parent::__construct($options); $this->conn = new Redis(); if (empty($this->options['persistent'])) { $this->conn->connect($this->options['host'], $this->options['port'], $this->options['timeout']); } else { $this->conn->pconnect($this->options['host'], $this->options['port'], $this->options['timeout']); } foreach ($this->optionKeys as $key) { if (isset($this->options[$key])) { $this->conn->setOption($key, $this->options[$key]); } } } /** * Set cache * * @param string $key
<?php define('APP_NAME', 'web'); define('PI_ROOT', dirname(dirname(dirname(__FILE__))) . '/pi/'); define('APP_ROOT', dirname(dirname(__FILE__)) . '/'); define('COM_ROOT', APP_ROOT . 'com/'); define('APP_CTR_ROOT', APP_ROOT . APP_NAME . '/ctr/'); define('LOG_PATH', dirname(dirname(dirname(__FILE__))) . '/logs'); define("__PI_EN_DEBUG", 1); include PI_ROOT . 'Web.php'; //web项目需要的框架配置 Pi::set('global.logFile', 'web'); Pi::set('env', 'dev'); $app = new WebApp(); $app->run();