このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
|
apricot:core:top [2020/05/05 10:14] y2sunlight [Apricot コア作成の準備] |
apricot:core:top [2020/06/03 10:02] (現在) tanaka [utilities.php] |
||
|---|---|---|---|
| 行 13: | 行 13: | ||
| * [[apricot: | * [[apricot: | ||
| * [[apricot: | * [[apricot: | ||
| + | * [[apricot: | ||
| * [[apricot: | * [[apricot: | ||
| * [[apricot: | * [[apricot: | ||
| - | * [[apricot: | + | * [[apricot: |
| - | + | ||
| - | \\ | + | |
| まずは、apricotのコアを作る為に以下を準備します。 | まずは、apricotのコアを作る為に以下を準備します。 | ||
| 行 91: | 行 90: | ||
| === assetsフォルダ === | === assetsフォルダ === | ||
| - | 同様に、リソース用のフォルダ assets を作成し、その下に3つのフォルダ(lang, | + | 同様に、リソース用のフォルダ assets を作成し、その下に3つのフォルダ(lang, |
| < | < | ||
| 行 100: | 行 99: | ||
| | | ||
| | | ||
| - | | + | |
| </ | </ | ||
| 行 193: | 行 192: | ||
| ===== ヘルパー ===== | ===== ヘルパー ===== | ||
| - | グローバル関数を保存するためのPHPファイルを core\helper | + | グローバル関数を保存するためのPHPファイルを core\helpers |
| * boilerplates.php --- apricotでよく使用される定型文的なコードパターンを関数化したもの\\ ( apricotではボイラープレートと呼んでいる ) | * boilerplates.php --- apricotでよく使用される定型文的なコードパターンを関数化したもの\\ ( apricotではボイラープレートと呼んでいる ) | ||
| 行 252: | 行 251: | ||
| utilities.php にはapricot内部で使用する様々な関数が実装さいれています。ほとんどの場合、アプリケーションから使用することはないと思います。使用法などは以下のソースコードを参照して下さい。 | utilities.php にはapricot内部で使用する様々な関数が実装さいれています。ほとんどの場合、アプリケーションから使用することはないと思います。使用法などは以下のソースコードを参照して下さい。 | ||
| - | {{fa> | + | {{fa> |
| <code php utilities.php> | <code php utilities.php> | ||
| <?php | <?php | ||
| 行 392: | 行 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; | ||
| } | } | ||
| </ | </ | ||