Skip to content

Instantly share code, notes, and snippets.

@polidog
Last active December 15, 2015 07:59
Show Gist options
  • Save polidog/5227919 to your computer and use it in GitHub Desktop.
Save polidog/5227919 to your computer and use it in GitHub Desktop.
<?php
App::import('Routing', 'Router');
App::import('Sanitize');
config('routes');
class DNodeShell extends AppShell
{
public function main() {
require __DIR__."/../../../vendor/autoload.php";
$loop = new React\EventLoop\StreamSelectLoop();
$server = new DNode\DNode($loop, new DNodeShellWrapper($this));
$server->listen(7070);
$loop->run();
}
/**
* requestActionを実行する
* @param string $path
* @param array $post
* @param array $configs
* @return string
*/
public function callAction($path,$post,$configs = null) {
$url = Router::url($path);
Configure::write('debug',0);
$html = $this->requestAction($url,array('return','bare'=>0,'webroot'=>'/','base'=>'/'));
$html = str_replace(dirname(__DIR__),$configs->domain,$html);
return $html;
}
/**
* modelを呼び出す
* @param string $modelName
* @param string $method
* @param array $args
* @return type
*/
public function callModel($modelName,$method,$args) {
if ( !isset($this->$modelName) ) {
$this->loadModel($modelName);
}
return call_user_func(array($this->$modelName,$method),$args);
}
}
class DNodeShellWrapper {
private $shell = null;
public function __construct($shell) {
$this->shell = $shell;
}
public function callAction($path,$post,$configs,$callback) {
$ret = $this->shell->callAction($path,$post,$configs);
$callback($ret);
}
public function callModel($model,$method,$args,$callback) {
$ret = $this->shell->callModel($model,$method,$args);
$callback($ret);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment