本文整理汇总了PHP中SpoonFilter::isEven方法的典型用法代码示例。如果您正苦于以下问题:PHP SpoonFilter::isEven方法的具体用法?PHP SpoonFilter::isEven怎么用?PHP SpoonFilter::isEven使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpoonFilter
的用法示例。
在下文中一共展示了SpoonFilter::isEven方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isCorrectSyntax
/**
* Check the string for syntax errors
*
* @return bool
* @param string $string
* @param string $type
*/
private function isCorrectSyntax($string, $type)
{
// init vars
$string = (string) $string;
$type = SpoonFilter::getValue($type, array('cycle', 'iteration', 'option', 'variable'), 'variable', 'string');
// types
switch ($type) {
// cycle string
case 'cycle':
// the number of single qoutes should always be an even number
if (!SpoonFilter::isEven(substr_count($string, "'"))) {
return false;
}
break;
// iteration string
// iteration string
case 'iteration':
// the number of square opening/closing brackets should be equal
if (substr_count($string, '[') != substr_count($string, ']')) {
return false;
}
// the number of single qoutes should always be an even number
if (!SpoonFilter::isEven(substr_count($string, "'"))) {
return false;
}
// first charachter should not be a number
if (SpoonFilter::isInteger(substr($string, 2, 1))) {
return false;
}
// square bracket followed by a dot is NOT allowed eg {option:variable[0].var}
if (substr_count($string, '].') != 0) {
return false;
}
// dot followed by a square bracket is NOT allowed eg {option:variable.['test']}
if (substr_count($string, '.[') != 0) {
return false;
}
// empty brackets are NOT allowed
if (substr_count($string, '[]') != 0) {
return false;
}
break;
// option string
// option string
case 'option':
// the number of square opening/closing brackets should be equal
if (substr_count($string, '[') != substr_count($string, ']')) {
return false;
}
// the number of single qoutes should always be an even number
if (!SpoonFilter::isEven(substr_count($string, "'"))) {
return false;
}
// square bracket followed by a dot is NOT allowed eg {option:variable[0].var}
if (substr_count($string, '].') != 0) {
return false;
}
// dot followed by a square bracket is NOT allowed eg {option:variable.['test']}
if (substr_count($string, '.[') != 0) {
return false;
}
// empty brackets are NOT allowed
if (substr_count($string, '[]') != 0) {
return false;
}
break;
// variable string
// variable string
case 'variable':
// the number of square opening/closing brackets should be equal
if (substr_count($string, '[') != substr_count($string, ']')) {
return false;
}
// the number of single qoutes should always be an even number
if (!SpoonFilter::isEven(substr_count($string, "'"))) {
return false;
}
// first charachter should not be a number
if (SpoonFilter::isInteger(substr($string, 2, 1))) {
return false;
}
// square bracket followed by a dot is NOT allowed eg {$variable[0].var}
if (substr_count($string, '].') != 0) {
return false;
}
// dot followed by a square bracket is NOT allowed eg {$variable.['test']}
if (substr_count($string, '.[') != 0) {
return false;
}
// empty brackets are NOT allowed
if (substr_count($string, '[]') != 0) {
return false;
}
//.........这里部分代码省略.........
示例2: testIsEven
public function testIsEven()
{
$this->assertTrue(SpoonFilter::isEven(0));
$this->assertFalse(SpoonFilter::isEven(1));
$this->assertTrue(SpoonFilter::isEven(10901920));
$this->assertFalse(SpoonFilter::isEven(-1337));
// I don't know man, semantically speaking, this bull shit, but it does
// adhere to PHP's idiosyncratic casting rules.
$this->assertTrue(SpoonFilter::isEven(array()));
$this->assertFalse(SpoonFilter::isEven(array(2)));
}
示例3: testIsEven
public function testIsEven()
{
$this->assertTrue(SpoonFilter::isEven(0));
$this->assertFalse(SpoonFilter::isEven(1));
$this->assertTrue(SpoonFilter::isEven(10901920));
$this->assertFalse(SpoonFilter::isEven(-1337));
}