示例#1
0
 function testEscapeRegex()
 {
     $this->assertEquals(1, preg_match("/\\\\b/", "\\b", $matches));
     $this->assertEquals("\\.", Str::escapeRegex("."));
     $this->assertEquals("\\\\b", Str::escapeRegex("\\b"));
     $this->assertEquals("\\\\bold\\.", Str::escapeRegex("\\bold."));
 }
示例#2
0
 /**
  * Get value for a given key but do no expression evaluation.
  *
  * @param string $key Key to use for message lookup.
  * @param boolean $strict Whether to throw an error when key not found.
  *
  * @return string Message.
  *
  * @throws Exception if key not found and $strict == true.
  */
 private function getSimple($key, $strict = FALSE)
 {
     // if null, empty, or starts with comment sequence  of '#" or '//' - fail
     // if in dev mode, check to see if exists multiple times and fail saying invalid property file
     //use preg_match_all
     // get regular expresion for matching key
     $regex = self::PROP_VALUE_REGEX_PREPEND . Str::escapeRegex($key) . self::PROP_VALUE_REGEX_APPEND;
     // find resource
     preg_match($regex, $this->properties, $matches);
     // if found, return it
     if (isset($matches[1])) {
         return $matches[1];
         // not found, if not default, try to find in default resource
     } else {
         if (!$this->isDefault) {
             preg_match($regex, $this->defaultProperties, $matches);
             // if found, return it
             if (isset($matches[1])) {
                 return $matches[1];
             }
         }
     }
     if ($strict) {
         throw new Exception("The key \"" . $key . "\" was not found.");
     } else {
         return $key;
     }
 }