LoginSignup
9
9

More than 5 years have passed since last update.

PHPフレームワーク

Last updated at Posted at 2015-02-03

hitSujiクラス

Web framework delivered as a C-extension for PHP

PHPのフレームワーク作りました。

ディレクトリ構成

サンプル

サンプル
app/
    libs/
    pages/
        always.php
        home.php
        user.php
    templates/
        home/
            fail.tpl
            success.tpl
        user/
            fail.tpl
            success.tpl
        always.tpl
        layout.tpl
www/
    index.php

ルーター系

index.php

hitSuji::router([
  '' => function () {
    echo '<html><head><title>サンプル</title></head><body></body></html>';
  },
  '/user/:id'=> [
    function ($id) {
      echo '<html><head><title>サンプル</title></head><body>'.
         'id='. $id .
         '</body></html>';
    }, 'get']
]);

結果

://sheeps.me/user/3

id=3

イベント処理を外部から読み込み

index.php

hitSuji::router([
  ''=> 'always.php'
  '/user/:id'=> ['user.php', 'get']
]);

always.php

$template = hitSuji::view();
$template->layout('layout.tpl');

hitSuji::delegate([
    /**
     * リクエスト定義
     *
     * @var array $data
     */
    'bind'=> [
        'signed' => ['number', 'coocke']
        'page'   => ['string', 'request'],
    ],
    /**
     * パース処理
     *
     * @access public
     * @param array $data
     * @return array
     */
    'parse' => function ($data) {
        return array_map('strtolower', $data);
    },
    /**
     * デフォルト処理
     *
     * @access public
     * @return void
     */
    'always' => function ($values) use($template) {
        $template->content('always.tpl');
        $template->display();
    }
]);

結果

://sheeps.me/

デフォルトページ

経緯

PHP-Extensionでやっちゃいました。
MVCってのがPHP向きじゃない気がしてならなかったので
リアクティブを目指して作ってみました。

  • PHPなんだし上から下に処理が流れるのでいいじゃないか?
  • 1プロセスのファイル数は極限まで抑えるべきじゃないか?
  • オブジェクト指向とかわけわからんし

アンシーを表現するのにダックスクラスとか犬クラスとかの
親クラスとかいらないし。
アンシーは唯一無二だからthe アンシーだから。

  • 再利用性がどーのこーのも正直、コードの可読性のほうが重要じゃね?

再利用性を高めるために迷路に迷い込むコードが無くなってほしい。

クラスは今後も使うけど、継承とか使わないです。
デフォルトの定義済みインターフェース以外いらん気がする。

主な機能

以下の流れを実現するフレームワークとしました。

1.URLの解析
2.リクエストの解析
3.アクション
4.出力
  ・デフォルト
  ・成功
  ・失敗

001.png

内部の機能はクラスで実装してます。
C言語の構造体の扱いが楽ちんになるからと
グループ化しやすいので クラス実装 してます。

修正

メモリの使用量と管理が面倒になったので配列ベースに修正しました。

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9