当前位置: 首页>>代码示例>>PHP>>正文


PHP SpoonFilter::isEven方法代码示例

本文整理汇总了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;
             }
//.........这里部分代码省略.........
开发者ID:JonckheereM,项目名称:Public,代码行数:101,代码来源:compiler.php

示例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)));
 }
开发者ID:jeroendesloovere,项目名称:library,代码行数:11,代码来源:SpoonFilterTest.php

示例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));
 }
开发者ID:sunkangtaichi,项目名称:library,代码行数:7,代码来源:SpoonFilterTest.php


注:本文中的SpoonFilter::isEven方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。