Exemplo n.º 1
0
 /**
  * 定义命令组对象并返回
  * 
  * @param  array   $list 指令集数组
  * 
  * @return \Ws\Mvc\CmdGroup
  */
 public static function group(array $list)
 {
     $ss = [];
     foreach ($list as $item) {
         if (!empty($item)) {
             $ss[] = Cmd::id($item['id'])->bind($item['event'], $item['closure']);
         }
     }
     return new CmdGroup($ss);
 }
Exemplo n.º 2
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.º 3
0
 /**
  * 生成 接口 模式的访问路径
  * 
  * @param  string $cmdId    命令标识
  * @param  array  $params   参数
  * 
  * @return string
  */
 public function jsonPathing($cmdId, $params = [])
 {
     $url = rtrim(Request::get_request_baseuri(), '\\/') . $this->config->get('app.mount');
     $url .= Cmd::build($cmdId, $params, Cmd::JSON);
     return $url;
 }
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('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.º 5
0
 public static function cmdBind(App $app)
 {
     Cmd::group([['id' => 'asdebug', 'event' => Request::GET, 'closure' => function ($a) {
         $f = Request::get('f');
         if ($f == 'json') {
             return AsDebug::instance()->cmdView($a, 'json');
         }
         return AsDebug::instance()->cmdView($a, 'ui');
     }]])->bindTo($app);
 }
Exemplo n.º 6
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);