Source for file ValidatorManager.php
Documentation is available at ValidatorManager.php
* Teeple2 - PHP5 Web Application Framework inspired by Seasar2
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @author Mitsutaka Sato <miztaka@gmail.com>
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* 'name' => 'フィールド名', // 必須
* 'label' => 'ラベル名', // 任意
const DEFAULT_MESSAGE =
'{0}が正しく入力されていません。';
* @param $yaml YAML形式の文字列
$yamlConfig =
Horde_Yaml::load($yaml);
//$this->log->debug(var_export($yamlConfig, true));
$validationConfig =
array();
foreach($yamlConfig as $field =>
$validations) {
if (count($fields) ==
2) {
$oneConfig['label'] =
$fields[1];
$oneConfig['name'] =
$fields[0];
$oneConfig['validation'] =
$validations;
//$this->log->debug(var_export($validationConfig, true));
return $validationConfig;
* 指定されたconfigでバリデーションを実行します。
* エラーがあった場合はエラーメッセージを組み立てて
public function execute($obj, &$config) {
foreach($config as $fieldConfig) {
$fieldName =
$fieldConfig['name'];
foreach($fieldConfig['validation'] as $validatorName =>
$attr) {
foreach($attr as $key =>
$value) {
$validator->$key =
$value;
if (! $validator->validate($obj, $fieldName)) {
$this->setErrorMessage($validator, $validatorName, $attr, $fieldConfig);
* @param Teeple_Validator $validator
* @param string $validatorName
* @param array $validatorConfig
* @param array $fieldConfig
private function setErrorMessage($validator, $validatorName, &$validatorConfig, &$fieldConfig) {
$msg =
$this->getMessage($validatorName, $validatorConfig);
$label =
$this->getLabel($fieldConfig);
foreach($validator->args as $propName) {
* @param string $validatorName
* @param array $validatorConfig
private function getMessage($validatorName, &$validatorConfig) {
return $validatorConfig['msg'];
$msg =
$this->resource->getResource('errors.'.
$validatorName);
$msg =
self::DEFAULT_MESSAGE;
* @param array $fieldConfig
private function getLabel(&$fieldConfig) {
return $fieldConfig['label'];
$label =
$this->resource->getResource('form.'.
$fieldConfig['name']);
$label =
$fieldConfig['name'];