/** * 进入工作模式 * * @access public static * @return void */ public static function run($ini, $args = null) { $run = array_shift($args); if (sizeof($args) < 1 || 0 === strcasecmp('help', reset($args))) { self::usage($run); exit(1); } $master = new self($ini, array_shift($args), self::parse($args)); $master->dispatch(); }
/** * Creates function callback as a route handler for the extension. * Redirects action parameter from route to $this->action<Action> method, like Nette's presenters. * * @return \Closure */ public static function getEntryPoint() { return function (IEditableFacade $editableFacade, $action, $presenter) { /** @var MicroPresenter $presenter */ $params = $presenter->getRequest()->getParameters(); unset($params['callback']); unset($params['action']); $api = new self($editableFacade); return $api->dispatch($action, $params); }; }
public static function run($config = [], $isConsoleApp = false, $path = '') { static $inst = null; if (null === $inst) { $inst = new self($isConsoleApp); \CW::$app = $inst; $inst->components = isset($config['components']) ? $config['components'] : []; $inst->params = isset($config['params']) ? $config['params'] : []; if (!$isConsoleApp) { $inst->dispatch($inst->getPath($path)); } } }
public static function multiMail($card_id, $list, $message) { $type = 'immediate'; $DEBUG = []; $reciever = []; $length = count($list); for ($i = 0; $i < $length; $i++) { $reciever['name'] = $list[$i]['name']; $reciever['email'] = $list[$i]['email']; $contact = array($reciever['name'] . '/' . $reciever['email']); array_push($DEBUG, $contact); $dispatcher = new self(); $dispatcher->dispatch(new SendCard($card_id, $reciever, $message, $type, $contact)); } return $DEBUG; }
public static function checkNeedToMail() { $reservation = DB::table('reservation')->get(); $now = date('Y-m-d H:i:s'); $reciever = []; $type = 'reservation'; $dispatcher = new self(); for ($i = 0; $i < count($reservation); $i++) { if (strtotime($now) > strtotime($reservation[$i]->mail_time)) { $card_id = $reservation[$i]->card_id; $reciever['name'] = $reservation[$i]->reciever_name; $reciever['email'] = $reservation[$i]->reciever_email; $message = $reservation[$i]->message; // send mail $dispatcher->dispatch(new SendCard($card_id, $reciever, $message, $type)); // remove reservation DB::table('reservation')->where('id', '=', $id)->delete(); } } }
/** * main() - This is typically called from zf.php. This method is a * self contained main() function. * */ public static function main($options = array()) { $cliClient = new self($options); $cliClient->dispatch(); }
/** * 寻找与网址匹配的handler和filters * 使用贪婪匹配,子目录中的路由器优先,长的路由项优先 * 没有找到匹配项时,返回空数组,否则返回数组中含有以下元素 * handler 控制器 filters 过滤器数组 url 网址 args 占位符对应值数组 * * @param string $path * 要查找的网址 * @param bool $is_sorted * 是否已经逆序排列过 * @return array */ public function dispatch($path, $is_sorted = false) { $path = rtrim(strtolower($path), ' /') . '/'; // 先寻找匹配的路由器 if (!$is_sorted) { krsort($this->children); // 贪婪匹配,需要逆向排序 } foreach ($this->children as $prefix => $filename) { if (starts_with($path, $prefix)) { $router = new self($filename, $prefix); $path = substr($path, strlen($prefix)); return $router->dispatch($path); } } // 再寻找匹配的路由项 if (!$is_sorted) { krsort($this->items); // 贪婪匹配,需要逆向排序 } foreach ($this->items as $rule => $handlers) { if (preg_match($rule, $path, $args) === 1) { // 第一项为匹配的网址 $url = $this->prefix . array_shift($args); return ['method' => Input::getMethod(), 'handlers' => &$handlers, 'args' => $args, 'url' => $url, 'rule' => $rule]; } } $this->abort(404); // 没有找到匹配项,输出HTTP 404 return ['method' => 'except', 'handlers' => [], 'args' => []]; }
/** * main() - This is typically called from zf.php. This method is a * self contained main() function. * */ public static function main($options = array()) { ini_set('display_errors', true); $cliClient = new self($options); $cliClient->dispatch(); }
/** * main() - This is typically called from zf.php. This method is a * self contained main() function. * */ public static function main() { ini_set('display_errors', true); $cliClient = new self(); $cliClient->dispatch(); }
/** * * @param Application $app * @param \collection $collection * * @return \record_adapter */ public static function createStory(Application $app, \collection $collection) { $connection = $collection->get_databox()->get_connection(); $sql = 'INSERT INTO record (coll_id, record_id, parent_record_id, moddate, credate, type, sha256, uuid, originalname, mime)' . ' VALUES (:coll_id, NULL, :parent_record_id, NOW(), NOW(), :type, :sha256, :uuid , :originalname, :mime)'; $stmt = $connection->prepare($sql); $stmt->execute([':coll_id' => $collection->get_coll_id(), ':parent_record_id' => 1, ':type' => 'unknown', ':sha256' => null, ':uuid' => Uuid::uuid4(), ':originalname' => null, ':mime' => null]); $stmt->closeCursor(); $story_id = $connection->lastInsertId(); $story = new self($app, $collection->get_databox()->get_sbas_id(), $story_id); try { $log_id = $app['phraseanet.logger']($collection->get_databox())->get_id(); $sql = 'INSERT INTO log_docs (id, log_id, date, record_id, action, final, comment)' . ' VALUES (null, :log_id, now(), :record_id, "add", :coll_id,"")'; $stmt = $connection->prepare($sql); $stmt->execute([':log_id' => $log_id, ':record_id' => $story_id, ':coll_id' => $collection->get_coll_id()]); $stmt->closeCursor(); } catch (\Exception $e) { unset($e); } $story->dispatch(RecordEvents::CREATED, new RecordCreatedEvent($story)); return $story; }
function dispatch($U, $lD = false) { $U = rtrim(strtolower($U), ' /') . '/'; if (!$lD) { krsort($this->children); } foreach ($this->children as $k => $R) { if (starts_with($U, $k)) { $fB = new self($R, $k); $U = substr($U, strlen($k)); return $fB->dispatch($U); } } if (!$lD) { krsort($this->items); } foreach ($this->items as $QC => $YC) { if (preg_match($QC, $U, $B) === 1) { $RB = $this->prefix . array_shift($B); return array('handlers' => &$YC, 'args' => $B, 'url' => $RB, 'rule' => $QC); } } $this->abort(404); return array('handlers' => array()); }
/** * 启动控制器 * * @param string $uri 路径 * * @return Controller */ public static function run($uri) { $c = new self($uri); $c->cutURI(); $c->dispatch(); try { $c->execute(); } catch (\Exception $e) { Error::exceptionHandler($e); } finally { if ($c->outputAllow) { Responder::write(); } } return $c; }
/** * Creates a new store for this app. * * @param callable $reducer * @param mixed $initialState * * @return Store */ public static function create(callable $reducer, $initialState) { $store = new self($reducer, $initialState); $store->dispatch(['type' => self::INIT]); return $store; }