k-holy / volcanus-routing Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
初回のインスタンスにセットされたパラメータが、次回に引数付きでインスタンス取得した場合に初期化されてしまう。
動作が分かりづらくなるため、instance()メソッドはシングルトンの実装のみとして、初期化したい場合はinitialize()メソッドを明示的に呼ぶこととする。
現在の仕様
<?php
$router = Router::instance([
'parameterDirectoryName' => '%VAR%',
])>execute();
// RequestURI /items/1 … include /items/%VAR%/index.php
<?php
$item_id = $router->parameter(0); // (string)'1'
こういうのに対応
<?php
$router = Router::instance([
'parameterDirectoryLeftDelimiter' => '{%',
'parameterDirectoryRightDelimiter' => '%}',
'parameterFilters' => [
'digit' => function($var) {
if (!ctype_digit($var)) {
throw new InvalidParameterException('oh...');
}
return intval($var);
},
],
])->execute();
// RequestURI /items/1 … include /items/{%digit%}/index.php
// RequestURI /items/a … InvalidParameterException
<?php
$item_id = $router->parameter(0); // (int)1
デリミタ導入前の仕様では実現できなかった以下のパターンにも対応できるか?
<?php
$router = Router::instance([
'parameterDirectoryLeftDelimiter' => '{%',
'parameterDirectoryRightDelimiter' => '%}',
'parameterFilters' => [
'digit' => function($var) {
if (!ctype_digit($var)) {
throw new InvalidParameterException('oh...');
}
return intval($var);
},
'alpha' => function($var) {
if (!ctype_alpha($var) {
throw new InvalidParameterException('ahh...');
}
return $var;
},
],
])->execute();
// RequestURI /users/1 … include /users/{%digit%}/index.php
// RequestURI /users/kholy … include /users/{%alpha%}/index.php
// RequestURI /users/k-holy ... InvalidParameterException
ただし、先にマッチしたものが適用されるので、ルールは相互に影響しないものとする必要あり?
<?php
$user_id = $router->parameter(0); // (int) 1
<?php
$account_id = $router->parameter(0); // (string) 'kholy'
あと、Ctype関数はデフォルトで対応しても良いかも。
Volcanus_Configurationの廃止メソッドが利用されているため
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.