本文整理汇总了PHP中Pi类的典型用法代码示例。如果您正苦于以下问题:PHP Pi类的具体用法?PHP Pi怎么用?PHP Pi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _pi_autoloader_core
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');
}
}
}
}
示例2: __construct
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);
}
}
示例3: index
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());
}
示例4: __construct
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);
}
}
示例5: execute
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);
}
示例6: __invoke
/**
* 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;
}
示例7: __construct
/**
* @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);
}
}
}
示例8: __construct
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);
}
}
示例9: __construct
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);
}
}
示例10: run
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();
}
示例11: getConfig
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;
}
示例12: dispatch
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;
}
示例13: dispatch
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);
}
}
示例14: execute
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);
}
}
示例15: _initLogger
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);
}