このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン 次のリビジョン 両方とも次のリビジョン | ||
apricot:core:top [2020/04/30 12:15] y2sunlight [ヘルパー] |
apricot:core:top [2020/05/11 22:03] y2sunlight [utilities.php] |
||
---|---|---|---|
行 9: | 行 9: | ||
* Apricot コア | * Apricot コア | ||
* Apricot コア作成の準備 | * Apricot コア作成の準備 | ||
- | * [[apricot: | + | * [[apricot: |
* [[apricot: | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
+ | * [[apricot: | ||
+ | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
* [[apricot: | * [[apricot: | ||
- | |||
- | ---- | ||
まずは、apricotのコアを作る為に以下を準備します。 | まずは、apricotのコアを作る為に以下を準備します。 | ||
行 23: | 行 23: | ||
* コアフォルダ、名前空間、オートローディングの設定 | * コアフォルダ、名前空間、オートローディングの設定 | ||
* コア構築のヘルパーとなるグローバル関数とベースクラス | * コア構築のヘルパーとなるグローバル関数とベースクラス | ||
- | \\ | + | |
+ | ---- | ||
===== 環境設定 ===== | ===== 環境設定 ===== | ||
行 72: | 行 73: | ||
</ | </ | ||
- | > core フォルダは[[https:// | + | * core フォルダは[[https:// |
=== configフォルダ === | === configフォルダ === | ||
- | プロジェクトフォルダ下に、アプリケーション設定用のフォルダ config を作成し、その下に2つのフォルダ(setting, | + | 同様に、アプリケーション設定用のフォルダ config を作成し、その下に2つのフォルダ(setting, |
< | < | ||
行 87: | 行 88: | ||
</ | </ | ||
- | > フォルダ及びファイル名は全てsnake_caseを使用します。 | + | === assetsフォルダ |
+ | |||
+ | 同様に、リソース用のフォルダ assets を作成し、その下に3つのフォルダ(lang, | ||
+ | |||
+ | < | ||
+ | apricot [プロジェクト] | ||
+ | | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | === var フォルダ === | ||
+ | |||
+ | 同様に、フォルダ var を作成し、その下に3つのフォルダ(cache, | ||
+ | |||
+ | < | ||
+ | apricot [プロジェクト] | ||
+ | | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
\\ | \\ | ||
行 168: | 行 195: | ||
* boilerplates.php --- apricotでよく使用される定型文的なコードパターンを関数化したもの\\ ( apricotではボイラープレートと呼んでいる ) | * boilerplates.php --- apricotでよく使用される定型文的なコードパターンを関数化したもの\\ ( apricotではボイラープレートと呼んでいる ) | ||
+ | |||
* utilities.php --- PHPの組み込み関数を拡張した関数群\\ ( apricot内部で使用することが主な目的 ) | * utilities.php --- PHPの組み込み関数を拡張した関数群\\ ( apricot内部で使用することが主な目的 ) | ||
行 221: | 行 249: | ||
==== utilities.php ==== | ==== utilities.php ==== | ||
- | utilities.php にはapricot内部で使用する様々な関数が実装さいれています。ほとんどの場合、アプリケーションから使用することはないと思うます。使用法などは以下のソースコードを参照して下さい。 | + | utilities.php にはapricot内部で使用する様々な関数が実装さいれています。ほとんどの場合、アプリケーションから使用することはないと思います。使用法などは以下のソースコードを参照して下さい。 |
{{fa> | {{fa> | ||
行 363: | 行 391: | ||
{ | { | ||
return (new \ReflectionClass($object))-> | return (new \ReflectionClass($object))-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Get snake_case from UpperCamelCase or lowerCamelCase | ||
+ | * @param string $camel | ||
+ | * @return string|null | ||
+ | */ | ||
+ | function snake_case(string $camel =null) | ||
+ | { | ||
+ | if (!isset($camel)) return null; | ||
+ | |||
+ | $snake = preg_replace('/ | ||
+ | return ltrim(strtolower($snake), | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Get SQL text from a file | ||
+ | * @param string $filename | ||
+ | * @return array | ||
+ | */ | ||
+ | function file_get_sql(string $filename): | ||
+ | { | ||
+ | if (!file_exists($filename)) return []; | ||
+ | |||
+ | // Read a file | ||
+ | $text = file_get_contents($filename); | ||
+ | $text = str_replace([" | ||
+ | |||
+ | // Remove comment | ||
+ | $text = preg_replace("/ | ||
+ | $text = preg_replace("/ | ||
+ | |||
+ | // Split SQL text | ||
+ | $sql = preg_split("/ | ||
+ | array_walk($sql, | ||
+ | $item = trim($item); | ||
+ | }); | ||
+ | $sql = array_filter($sql, | ||
+ | return !empty(trim($val)); | ||
+ | }); | ||
+ | return $sql; | ||
} | } | ||
</ | </ |