LoginSignup
0
0

More than 5 years have passed since last update.

hitSuji基底クラス

Last updated at Posted at 2015-02-04

hitSujiクラス

Web framework delivered as a C-extension for PHP

hitSujiクラス
class hitSuji {
    public static function nonce(string $seed);
    public static function template(void);
    public static function request(array $opstion);
    public static function router(array $opstion);
    public static function delegate(array $opstion);
    public static function quick(array $opstion);
}

実行時設定

名前 変更可能 デフォルト
hitsuji.nonce_function PHP_INI_ALL NULL
hitsuji.lifetime PHP_INI_ALL 28800
hitsuji.seed PHP_INI_ALL "asdfj5246485902rweld"
hitsuji.template_path PHP_INI_ALL NULL
hitsuji.page_path PHP_INI_ALL NULL
hitsuji.string_pattern PHP_INI_ALL "/[^\/]/i"
hitsuji.email_pattern PHP_INI_ALL 下記に記述
hitsuji.date_pattern PHP_INI_ALL "/[0-9]{4}-?[0-9]{2}-?[0-9]{2}/"
hitsuji.datetime_pattern PHP_INI_ALL "/[0-9]{4}-?[0-9]{2}-?[0-9]{2}\s?[0-9]{2}:?[0-9]{2}:?[0-9]{2}/"

hitsuji.nonce_function string

nonce値取得用の関数名を設定
NULLの場合hitSujiクラスの関数を使用

hitsuji.lifetime long

nonce値の有効時間(秒)

hitsuji.seed string

nonce値生成用文字列

hitsuji.template_path string

テンプレートファイルの保存パス

hitsuji.page_path string

ページロジックの保存パス

hitsuji.string_pattern string

文字列判定用正規表現

hitsuji.email_pattern string

メールアドレス判定用正規表現

"/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/"

hitsuji.date_pattern string

日付判定用正規表現

hitsuji.datetime_pattern string

日時判定用正規表現

nonce値の取得

public static function nonce(string $seed);

引数

名前 概要
seed string ハッシュ種

戻り値

nonce値文字列

$nonce = \hitSuji::nonce('/usr/:id');

ワンタイムパスワードなどで使用する文字列を取得します。

ビューの呼び出し

public static function template();

戻り値

hitSuji\Viewオブジェクト

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

リクエスト処理

public static function request(array $opstion);

引数

名前 概要
opstion array オプション

オプション

変数名をキーとして配列を渡します。

配列要素型 概要
number 数値判定
string 文字列判定
email メールアドレス判定
url URL判定
date 日付判定
datetime 日時判定
regex 正規表現判定
Track指定 概要
post $_POSTデータ
get $_GETデータ
route URL指定したデータ /user/:id
cookie $_COOKIEデータ
server $_SERVERデータ
request $_REQUESTデータ
特殊指定 概要
require 必須データ

戻り値

取得したデータ

$vars = hitSuji::request([
  'id'=> number,
  'name'=> array('string', 'require'),
  'email'=> array('email', 'request'),
));

ルーター処理

public static function router(array $opstion);

引数

名前 概要
opstion array オプション

オプション

アクセスURLをキーとして配列を渡します。

キー 概要
'' emptyの場合はデフォルト処理
/user/:id :(変数名) コロン+変数名でURL文字列取得
/about 変数名なしのアクセスパス
配列要素 概要
'get' GETメソッドの処理
'post' POSTメソッドの処理
callback 処理をするコールバック関数
phpファイル 処理をするPHPファイル名
\hitSuji::router([
  '' => 'always.php'
  '/user/:id' => ['post', 'user.php']
  '/about' => [
    function() {
      echo 'about';
    }, 'get'
  ]
]);

デリゲータ処理

public static function delegate(array $opstion);

引数

名前 概要
opstion array オプション

オプション

キー 概要
data 直接指定したデータ
bind フォームなどのデータ取得ルール
parse データの解析処理
action DBなどアクション処理
always デフォルト表示処理
done 成功時表示処理
fail 失敗時表示処理
hitSuji::delegate([
  'data' => [
    'skey' => $_REQUEST['skey']
  ],
  'bind' => [
    'id' => ['number', 'route'],
  ],
  'parse' => function ($data) {
    return array_map('intval', $data);
  },
  'action' => function ($data) {
    return [true, $data];
  },
  'always' => function ($values) {
    echo 'デフォルト';
  },
  'done' => function ($values) {
    echo '成功';
  },
  'fail' => function ($values) {
    echo '失敗';
  }
]);

001.png

クイック処理

public static function quick(array $opstion);

引数

名前 概要
opstion array オプション

オプション

キー 概要
data 直接指定したデータ
parse データの解析処理
action DBなどアクション処理
done 成功時処理
fail 失敗時処理
hitSuji::quick([
  'data' => [
    'skey' => $_REQUEST['skey']
  ],
  'parse' => function ($data) {
    return array_map('intval', $data);
  },
  'action' => function ($data) {
    return [true, $data];
  },
  'done' => function ($values) {
    echo '成功';
  },
  'fail' => function ($values) {
    echo '失敗';
  }
]);

002.png

0
0
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
0
0