本文整理汇总了PHP中Validation::comparison方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::comparison方法的具体用法?PHP Validation::comparison怎么用?PHP Validation::comparison使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validation
的用法示例。
在下文中一共展示了Validation::comparison方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: field_comparison
function field_comparison($check1, $operator, $field2)
{
foreach ($check1 as $key => $value1) {
$value2 = $this->data[$this->alias][$field2];
if (!Validation::comparison($value1, $operator, $value2)) {
return false;
}
}
return true;
}
示例2: compareWithField
public function compareWithField($validationFields = array(), $operator = null, $compareFieldName = '')
{
if (!isset($this->data[$this->name][$compareFieldName])) {
throw new CakeException(sprintf('Can\'t compare to the non-existing field "%s" of model %s.'), $compareFieldName, $this->name);
}
$compareTo = $this->data[$this->name][$compareFieldName];
foreach ($validationFields as $key => $value) {
if (!Validation::comparison($value, $operator, $compareTo)) {
return false;
}
}
return true;
}
示例3: testComparisonAsArray
/**
* testComparisonAsArray method
*
* @return void
*/
public function testComparisonAsArray()
{
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'is greater', 'check2' => 6)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '>', 'check2' => 6)));
$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => 'is less', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => '<', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'greater or equal', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '>=', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'greater or equal', 'check2' => 6)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '>=', 'check2' => 6)));
$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => 'less or equal', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => '<=', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'equal to', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '==', 'check2' => 7)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'not equal', 'check2' => 6)));
$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '!=', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => 'is greater', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => '>', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'is less', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '<', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => 'greater or equal', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => '>=', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => 'greater or equal', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => '>=', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'less or equal', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '<=', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'equal to', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '==', 'check2' => 6)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'not equal', 'check2' => 7)));
$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '!=', 'check2' => 7)));
}
示例4: applyConditions
/**
* Retorna o texto já aplicadas as suas condições
*
* @param string $col a coluna que será comparada
* @param array $conditions array com as condições
* @param integer $row O número da linha no array de dados
* @return string O texto formatado e aplicado as condições
*/
private function applyConditions($col, $conditions, $row)
{
//valor dessa linha e desse campo
$curValue = $this->data[$row][$col];
foreach ($conditions as $key => $cond) {
$params = $conditions[$key];
//Se for acima da versão 0.2
//if((SPAGHETTI_VERSION >= 0.2)):
$comparison = Validation::comparison($curValue, $params['operator'], $params['comparator']);
//Se for a versão 0.1, não suportará operadores de comparação
//else:
// $comparison = $curValue == $params['comparator'];
//endif;
//Se a comparação foi promissora
if ($comparison) {
//Se existir um label
//$alt = isset($params['alt']) ? $params['alt'] : '';
$label = isset($params['label']) ? $this->isImage($params['label'], $params) : $curValue;
//Se um link foi definido
$return = isset($params['href']) ? $this->link($label, $params['href']) : $label;
//Se uma class de linha tiver definida
if (isset($params['rowClass'])) {
$this->rowClass[$row] = array_unset($params, 'rowClass');
//$this->rowClass[$row] = $params['rowClass'];
}
//Se uma classe de célula estiver definida
if (isset($params['cellClass'])) {
$this->cellClass[$col][$row] = array_unset($params, 'cellClass');
// $this->cellClass[$col][$row] = $params['cellClass'];
}
$matched = true;
break;
}
}
//Se após o foreach achou-se o valor
if ($matched === true) {
return $this->extract($return, $row);
} else {
return $curValue;
}
}
示例5: testInvalidComparison
/**
* @testdox valid should return false to number equal other number
*/
public function testInvalidComparison()
{
$value1 = 3.14;
$value2 = 42;
$this->assertFalse(Validation::comparison($value1, 'equal', $value2));
}
示例6: testComparisonTypeChecks
/**
* Test comparison casting values before comparisons.
*
* @return void
*/
public function testComparisonTypeChecks()
{
$this->assertFalse(Validation::comparison('\\x028', '>=', 1), 'hexish encoding fails');
$this->assertFalse(Validation::comparison('0b010', '>=', 1), 'binary string data fails');
$this->assertFalse(Validation::comparison('0x01', '>=', 1), 'hex string data fails');
$this->assertFalse(Validation::comparison('0x1', '>=', 1), 'hex string data fails');
$this->assertFalse(Validation::comparison('\\x028', '>=', 1.5), 'hexish encoding fails');
$this->assertFalse(Validation::comparison('0b010', '>=', 1.5), 'binary string data fails');
$this->assertFalse(Validation::comparison('0x02', '>=', 1.5), 'hex string data fails');
}
示例7: validateImageSize
/**
* Image size validation method
*
* @param mixed $check
* @param array $options is an array with key width or height and a value of array
* with two options, operator and value. For example:
* array('height' => array('==', 100)) will only be true if the image has a
* height of exactly 100px. See the CakePHP core class and method
* Validation::comparison for all operators.
* @return boolean true
* @see Validation::comparison()
* @throws \InvalidArgumentException
*/
public function validateImageSize($check, $options)
{
if (!isset($options['height']) && !isset($options['width'])) {
throw new \InvalidArgumentException(__d('file_storage', 'Invalid image size validation parameters'));
}
if (is_string($check)) {
$imageFile = $check;
} else {
$check = array_values($check);
$check = $check[0];
if (is_array($check) && isset($check['tmp_name'])) {
$imageFile = $check['tmp_name'];
} else {
$imageFile = $check;
}
}
$imageSizes = $this->getImageSize($imageFile);
if (isset($options['height'])) {
$height = Validation::comparison($imageSizes[1], $options['height'][0], $options['height'][1]);
} else {
$height = true;
}
if (isset($options['width'])) {
$width = Validation::comparison($imageSizes[0], $options['width'][0], $options['width'][1]);
} else {
$width = true;
}
if ($height === false || $width === false) {
return false;
}
return true;
}
示例8: checkDateComp
/**
* Used to compare 2 datetime values.
*
* @param object &$model use model
* @param string|array $check datetime string
* @param string $operator Can be either a word or operand
* is greater >, is less <, greater or equal >=
* less or equal <=, is less <, equal to ==, not equal !=
* @param string $compare compare datetime string
* @return bool Success
*/
public function checkDateComp(&$model, $check, $operator, $compare)
{
// 比較対象がないので比較する必要なし
if (Validation::blank($model->data['Registration'][$compare])) {
return true;
}
$check2 = strtotime($model->data['Registration'][$compare]);
foreach ($check as $val) {
if (Validation::blank($val)) {
continue;
}
$check1 = strtotime($val);
$ret = Validation::comparison($check1, $operator, $check2);
if (!$ret) {
return false;
}
}
return true;
}