本文整理汇总了PHP中Validation::inList方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::inList方法的具体用法?PHP Validation::inList怎么用?PHP Validation::inList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validation
的用法示例。
在下文中一共展示了Validation::inList方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInList
/**
* testInList method
*
* @return void
*/
public function testInList()
{
$this->assertTrue(Validation::inList('one', array('one', 'two')));
$this->assertTrue(Validation::inList('two', array('one', 'two')));
$this->assertFalse(Validation::inList('three', array('one', 'two')));
$this->assertFalse(Validation::inList('1one', array(0, 1, 2, 3)));
$this->assertFalse(Validation::inList('one', array(0, 1, 2, 3)));
$this->assertFalse(Validation::inList('2', array(1, 2, 3)));
$this->assertTrue(Validation::inList('2', array(1, 2, 3), false));
}
示例2: testInList
/**
* testInList method
*
* @return void
*/
public function testInList()
{
$this->assertTrue(Validation::inList('one', array('one', 'two')));
$this->assertTrue(Validation::inList('two', array('one', 'two')));
$this->assertFalse(Validation::inList('three', array('one', 'two')));
$this->assertFalse(Validation::inList('1one', array(0, 1, 2, 3)));
$this->assertFalse(Validation::inList('one', array(0, 1, 2, 3)));
$this->assertTrue(Validation::inList('2', array(1, 2, 3)));
$this->assertFalse(Validation::inList('2x', array(1, 2, 3)));
$this->assertFalse(Validation::inList(2, array('1', '2x', '3')));
$this->assertFalse(Validation::inList('One', array('one', 'two')));
// No hexadecimal for numbers.
$this->assertFalse(Validation::inList('0x7B', array('ABC', '123')));
$this->assertFalse(Validation::inList('0x7B', array('ABC', 123)));
// case insensitive
$this->assertTrue(Validation::inList('one', array('One', 'Two'), true));
$this->assertTrue(Validation::inList('Two', array('one', 'two'), true));
$this->assertFalse(Validation::inList('three', array('one', 'two'), true));
}
示例3: testInList
/**
* testInList method
*
* @return void
*/
public function testInList()
{
$this->assertTrue(Validation::inList('one', array('one', 'two')));
$this->assertTrue(Validation::inList('two', array('one', 'two')));
$this->assertFalse(Validation::inList('three', array('one', 'two')));
$this->assertFalse(Validation::inList('1one', array(0, 1, 2, 3)));
$this->assertFalse(Validation::inList('one', array(0, 1, 2, 3)));
$this->assertTrue(Validation::inList('2', array(1, 2, 3)));
$this->assertFalse(Validation::inList('2x', array(1, 2, 3)));
$this->assertFalse(Validation::inList(2, array('1', '2x', '3')));
$this->assertFalse(Validation::inList('One', array('one', 'two')));
// case insensitive
$this->assertTrue(Validation::inList('one', array('One', 'Two'), true));
$this->assertTrue(Validation::inList('Two', array('one', 'two'), true));
$this->assertFalse(Validation::inList('three', array('one', 'two'), true));
}
示例4: testInvalidInList
/**
* @testdox inList should return false to element not within the list
*/
public function testInvalidInList()
{
$value = 'PHP';
$list = array('Spaghetti', 'Framework');
$this->assertFalse(Validation::inList($value, $list));
}
示例5: testInList
/**
* testInList method
*
* @access public
* @return void
*/
function testInList()
{
$this->assertTrue(Validation::inList('one', array('one', 'two')));
$this->assertTrue(Validation::inList('two', array('one', 'two')));
$this->assertFalse(Validation::inList('three', array('one', 'two')));
}
示例6: checkMatrixAnswerInList
/**
* checkMatrixAnswerInList
*
* @param object &$model use model
* @param string $answers answer value
* @param int $list choice list ( choice key list)
* @return bool
*/
public function checkMatrixAnswerInList(&$model, $answers, $list)
{
$ret = true;
foreach ($answers as $matrixRowId => $matrixColAns) {
if (!Validation::inList(strval($matrixRowId), $list)) {
$ret = false;
$model->validationErrors['answer_value'][] = __d('registrations', 'Invalid choice');
}
$choiceIds = array_keys($matrixColAns);
foreach ($choiceIds as $choiceId) {
if ($choiceId != '' && !Validation::inList(strval($choiceId), $list)) {
$ret = false;
$model->validationErrors['answer_value'][] = __d('registrations', 'Invalid choice');
}
}
}
return $ret;
}
示例7: checkMatrixAnswerInList
/**
* checkMatrixAnswerInList
*
* @param array $question question
* @param string $answers answer value
* @param int $list choice list ( choice origin_id list)
* @return array error message
*/
public function checkMatrixAnswerInList($question, $answers, $list)
{
$errors = array();
foreach ($answers as $matrixRowId => $matrixColAns) {
if (!Validation::inList(strval($matrixRowId), $list)) {
$errors[] = __d('questionnaires', 'Invalid choice');
}
$choiceIds = array_keys($matrixColAns);
foreach ($choiceIds as $choiceId) {
if ($choiceId != '' && !Validation::inList(strval($choiceId), $list)) {
$errors[] = __d('questionnaires', 'Invalid choice');
}
}
}
return $errors;
}
示例8: testInvalidInList
public function testInvalidInList()
{
$value = "PHP";
$list = array("Spaghetti", "Framework");
$this->assertFalse(Validation::inList($value, $list));
}
示例9: answerChoiceValidation
/**
* answerValidation 登録内容の正当性
*
* @param object &$model use model
* @param array $data Validation対象データ
* @param array $question 登録データに対応する項目
* @param array $allAnswers 入力された登録すべて
* @return bool
*/
public function answerChoiceValidation(&$model, $data, $question, $allAnswers)
{
if (!in_array($question['question_type'], $this->_choiceValidateType)) {
return true;
}
if (!isset($model->data['RegistrationAnswer']['answer_values'])) {
return true;
}
// 項目に設定されている選択肢を配列にまとめる
$list = Hash::combine($question['RegistrationChoice'], '{n}.id', '{n}.key');
$ret = true;
// 選択された選択肢IDすべてについて調査する
$choiceIds = array_keys($model->data['RegistrationAnswer']['answer_values']);
foreach ($choiceIds as $choiceId) {
// 選択されたIDは、ちゃんと用意されている選択肢の中のひとつであるか
if ($choiceId != '' && !Validation::inList(strval($choiceId), $list)) {
$ret = false;
$model->validationErrors['answer_value'][] = __d('registrations', 'Invalid choice');
}
// チェックされている選択肢が「その他」の項目である場合は
$choice = Hash::extract($question['RegistrationChoice'], '{n}[key=' . $choiceId . ']');
if ($choice && $choice[0]['other_choice_type'] != RegistrationsComponent::OTHER_CHOICE_TYPE_NO_OTHER_FILED) {
// 具体的なテキストが書かれていないといけない
if (empty($model->data['RegistrationAnswer']['other_answer_value'])) {
$ret = false;
$model->validationErrors['answer_value'][] = __d('registrations', 'Please enter something, if you chose the other item');
}
}
}
return $ret;
}
示例10: notInListFromConfigure
/**
* notInListFromConfigure
* jpn: Configure::write()で設定されているarray()からnotInListを生成
*
*/
public function notInListFromConfigure(Model $model, $field, $listname)
{
$value = array_shift($field);
$list = Configure::read($listname);
if ($list !== array_values($list)) {
// jpn: selectのoptionsにそのまま設置するような連想配列を想定
$list = array_keys($list);
}
foreach ($list as $k => $v) {
$list[$k] = (string) $v;
}
return !Validation::inList($value, $list);
}