本文整理匯總了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));
}