Exemplo n.º 1
0
 public static function init($options = [])
 {
     static $noinit = true;
     if ($noinit) {
         // 载入 框架默认值
         $config = new Config(require __DIR__ . '/__defaults.php');
         $config->import($options);
         $timezone = $config->get('app.timezone', 'Asia/Chongqing');
         date_default_timezone_set($timezone);
         $config->set('app.runtime_id', Runtime::instance()->id());
         if (!Env::is('cli')) {
             $session = $config->get('app.session_autostart', true);
             if ($session) {
                 session_start();
             }
             header("Content-Type: text/html;charset=utf-8");
         }
         self::$config = $config;
         $noinit = false;
     }
 }
Exemplo n.º 2
0
 function __destruct()
 {
     // 进行资源释放
     if (!$this->enable) {
         return;
     }
     if (!is_dir($this->qargs['dir'])) {
         mkdir($this->qargs['dir'], 0700, true);
     }
     $headers = [];
     if (function_exists('getallheaders')) {
         $headers['request'] = getallheaders();
     } else {
         $headers['request'] = self::emu_getallheaders();
     }
     $headers['response'] = headers_list();
     $data = ['url' => Request::get_request_uri(), 'runtimeId' => Runtime::instance()->id(), 'headers' => $headers, 'cookies' => isset($_COOKIE) ? $_COOKIE : [], 'sessions' => isset($_SESSION) ? $_SESSION : [], 'items' => $this->items];
     $create_at = time();
     $id = md5($data['url'] . $create_at);
     $data = json_encode(['id' => $id, 'tag' => $this->qargs['tagval'], 'content' => Env::dump($data, '', true), 'create_at' => date('m-d H:i:s', $create_at)]);
     file_put_contents($this->qargs['logfile'], $data);
 }
Exemplo n.º 3
0
 /**
  * 绑定 过滤器
  * 
  * @param  closure    $before
  * @param  closure    $after
  * 
  * @return \Ws\Mvc\Cmd
  */
 public function filter($before = null, $after = null)
 {
     $before = Env::getClosure($before);
     $after = Env::getClosure($after);
     $this->filter = ['before' => empty($before) ? null : $before['closure'], 'after' => empty($after) ? null : $after['closure']];
     return $this;
 }
Exemplo n.º 4
0
<?php

use Ws\Env;
use Ws\Mvc\Request;
use Ws\Mvc\Cmd;
$app = $this->me();
/*@var $app \Ws\Mvc\App */
$dir = $app->config()->get('app.dir');
// 注入类路径
Env::classLoader()->addPsr4('Default\\', $dir);
// 绑定命令
Cmd::id('index')->bind(Request::GET, function ($app) {
    output('App: ' . $app->config()->get('app.id'), '');
    output('Hello World!', 'text');
    output($app->pagePathing('who.are.you', ['name' => 'a test']), 'url');
    output($app->jsonPathing('who.love.you', ['tag' => 'php']), 'url');
})->bindTo($app);
Exemplo n.º 5
0
function output($var, $tag = 'info')
{
    \Ws\Env::dump($var, $tag);
}
Exemplo n.º 6
0
 private function pipe($tag, $track)
 {
     $msg = ['tag' => $tag];
     switch ($tag) {
         case self::TAG_INIT:
             $ms = microtime(true);
             $m = explode('.', (string) $ms);
             if (!isset($m[1])) {
                 $m[1] = 0;
             }
             $msg = ['tag' => $tag, 'runtimeId' => Runtime::instance()->id(), 'ms' => $ms, 'date' => date("Ymd H:i:s.{$m[1]}", $m[0]), 'cookies' => isset($_COOKIE) ? $_COOKIE : [], 'sessions' => isset($_SESSION) ? $_SESSION : []];
             break;
         case self::TAG_START:
             if (!empty($track)) {
                 $msg['track'] = $track;
             }
             break;
         case self::TAG_BEFORE:
             if (!empty($track)) {
                 $msg['track'] = $track;
             }
             break;
         case self::TAG_INFO:
             $msg['track'] = $track;
             break;
         case self::TAG_AFTER:
             if (!empty($track)) {
                 $msg['track'] = $track;
             }
             break;
         case self::TAG_ERROR:
             if (!empty($track)) {
                 $msg['track'] = $track;
             }
             break;
         case self::TAG_FINISH:
             if (!empty($track)) {
                 $msg['track'] = $track;
             }
             break;
         case self::TAG_SHUTDOWN:
             $msg = ['tag' => $tag];
             break;
     }
     Env::dump($msg);
 }
Exemplo n.º 7
0
<?php

use Ws\Env;
use Ws\Mvc\Request;
use Ws\Mvc\Cmd;
$app = $this->me();
/*@var $app \Ws\Mvc\App */
$dir = $app->config()->get('app.dir');
// 注入类路径
Env::classLoader()->addPsr4('Im\\', $dir);
// 绑定命令
Cmd::id('index')->bind(Request::GET, function ($app) {
    output('App: ' . $app->config()->get('app.id'), '');
    output('Hello World!', 'text');
    output($app->pagePathing('who.are.you', ['name' => 'a test']), 'url');
    output($app->jsonPathing('who.love.you', ['tag' => 'php']), 'url');
})->bindTo($app);
Cmd::id('view')->bind(Request::GET, 'Im\\Controller\\Index@index')->bindTo($app);
Cmd::group([['id' => 'hello', 'event' => Request::GET, 'closure' => function ($a) {
    Env::dump($a);
}]])->bindTo($app);
// Env::dump($app);
Exemplo n.º 8
0
<?php

use Ws\Env;
use Ws\Mvc\Request;
use Ws\Mvc\Cmd;
$app = $this->me();
/*@var $app \Ws\Mvc\App */
$dir = $app->config()->get('app.dir');
// 注入类路径
Env::classLoader()->addPsr4('Blog\\', $dir);
// 绑定命令
Cmd::id('hello')->bind(Request::GET, function ($app) {
    output('App: ' . $app->config()->get('app.id'), '');
    output('Hello World!', 'text');
    output($app->pagePathing('who.are.you', ['name' => 'a test']), 'url');
    output($app->jsonPathing('who.love.you', ['tag' => 'php']), 'url');
})->bindTo($app);
Cmd::id('index')->bind(Request::GET, 'Blog\\Controller\\Index@index')->bindTo($app);
// Cmd::group([
// 		[
// 			'id'	=> 'hello',
// 			'event'	=> Request::GET,
// 			'closure'	=> function($a){
// 				Env::dump($a);
// 			}
// 		]
// 	])->bindTo($app);
// Env::dump($app);