Mapleiniチェッカ
http://bobchin.ddo.jp/wiki/index.php?cmd=read&page=maple%2FDevelop%2FMapleIniCheck
Filter.interface.phpにチェック関数を追加しようと思ってたけど、別クラスにしておいたらテストで利用できるのかなぁ?
class Filter { /** * @var validate()で使用するmaple.iniの情報を格納する。 */ var $mapleini; /** * maple.iniの内容をチェックする * * @param $action アクションクラス名 * @param $attributes maple.iniの情報 * @access public * @since 3.0.0 **/ function validate($action, $attributes) { $log =& LogFactory::getLog(); $log->fatal("Filterでvalidate関数が作成されていません。", "Filter#validate"); exit; } /** * maple.iniに指定したセクション名があるか * * @param string $section セクション名 * @return boolean */ function inSection($section) { $sections = array_keys($this->mapleini); return in_array($sections, $section); } /** * 指定した配列内の値かどうか * * @param mixed $needles $haystackで指定した値かを確認する値 * @param array $haystack 固定の比較対象 * @return boolean */ function inArray($needles, $haystack) { if (!is_array($needles)) { $needles = array($needles); } foreach ($needles as $needle) { if (!in_array($needle, $haystack)) { return false; } } return true; } /** * Converter名かどうか * * @param string $name Converter名 * @return boolean */ function inConverter($name) { return $this->inFilename(CONVERTER_DIR, '/^Converter_(.*)\.class\.php$/'); } /** * Validator名かどうか * * @param string $name Validator名 * @return boolean */ function inValidator($name) { return $this->inFilename(VALIDATOR_DIR, '/^Validator_(.*)\.class\.php$/'); } /** * Filter名かどうか * * @param string $name Filter名 * @return boolean */ function inFilter($name) { return $this->inFilename(FILTER_DIR, '/^Filter_(.*)\.class\.php$/'); } /** * 指定したファイルかどうか * * @param string $dir ファイルの存在するディレクトリ * @param string $regex ファイル名の正規表現 * @return boolean */ function inFilename($dir, $regex) { $file = new Jp_Ddo_Bobchin_File(); $lists = $file->find($dir, $regex); foreach (array_keys($list) as $key) { $lists[$key] = strtolower(preg_replace($regex, '${1}', $lists[$key])); } return in_array($lists, strtolower($name)); } /** * アクションクラスのパラメータかどうか * * @param string $actionClass アクションクラス * @param string $name パラメータ名 * @return boolean */ function inActionParams($actionClass, $name) { if (!class_exists($actionClass)) { // アクションファイルのロード $path = array_map("strtolower", explode("_", $actionClass)); $actionfile = MODULE_DIR.DIRECTORY_SEPARATOR. implode(DIRECTORY_SEPARATOR, $path).DIRECTORY_SEPARATOR. $actionClass."class.php"; if (file_exists($actionfile)) { require_once $actionfile; } } $vars = get_class_vars($actionClass); return in_array(array_keys($vars), $name); } /** * ビューファイルが存在するかどうか * * @param string $viewfile ビューファイル名 * @return boolean */ function existsViewFile($viewfile) { return file_exists(SMARTY_TEMPLATE_DIR.$viewfile); } /** * diconファイルが存在するかどうか * * @param string $actionClass アクションクラス名 * @param string $diconfile diconファイル名 * @return boolean */ function existsDiconFile($actionClass, $diconfile) { $path = array_map("strtolower", explode("_", $actionClass)); $diconfile = MODULE_DIR.DIRECTORY_SEPARATOR. implode(DIRECTORY_SEPARATOR, $path).DIRECTORY_SEPARATOR.$diconfile; return file_exists($diconfile); } /** * 指定した値が正規表現にマッチするかどうか * * @param string $regex 正規表現 * @param string $value 値 * @return boolean */ function match($regex, $value) { if ($regex{0} != '/' || $regex{strlength($regex)-1} != '/') { $regex = '/' . trim($regex, '/') . '/'; } return (preg_match($regex, $value) == 1); } /** * 順番が正しいかどうか * * @param array $filters maple.ini上の順番を配列で指定する * @return boolean */ function order($filters) { if (!is_array($filters)) { return false; } $sections = array_map("strtolower", array_keys($this->mapleini)); $sections = array_flip($sections); $order = -1; foreach ($filters as $filter) { if (!isset($sections[$filter])) { continue; } if ($order < $sections[$filter]) { $order = $sections[$filter]; continue; } else { return false; } } return true; } }