public function handle() { $this->checkArgs(array('table')); $namespace = array_key_exists('namespace', $this->args) ? $this->args['namespace'] : null; if (!isset($namespace)) { $namespace = array_key_exists('ns', $this->args) ? $this->args['ns'] : null; } $table = $this->args['table']; $class = array_key_exists('class', $this->args) ? $this->args['class'] : Strings::snakeToCamel($table); $path = $this->path($class, $namespace); $schema = new TableSchema($table); if (file_exists($path)) { $content = File::readText($path); $className = isset($namespace) ? "{$namespace}\\{$class}" : $class; $reflection = new \ReflectionClass($className); $header = $reflection->getDocComment(); if (isset($header)) { $content = str_replace($header, Template::generateHeader($schema->columns()), $content); unlink($path); File::writeText($path, $content); } Console::line("Model [{$class}] updated in path [{$path}]."); } else { File::writeText($path, Template::generateModel($table, $class, $schema->columns(), $namespace)); Console::line("Model [{$class}] created in path [{$path}]."); } }
public function handle() { if (Globals::RUNTIME_MODE_CLI !== App::environment(Globals::ENV_RUNTIME_MODE)) { throw new ConsoleException("Only run in command line mode"); } //加载Worker并为每个Worker创建一个子进程,然后进入休眠,当接收到信号量时,则执行相应的进程调度操作。 if (!function_exists("pcntl_signal")) { throw new ConsoleException("PHP does not appear to be compiled with the PCNTL extension.This is neccesary for daemonization"); } if (function_exists("gc_enable")) { gc_enable(); } $daemon = Daemon::make($_SERVER['argc'], $_SERVER['argv']); try { /** * @var $daemon Daemon */ if (isset($daemon)) { $daemon->start(); sleep(1); Console::line("Daemon [" . $daemon->getPID() . "] started."); } } catch (\Exception $ex) { throw new DaemonException($daemon->getName(), $ex->getMessage(), $ex); } }
private function showAllDaemon() { $messageQueueKey = ftok(App::path('cache') . "/queue/daemon.queue", "a"); $messageQueue = msg_get_queue($messageQueueKey, 0666); $messageQueueState = msg_stat_queue($messageQueue); $msgCount = $messageQueueState['msg_qnum']; if (0 === $msgCount) { Console::line("None service is running."); } while ($msgCount > 0) { /** @var MessageQueue $message */ msg_receive($messageQueue, 0, $messageType, 1024, $message, true, MSG_IPC_NOWAIT); Console::line("PID:{$message->pid},NAME:{$message->name},TIME:" . date("Y-m-d H:i:s", $message->timestamp) . "Alive."); $messageQueueState = msg_stat_queue($messageQueue); $msgCount = $messageQueueState['msg_qnum']; } }
public function handle() { $command = Command::make($_SERVER['argc'], $_SERVER['argv']); try { /** * @var $command Command */ if (isset($command)) { Console::line("Start:"); Console::line("----------------------------------------"); $command->handle(); Console::line("----------------------------------------"); Console::line("End."); } } catch (\Exception $ex) { throw new ConsoleException($ex->getMessage(), $ex); } }
private function migrate($name) { if (!isset($name) || "" === $name || array_search($name, $this->history)) { return; } $migration = DI::get($name); if (!isset($migration) || !$migration instanceof Migration) { return; } if (DB::transaction(function () use($migration, $name) { return false !== $migration->up(); })) { $this->recordHistory($name); $this->clearTableSchema($name); Console::line("migrate {$name} finished."); } else { Console::line("migrate {$name} failure."); } }
private function forgetMigration() { if (!isset($this->args[1])) { throw new ConsoleException("Invalid migration argument in [--forget]."); } $selectedIndex = intval($this->args[1]); $history = Settings::get(App::path('migration_history')); if (isset($history)) { $history = unserialize($history); if (!empty($history)) { $this->history = $history; $date = "Unknown datetime"; foreach ($this->history as $key => $value) { if ($key === $selectedIndex) { unset($this->history[$selectedIndex]); if (preg_match('#^m(?<timestamp>\\d+)#i', $value, $match)) { if (array_key_exists('timestamp', $match)) { $timestamp = intval($match['timestamp']); $date = date("Y-m-d H:i:s", $timestamp); } } Settings::save(App::path('migration_history'), serialize($this->history)); Console::line("{$key}.[{$date}][{$value}] has forget."); return; } } Console::line("Can't find index [{$selectedIndex}]."); return; } } Console::line("History is empty."); }