Beispiel #1
0
 public function testIssetAndNotBlank()
 {
     $input = array('a' => '', 'b' => null, 'c' => false, 'd' => true, 'e' => 'value');
     $this->assertFalse(ArrayUtil::issetAndNotBlank($input, 'a'));
     $this->assertFalse(ArrayUtil::issetAndNotBlank($input, 'b'));
     $this->assertTrue(ArrayUtil::issetAndNotBlank($input, 'c'));
     $this->assertTrue(ArrayUtil::issetAndNotBlank($input, 'd'));
     $this->assertTrue(ArrayUtil::issetAndNotBlank($input, 'e'));
 }
Beispiel #2
0
 /**
  * Take a rule roke (e.g. news from /news/) and parse it
  *
  * @param string $token A token from the rule
  * @return array An array describing the token (name, isVar, choices, default)
  * @throws \MistyRouting\Exception\MalformedRuleException If the token is not valid
  */
 public static function parseToken($token)
 {
     $matches = array();
     $variableTokenPattern = "/^:([a-zA-Z0-9-_]+)(?:\\[([a-zA-Z0-9-_|]+)\\])?\$/";
     preg_match($variableTokenPattern, $token, $matches);
     $isVar = $choices = null;
     if (!empty($matches)) {
         // It matched the pattern, this means it's a variable token
         $name = $matches[1];
         $isVar = true;
         $choices = ArrayUtil::issetAndNotBlank($matches, 2) ? explode('|', $matches[2]) : null;
     } else {
         // It didn't matched the pattern, this means it's a fixed token
         if (strpos($token, ':') !== false) {
             throw new MalformedRuleException(sprintf('Invalid url token: %s', $token));
         }
         $name = $token;
     }
     return array('name' => $name, 'isVar' => (bool) $isVar, 'choices' => $choices);
 }