このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン | ||
apricot:core:applocation-class [2020/04/29 23:17] y2sunlight 作成 |
— (現在) | ||
---|---|---|---|
行 1: | 行 1: | ||
- | >TODO: 編集中 | ||
- | |||
- | ---- | ||
- | |||
- | ====== Apricot 基本コア ====== | ||
- | --- // | ||
- | |||
- | [[apricot: | ||
- | |||
- | 関連記事 | ||
- | * [[apricot: | ||
- | * [[apricot: | ||
- | * Apricot 基本コア | ||
- | * [[apricot: | ||
- | * [[apricot: | ||
- | * [[apricot: | ||
- | |||
- | ---- | ||
- | |||
- | ===== コア作成の準備 ===== | ||
- | まずは、apricotのコアを作る為に以下を準備します。 | ||
- | |||
- | * アプリケーションに追加する環境変数(phpdotenv) | ||
- | * コアフォルダ、名前空間、オートローディングの設定 | ||
- | * コア構築のヘルパーとなるグローバル関数とベースクラス | ||
- | \\ | ||
- | |||
- | ==== 環境設定 ==== | ||
- | |||
- | アプリケーション全体の環境設定は [[basic-library: | ||
- | |||
- | {{fa> | ||
- | <code ini .env> | ||
- | # Application | ||
- | APP_NAME=Apricot | ||
- | APP_VERSION=0.9 | ||
- | # | ||
- | APP_SECRET=0123456789ABCEDF0123456789ABCEDF | ||
- | APP_DEBUG=true | ||
- | APP_TIMEZONE=Asia/ | ||
- | APP_LANG=ja | ||
- | |||
- | # Loging | ||
- | LOG_NAME =" | ||
- | LOG_LEVEL = " | ||
- | </ | ||
- | |||
- | ^環境変数^設定内容^型^必須^ | ||
- | |APP_NAME|アプリケーション名(半角英数字)|string|〇| | ||
- | |APP_VERSION|バージョン|string|〇| | ||
- | |APP_SECRET|シークレット文字列\\ 安全の為にランダムな32文字を設定して下さい|string|〇| | ||
- | |APP_DEBUG|デバッグモード|bool|〇| | ||
- | |APP_TIMEZON|タイムゾーン|string|〇| | ||
- | |LOG_NAME|ログ名 (省略時はAPP_NAMEと同じ)|string| | | ||
- | |LOG_LEVEL|[[https:// | ||
- | |||
- | \\ | ||
- | |||
- | ==== コアフォルダ ==== | ||
- | 以下に示すようにプロジェクトフォルダ下に、コア用のフォルダ core を作成し、その下に4つのフォルダ(Derivations, | ||
- | |||
- | < | ||
- | apricot [プロジェクト] | ||
- | | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | </ | ||
- | |||
- | > クラスを保存するフォルダはUpperCamelCaseそれ以外はsnake_caseを使用しています | ||
- | |||
- | \\ | ||
- | |||
- | === composer.jsonの変更 === | ||
- | |||
- | 以下のようにcomposer.jsonへ '' | ||
- | |||
- | {{fa> | ||
- | <code json composer.json> | ||
- | { | ||
- | ... | ||
- | " | ||
- | " | ||
- | " | ||
- | }, | ||
- | " | ||
- | " | ||
- | " | ||
- | ] | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | * coreフォルダをCore名前空間にマッピングします | ||
- | * 次のファイルをオートロードの対象に追加します(グローバル関数用) | ||
- | * core/ | ||
- | * core/ | ||
- | |||
- | オートローディングファイルを更新する為に、プロジェクトフォルダで以下のコマンドを実行します。 | ||
- | < | ||
- | composer dump-autoload | ||
- | </ | ||
- | |||
- | \\ | ||
- | |||
- | ==== 例外クラス ==== | ||
- | |||
- | Exceptionを継承した2つの例外クラスを core\Exceptions に作成します。 | ||
- | |||
- | * HttpExceptionクラス --- HTTP例外(HTTPステータスコード400番台, | ||
- | * TokenMismatchExceptionクラス --- トークンミスマッチ例外(CSRFトークンなどの不一致) | ||
- | |||
- | {{fa> | ||
- | |||
- | <code php HttpException.php> | ||
- | <?php | ||
- | namespace Core\Exceptions; | ||
- | |||
- | /** | ||
- | * Http Exception | ||
- | */ | ||
- | class HttpException extends \Exception | ||
- | { | ||
- | /** | ||
- | * Http Status Code | ||
- | * @var int | ||
- | */ | ||
- | private $statusCode; | ||
- | |||
- | /** | ||
- | * Create HttpException | ||
- | * @param int $statusCode | ||
- | * @param string $message | ||
- | * @param int $code | ||
- | * @param \Exception $previous | ||
- | */ | ||
- | public function __construct(int $statusCode, | ||
- | { | ||
- | $this-> | ||
- | parent:: | ||
- | } | ||
- | |||
- | /** | ||
- | * Get Http Status Code | ||
- | * @return int | ||
- | */ | ||
- | public function getStatusCode() | ||
- | { | ||
- | return $this-> | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | <code php TokenMismatchException.php> | ||
- | <?php | ||
- | namespace Core\Exceptions; | ||
- | |||
- | /** | ||
- | * Token Mismatch Exception | ||
- | */ | ||
- | class TokenMismatchException extends \Exception | ||
- | { | ||
- | /** | ||
- | * Create TokenMismatchException | ||
- | * @param string $message | ||
- | * @param int $code | ||
- | * @param \Exception $previous | ||
- | */ | ||
- | public function __construct(string $message = 'Token Mismatch Exception', | ||
- | { | ||
- | parent:: | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | \\ | ||
- | |||
- | ==== ヘルパー ==== | ||
- | |||
- | グローバル関数を保存するためのPHPファイルを core\helper に作成します。目的別に2種類のPHPファイルがあります。 | ||
- | |||
- | * utilities.php --- PHPの基本的な組み込み関数を拡張する目的 | ||
- | * boilerplates.php --- apricotでよく使用される定型文的なコードパターンを関数化したもの\\ ( apricotではボイラープレートと呼んでいる ) | ||
- | |||
- | {{fa> | ||
- | <code php utilities.php> | ||
- | <?php | ||
- | /** | ||
- | * Add path | ||
- | * @param string $base Base path | ||
- | * @param string $path Sub path, if necessary | ||
- | * @return string path | ||
- | */ | ||
- | function add_path(string $base, string $path = null) : string | ||
- | { | ||
- | return (is_null($path)) ? $base : rtrim($base,'/' | ||
- | } | ||
- | |||
- | /** | ||
- | * Convert a multi-dimensional associative array to a Dot-notation array | ||
- | * @param | ||
- | * @param | ||
- | * @return array a Dot-notation array | ||
- | */ | ||
- | function array_dot(array $hash, $prepend = '' | ||
- | { | ||
- | $dot_arry = []; | ||
- | foreach ($hash as $key => $value) | ||
- | { | ||
- | if (is_array($value) && count($value)) | ||
- | { | ||
- | $dot_arry = array_merge($dot_arry, | ||
- | } | ||
- | else | ||
- | { | ||
- | $dot_arry[$prepend.$key] = $value; | ||
- | } | ||
- | } | ||
- | return $dot_arry; | ||
- | } | ||
- | |||
- | /** | ||
- | * Get an item from an array using Dot-notation | ||
- | * @param | ||
- | * @param | ||
- | * @param | ||
- | * @return mixed | ||
- | */ | ||
- | function array_get(array $hash, string $dot=null, $default=null) | ||
- | { | ||
- | if (!isset($dot)) return $hash; | ||
- | |||
- | $keys = explode(' | ||
- | foreach($keys as $key) | ||
- | { | ||
- | if (array_key_exists($key, | ||
- | { | ||
- | $hash = $hash[$key]; | ||
- | } | ||
- | else | ||
- | { | ||
- | return $default; | ||
- | } | ||
- | } | ||
- | return $hash; | ||
- | } | ||
- | |||
- | /** | ||
- | * Checks if a key is present in an array using Dot-notation | ||
- | * @param | ||
- | * @param | ||
- | * @return bool | ||
- | */ | ||
- | function array_has(array $hash, string $dot):bool | ||
- | { | ||
- | $keys = explode(' | ||
- | foreach($keys as $key) | ||
- | { | ||
- | if (array_key_exists($key, | ||
- | { | ||
- | $hash = $hash[$key]; | ||
- | } | ||
- | else | ||
- | { | ||
- | return false; | ||
- | } | ||
- | } | ||
- | return true; | ||
- | } | ||
- | |||
- | /** | ||
- | * Get a subset of the input for only specified items | ||
- | * @param array $input | ||
- | * @param array|mixed $keys | ||
- | * @return array subset of the input | ||
- | */ | ||
- | function array_only(array $input, $keys) | ||
- | { | ||
- | $key_arr = is_array($keys) ? $keys : array_slice(func_get_args(), | ||
- | |||
- | $results = []; | ||
- | foreach ($key_arr as $key) | ||
- | { | ||
- | $results[$key] = $input[$key]; | ||
- | } | ||
- | return $results; | ||
- | } | ||
- | |||
- | /** | ||
- | * Get a subset of the input except for specified items | ||
- | * @param array $input | ||
- | * @param array|mixed $keys | ||
- | * @return array subset of the input | ||
- | */ | ||
- | function array_except(array $input, $keys=null) | ||
- | { | ||
- | $key_arr = is_array($keys) ? $keys : array_slice(func_get_args(), | ||
- | |||
- | $results = []; | ||
- | foreach($input as $key=> | ||
- | { | ||
- | if (!in_array($key, | ||
- | } | ||
- | return $results; | ||
- | } | ||
- | |||
- | /** | ||
- | * Generate random numbers | ||
- | * @param number $length | ||
- | * @return string | ||
- | */ | ||
- | function str_random($length = 32) | ||
- | { | ||
- | return substr(bin2hex(random_bytes($length)), | ||
- | } | ||
- | |||
- | /** | ||
- | * Get short class name | ||
- | * @param object $object | ||
- | * @return string | ||
- | */ | ||
- | function get_short_class_name($object) | ||
- | { | ||
- | return (new \ReflectionClass($object))-> | ||
- | } | ||
- | </ | ||
- | |||
- | |||
- | boilerplates.php へは関数を逐次追加します。現段階での内容は以下の通りです。 | ||
- | |||
- | <code php boilerplates.php> | ||
- | <?php | ||
- | |||
- | /** | ||
- | * Abort | ||
- | * @param int $code | ||
- | * @param string $message | ||
- | * @throws \Core\Exceptions\HttpException | ||
- | */ | ||
- | function abort(int $code, string $message=null) | ||
- | { | ||
- | throw new Core\Exceptions\HttpException($code, | ||
- | } | ||
- | </ | ||
- | |||
- | \\ | ||
- | |||
- | ==== ベースクラス ==== | ||
- | |||
- | apricotでは、ログ、デバッグ、設定、HTMLテンプレート、翻訳などのクラスをシングルトンとして実装します。そして、それらのシングルトンのメソッドを静的にアクセス出来るようにしたいと思います。これらの仕組みを実装する為に、core\Foundation に次の2つのベースクラスを作ります。 | ||
- | |||
- | * CallStaticクラス --- インスタンスメソッドを静的アクセス可能にするクラス | ||
- | * Singletonクラス --- CallStaticから継承したシングルトン | ||
- | |||
- | {{fa> | ||
- | <code php CallStatic.php> | ||
- | <?php | ||
- | namespace Core\Foundation; | ||
- | |||
- | /** | ||
- | * CallStatic | ||
- | */ | ||
- | abstract class CallStatic | ||
- | { | ||
- | protected static abstract function getInstance(); | ||
- | |||
- | /** | ||
- | * Handle calls to Instance, | ||
- | * @param | ||
- | * @param | ||
- | * @return mixed | ||
- | */ | ||
- | public static function __callStatic($method, | ||
- | { | ||
- | $instance = static:: | ||
- | return $instance-> | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | <code php Singleton.php> | ||
- | <?php | ||
- | namespace Core\Foundation; | ||
- | |||
- | /** | ||
- | * Singleton | ||
- | */ | ||
- | abstract class Singleton extends CallStatic | ||
- | { | ||
- | protected static abstract function createInstance(); | ||
- | |||
- | /** | ||
- | * Get instance. | ||
- | * @return object | ||
- | */ | ||
- | public static function getInstance() | ||
- | { | ||
- | static $instance = null; | ||
- | if (!$instance) | ||
- | { | ||
- | $instance = static:: | ||
- | } | ||
- | return $instance; | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | \\ | ||
- | |||
- | |||
- | ===== Applicationクラスの作成 ===== | ||
- | |||
- | さて、準備が出来たのでいよいよコアのクラス群を作って行きたいと思います。最初にApplicationクラスを作成しますが、その前にApplicationクラスの責任を明確にしておきます。 | ||
- | |||
- | === Applicationクラスの責任 === | ||
- | |||
- | * アプリケーションの初期化 | ||
- | * ルーティングとセキュリティの設定 | ||
- | * ミドルウェアの設定 | ||
- | * アクションの起動 | ||
- | |||
- | Applicationクラスは、以下の公開メソッドを持っています。詳細はソースコードを参照して下さい。 | ||
- | |||
- | === フロントコントローラ(index.php)から呼び出されるメソッド === | ||
- | |||
- | ^公開メソッド^機能^ | ||
- | |setup(array $app=[])|アプリケーションのセットアップ| | ||
- | |run(callable $routeDefinitionCallback)|アプリケーションの起動| | ||
- | |||
- | === ゲッターメソッド === | ||
- | |||
- | ^公開メソッド^機能^ | ||
- | |getInstance(): | ||
- | |getSetting($dot = null, $default=null)|アプリケーション設定(app.php)の取得| | ||
- | |getProjectDir(): | ||
- | |getConfigDir(): | ||
- | |getAssetsDir(): | ||
- | |getVarDir(): | ||
- | |getPublicDirectory(): | ||
- | |getRouteBase(): | ||
- | |getControllerName(): | ||
- | |getActionName(): | ||
- | |||
- | \\ | ||
- | |||
- | ==== Applicationクラス(暫定版) ==== | ||
- | |||
- | 以下に現段階のApplicationクラスを示します。ほとんどの機能は実装していますが、アクションを実行するメソッド(executeAction)だけが未実装(スタブ)です。 | ||
- | |||
- | {{fa> | ||
- | <code php Application.php> | ||
- | <?php | ||
- | namespace Core; | ||
- | |||
- | /** | ||
- | * Application Class | ||
- | */ | ||
- | class Application | ||
- | { | ||
- | /** | ||
- | * Application Instance | ||
- | * var Application | ||
- | */ | ||
- | private static $instance = null; | ||
- | |||
- | /** | ||
- | * Application Setting | ||
- | * @var array | ||
- | */ | ||
- | private $app = []; | ||
- | |||
- | /* | ||
- | * Project Directories | ||
- | */ | ||
- | private $projectDir; | ||
- | private $configDir; | ||
- | private $assetsDir; | ||
- | private $varDir; | ||
- | |||
- | /* | ||
- | * Public Directory | ||
- | */ | ||
- | private $publicDir; | ||
- | |||
- | /* | ||
- | * Route Base Path | ||
- | */ | ||
- | private $routeBase; | ||
- | |||
- | /* | ||
- | * Controller Name | ||
- | */ | ||
- | private $controllerName; | ||
- | |||
- | /* | ||
- | | ||
- | */ | ||
- | private $actionName; | ||
- | |||
- | /** | ||
- | * Get Project dir | ||
- | * @return string | ||
- | */ | ||
- | public function getProjectDir(): | ||
- | |||
- | /** | ||
- | * Get config dir | ||
- | * @return string | ||
- | */ | ||
- | public function getConfigDir(): | ||
- | |||
- | /** | ||
- | * Get assets dir | ||
- | * @return string | ||
- | */ | ||
- | public function getAssetsDir(): | ||
- | |||
- | /** | ||
- | * Get var dir | ||
- | * @return string | ||
- | */ | ||
- | public function getVarDir(): | ||
- | |||
- | /** | ||
- | * Get Public Directory | ||
- | * @return string | ||
- | */ | ||
- | public function getPublicDirectory(): | ||
- | |||
- | /** | ||
- | * Get Route Base Path | ||
- | * @return string | ||
- | */ | ||
- | public function getRouteBase(): | ||
- | |||
- | /** | ||
- | * Get controller Name | ||
- | * @return string | ||
- | */ | ||
- | public function getControllerName(): | ||
- | |||
- | /** | ||
- | * Get Action Name | ||
- | * @return string | ||
- | */ | ||
- | public function getActionName(): | ||
- | |||
- | /** | ||
- | * Get Application instance. | ||
- | * @return \Core\Application | ||
- | */ | ||
- | static public function getInstance(): | ||
- | { | ||
- | if (!self:: | ||
- | { | ||
- | throw new \RuntimeException(' | ||
- | } | ||
- | return self:: | ||
- | } | ||
- | |||
- | /** | ||
- | * Create Application | ||
- | * @param string $projectDir | ||
- | * @param string $publicDir | ||
- | */ | ||
- | function __construct(string $projectDir, | ||
- | { | ||
- | if (!self:: | ||
- | { | ||
- | // Set Project Directories | ||
- | $this-> | ||
- | $this-> | ||
- | $this-> | ||
- | $this-> | ||
- | |||
- | // Set Public Directory | ||
- | $this-> | ||
- | |||
- | // Set Route Base Path | ||
- | $routeBase = dirname($_SERVER[' | ||
- | if (preg_match('/ | ||
- | $this-> | ||
- | |||
- | // Set Dotenv | ||
- | \Dotenv\Dotenv:: | ||
- | |||
- | // Set timezone | ||
- | date_default_timezone_set(env(' | ||
- | |||
- | self:: | ||
- | } | ||
- | } | ||
- | |||
- | /** | ||
- | * Get an application setting value | ||
- | * @param string|null $dot Dot-notation key | ||
- | * @param mixed $default | ||
- | * @return mixed | ||
- | */ | ||
- | public function getSetting($dot = null, $default=null) | ||
- | { | ||
- | return array_get($this-> | ||
- | } | ||
- | |||
- | /** | ||
- | * Setup Application | ||
- | * @param array $app Application Setting | ||
- | */ | ||
- | public function setup(array $app=[]) | ||
- | { | ||
- | $this-> | ||
- | |||
- | // Application setup | ||
- | if (!empty($this-> | ||
- | { | ||
- | foreach($this-> | ||
- | { | ||
- | $func = require_once $setup; | ||
- | if (!is_callable($func) || ($func()===false)) | ||
- | { | ||
- | throw new \RuntimeException(" | ||
- | } | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | /** | ||
- | * Run Application | ||
- | * @param callable $routeDefinitionCallback | ||
- | */ | ||
- | public function run(callable $routeDefinitionCallback) | ||
- | { | ||
- | // Create Dispatcher | ||
- | $dispatcher = \FastRoute\simpleDispatcher($routeDefinitionCallback); | ||
- | |||
- | // Fetch method and URI from somewhere | ||
- | $httpMethod = $_SERVER[' | ||
- | $uri = $_SERVER[' | ||
- | |||
- | // Strip query string (?foo=bar) and decode URI | ||
- | if (false !== $pos = strpos($uri, | ||
- | { | ||
- | $uri = substr($uri, | ||
- | } | ||
- | $uri = rawurldecode($uri); | ||
- | |||
- | $routeInfo = $dispatcher-> | ||
- | switch ($routeInfo[0]) | ||
- | { | ||
- | case \FastRoute\Dispatcher:: | ||
- | abort(404, 'Page Not Found' | ||
- | break; | ||
- | |||
- | case \FastRoute\Dispatcher:: | ||
- | abort(405, ' | ||
- | break; | ||
- | |||
- | case \FastRoute\Dispatcher:: | ||
- | |||
- | $handler = $routeInfo[1]; | ||
- | $params = $routeInfo[2]; | ||
- | |||
- | if (is_callable($handler)) | ||
- | { | ||
- | // Case of callable | ||
- | $handler($params); | ||
- | } | ||
- | elseif(strpos($handler,' | ||
- | { | ||
- | // Case of Controller/ | ||
- | list($this-> | ||
- | |||
- | // Ecexute action | ||
- | $this-> | ||
- | } | ||
- | else | ||
- | { | ||
- | abort(500,' | ||
- | } | ||
- | break; | ||
- | } | ||
- | } | ||
- | |||
- | /** | ||
- | * Ecexute action | ||
- | * @param string $controllerName | ||
- | * @param string $actionName | ||
- | * @param array $params | ||
- | */ | ||
- | private function executeAction(string $controllerName, | ||
- | { | ||
- | // TODO: Stub Version | ||
- | $controller = " | ||
- | $instance = new $controller(); | ||
- | return call_user_func_array(array($instance, | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | \\ | ||
- | |||
- | ==== Applicationクラスのヘルパー関数 ==== | ||
- | |||
- | Applicationクラスのゲッターメソッドで良く使用されるものは boilerplates.php にヘルパー関数として追加しておきます。 | ||
- | |||
- | {{fa> | ||
- | <code php boilerplates.php> | ||
- | // ... | ||
- | |||
- | /** | ||
- | * Get application setting value | ||
- | * @param string|null $dot Dot-notation key | ||
- | * @param mixed $default | ||
- | * @return mixed | ||
- | */ | ||
- | function app($dot = null, $default=null) | ||
- | { | ||
- | return Core\Application:: | ||
- | } | ||
- | |||
- | /** | ||
- | * Get project directory | ||
- | * @param string|null $default | ||
- | * @return string project directory | ||
- | */ | ||
- | function project_dir($path = null): | ||
- | { | ||
- | return add_path(Core\Application:: | ||
- | } | ||
- | |||
- | /** | ||
- | * Get config directory | ||
- | * @param string $path Sub path, if necessary | ||
- | * @return string config directory | ||
- | */ | ||
- | function config_dir($path = null): | ||
- | { | ||
- | return add_path(Core\Application:: | ||
- | } | ||
- | |||
- | /** | ||
- | * Get assets directory | ||
- | * @param string $path Sub path, if necessary | ||
- | * @return string assets directory | ||
- | */ | ||
- | function assets_dir($path = null): | ||
- | { | ||
- | return add_path(Core\Application:: | ||
- | } | ||
- | |||
- | /** | ||
- | * Get var directory | ||
- | * @param string $path Sub path, if necessary | ||
- | * @return string var directory | ||
- | */ | ||
- | function var_dir($path = null): | ||
- | { | ||
- | return add_path(Core\Application:: | ||
- | } | ||
- | |||
- | /** | ||
- | * Get public directory | ||
- | * @param string $path Sub path, if necessary | ||
- | * @return string public directory | ||
- | */ | ||
- | function public_dir($path = null): | ||
- | { | ||
- | return add_path(Core\Application:: | ||
- | } | ||
- | |||
- | /** | ||
- | * Get application URL | ||
- | * @param string $path Sub path, if necessary | ||
- | * @return string URL | ||
- | */ | ||
- | function url($path = null): | ||
- | { | ||
- | // TODO: DomainとProtocolから計算する | ||
- | $base = env(' | ||
- | return add_path($base, | ||
- | } | ||
- | |||
- | /** | ||
- | * Get file URL With version | ||
- | * @param string $filename | ||
- | * @return string URL | ||
- | */ | ||
- | function url_ver(string $filename) | ||
- | { | ||
- | return url($filename).'? | ||
- | } | ||
- | |||
- | /** | ||
- | * Get routing path | ||
- | * @param string $path Sub path, if necessary | ||
- | * @return string routing path | ||
- | */ | ||
- | function route($path = null): | ||
- | { | ||
- | return add_path(Core\Application:: | ||
- | } | ||
- | |||
- | /** | ||
- | * Get current controller name | ||
- | * @return string name | ||
- | */ | ||
- | function controllerName(): | ||
- | { | ||
- | return Core\Application:: | ||
- | } | ||
- | |||
- | /** | ||
- | * Get current action name | ||
- | * @return string name | ||
- | */ | ||
- | function actionName(): | ||
- | { | ||
- | return Core\Application:: | ||
- | } | ||
- | </ | ||
- | |||
- | \\ | ||
- | |||
- | ==== Applicationクラスの設定ファイル ==== | ||
- | |||
- | Applicationクラスは次の2つの設定ファイルを持っています。これらはconfigフォルダ内に保存されています。 | ||
- | |||
- | * app.php | ||
- | * setup --- ライブラリの初期化ファイルの所在(フルパス) | ||
- | * middleware --- ミドルウェアの完全修飾クラス名 | ||
- | * auth --- ユーザ認証(セッション認証)の設定 | ||
- | * csrf --- CSRFトークンの設定 | ||
- | * routes.php --- ルーティング設定(URIとアクションの紐づけ)\\ ( ルーティング設定に関しては[[https:// | ||
- | |||
- | {{fa> | ||
- | |||
- | <code php app.php> | ||
- | <?php | ||
- | return | ||
- | [ | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ]; | ||
- | </ | ||
- | |||
- | <code php routes.php> | ||
- | <?php | ||
- | // | ||
- | // Route Definition Callback | ||
- | // | ||
- | return function (FastRoute\RouteCollector $r) | ||
- | { | ||
- | $base = Core\Application:: | ||
- | $r-> | ||
- | { | ||
- | // TODO: Stub Version | ||
- | $r-> | ||
- | header(" | ||
- | echo ' | ||
- | }); | ||
- | }); | ||
- | }; | ||
- | </ | ||
- | |||
- | \\ | ||
- | |||
- | ==== index.php(正式版) ==== | ||
- | |||
- | \\ | ||
- | |||
- | ===== 各種基本コアクラスの作成 ===== | ||
- | |||
- | 次に、Application以外の基本的なコアクラスを作って行きます。ここで作成する多くのクラスはシングルトンとして実装します。 | ||
- | |||
- | \\ | ||
- | |||
- | ==== 設定管理 ==== | ||
- | |||
- | \\ | ||
- | |||
- | ==== ロギング ==== | ||
- | |||
- | \\ | ||
- | |||
- | ==== 集約例外ハンドラー ==== | ||
- | |||
- | \\ | ||
- | |||
- | ==== デバッグバー ==== | ||
- | |||
- | \\ | ||
- | |||
- | ==== リクエスト ===== | ||
- | |||
- | \\ | ||
- | |||
- | ==== レスポンス ==== | ||
- | |||
- | \\ | ||
- | |||
- | ==== HTMLテンプレート ==== | ||
- | |||
- | \\ | ||
- | |||
- | ==== トランスレーション ==== | ||
- | |||
- | \\ | ||
- | |||
- | ===== アクションの実行 ===== | ||
- | |||
- | \\ | ||