public static function load($key) { $path = App::path($key); if (isset($path) && is_readable($path)) { return require_once $path; } return null; }
/** * @param $key * @return string */ private function getPath($key) { $fileName = md5($key); $folder = App::path('cache') . $this->cacheFolder; $path = $folder . '/' . $fileName . '.dat'; Directory::makeDir($folder); return $path; }
private static function getFilePath($viewName) { $filePath = str_replace('.', '/', $viewName); $extension = App::environment(Globals::ENV_MVC_VIEW_FILE_EXTENSION); if (!isset($extension) || $extension === '') { $extension = self::ENV_VIEW_FILE_EXT; } return App::path('app') . self::VIEW_BASE_PATH . $filePath . '.' . $extension; }
private function clearTableSchema($name) { if (preg_match('#m[\\d]+(Create|Alter)(?<table>[a-zA-Z][a-zA-Z0-9\\_]+)Table#i', $name, $matches)) { $table = strtolower(Strings::camelToSnake($matches['table'])); $path = App::path('cache') . "/schema/" . DB::getDatabaseName() . "/{$table}.dat"; if (file_exists($path)) { unlink($path); } } }
public function appStart() { App::path('migration', App::path('app') . '/database/migration'); App::path('migration_history', App::path('migration') . '/history.dat'); App::path('cache', App::path('app') . '/cache'); App::path('exception', App::path('config') . '/exception.php'); App::path('runtime', App::path('app') . '/runtime'); App::path('daemons', App::path('config') . '/daemons.php'); App::path('commands', App::path('config') . '/commands.php'); App::path('log', App::path('app') . '/log'); }
private function __construct(\Xaircraft\Database\Database $provider, $database) { $this->provider = $provider; $configs = (require App::path('config') . '/database.php'); if (isset($configs) && !empty($configs)) { if (!array_key_exists($database, $configs)) { throw new DatabaseException("找不到数据库配置 [{$database}]"); } $config = $configs[$database]; if (!isset($config) || !is_array($config) || empty($config)) { throw new DatabaseException("Database config undefined."); } if (!array_key_exists('driver', $config) || !isset($config['driver'])) { throw new DatabaseException("Database config must include driver."); } else { $dsn[] = $config['driver'] . ':'; } if (!array_key_exists('database', $config) || !isset($config['database'])) { throw new DatabaseException("Database config must include database name."); } else { $dsn[] = 'dbname=' . $config['database'] . ';'; } if (!array_key_exists('host', $config) || !isset($config['host'])) { throw new DatabaseException("Database config must include host."); } else { $dsn[] = 'host=' . $config['host'] . ';'; } if (array_key_exists('charset', $config) && isset($config['charset'])) { $dsn[] = 'charset=' . $config['charset'] . ';'; } if (array_key_exists('collation', $config) && isset($config['collation'])) { $dsn[] = 'collation=' . $config['collation'] . ';'; } $dsn = implode('', $dsn); if (!array_key_exists('username', $config) || !isset($config['username'])) { throw new DatabaseException("Database config must include username."); } else { $username = $config['username']; } if (!array_key_exists('password', $config) || !isset($config['password'])) { throw new DatabaseException("Database config must include password."); } else { $password = $config['password']; } $prefix = null; if (array_key_exists('prefix', $config) && isset($config['prefix'])) { $prefix = $config['prefix']; } $this->provider->connection($dsn, $username, $password, null, $config['database'], $prefix); } else { throw new DatabaseException("数据库配置错误"); } }
private function getModelPath() { $path = App::path('models'); if (!isset($path)) { $path = App::path('app'); if (isset($path)) { $path = "{$path}/models"; } else { throw new ConsoleException("Can't find app path."); } } return $path; }
public function __construct($table) { if (!isset($table)) { throw new DataTableException($table, "Table name invalid - [{$table}]"); } $this->tableSymbol = TableSymbol::create($table); $this->table = $this->tableSymbol->getName(); $schema = App::path('schema'); if (!isset($schema)) { throw new DatabaseException("Can't find schema cache directory."); } $this->source = $schema . '/' . DB::getDatabaseName() . '/' . $this->table . '.dat'; $this->initialize(); }
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 appStart() { $this->classLoader = new ClassLoader(); $paths = Settings::load('autoload'); if (!isset($paths)) { $paths = array(); } $paths[] = '/service'; $paths[] = '/job'; $paths[] = '/command'; $paths[] = '/daemon'; $paths[] = '/module'; $paths[] = '/models'; $paths[] = '/test'; $paths[] = '/database/migration'; foreach ($paths as $item) { $this->classLoader->addPath(App::path('app') . $item); } }
public function handle() { $this->router = Router::getInstance(App::path('routes'), App::path('filter')); $defaultRouterToken = App::environment(Globals::ROUTER_DEFAULT_TOKENS); if (isset($defaultRouterToken) && !empty($defaultRouterToken)) { $this->router->baseMappings['default']['default'] = $defaultRouterToken; } else { $defaultRouterToken = $this->router->baseMappings['default']['default']; } $this->router->registerMatchedHandler(function ($params) { DI::bindSingleton(Request::class, new Request($params)); DI::bindSingleton(Response::class, new Response()); }); $this->router->registerDefaultMatchedHandler(function ($params) use($defaultRouterToken) { $namespace = null; if (array_key_exists('namespace', $params)) { $namespace = $params['namespace']; } if (array_key_exists('controller', $params)) { $controller = $params['controller']; } if (array_key_exists('action', $params)) { $action = $params['action']; } if (!isset($controller)) { $controller = $defaultRouterToken['controller']; } if (!isset($action)) { $action = $defaultRouterToken['action']; } Controller::invoke($controller, $action, $namespace); }); $this->router->missing(function () { throw new URLRouterException("URL Routing missing."); }); $this->router->routing(); }
public function __construct(array $args) { $this->pidFilePath = App::path('runtime') . '/daemon/' . get_called_class() . '.pid'; $this->args = $args; $this->initialize(); }
public function beforeStop() { File::appendText(App::path('cache') . "/" . get_called_class() . "_stop.log", $this->getPID() . "_" . posix_getpid() . "_" . time() . "\r\n"); }
private function getControllerPath($className) { $className = substr($className, 0, strpos($className, "_controller")); $className = str_replace('_', DIRECTORY_SEPARATOR, $className); return App::path("app") . '/controllers/' . $className . '.php'; }
<?php /** * Created by PhpStorm. * User: lbob * Date: 2015/12/8 * Time: 14:25 */ use Xaircraft\Core\IO\File; use Xaircraft\Exception\DaemonException; use Xaircraft\Exception\HttpAuthenticationException; return array(HttpAuthenticationException::class => function ($ex) { var_dump("aa"); }, DaemonException::class => function ($ex) { $path = \Xaircraft\App::path('log') . "/daemon/" . date("Ymd", time()) . '.log'; File::appendText($path, $ex->getMessage); });
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."); }