コード例 #1
0
ファイル: StringTest.php プロジェクト: jjok/string
 /**
  * @covers jjok\String\String::hyphenate
  */
 public function testStringCanBeHyphenated()
 {
     $this->assertSame('', String::hyphenate(''));
     $this->assertSame('-', String::hyphenate(' '));
     $this->assertSame('-', String::hyphenate('-'));
     $this->assertSame('1234567890', String::hyphenate('1234567890'));
     $this->assertSame('qwertyuiop', String::hyphenate('qwertyuiop'));
     $this->assertSame('qwertyuiop', String::hyphenate('QWERTYUIOP'));
     $this->assertSame('camel-case-string', String::hyphenate('CamelCaseString'));
     $this->assertSame('some-camel-case-string', String::hyphenate('someCamelCaseString'));
     $this->assertSame('a-hyphenated-string', String::hyphenate('a-hyphenated-string'));
     $this->assertSame('an-hyphenated-string', String::hyphenate('an-hyphenated-string'));
     $this->assertSame('a-string-with-spaces', String::hyphenate('a string with spaces'));
 }
コード例 #2
0
ファイル: Router.php プロジェクト: jjok/router
 /**
  * Find a defined Route based on the given query.
  * @param string $query
  * @return Route?
  */
 public function match($query)
 {
     #530600
     // 		#Exact match
     // 		if(array_key_exists($query, $this->routes)) {
     // 			echo 'Exact match';
     // 			return $this->routes[$query];
     // 		}
     foreach ($this->routes as $path => $route) {
         if (preg_match(sprintf('#^%s$#', $path), $query, $matches)) {
             // 				echo 'Preg match', PHP_EOL, $path, PHP_EOL;
             // 				print_r($matches);
             $route = clone $route;
             if (count($matches) > 1) {
                 # Remove the full match
                 array_shift($matches);
                 # Split up any grouped matches
                 $new_matches = array();
                 foreach ($matches as $match) {
                     foreach (explode('/', $match) as $param) {
                         $new_matches[] = $param;
                     }
                 }
                 $matches = $new_matches;
                 # Set controller, if null
                 if ($route->getController() == null) {
                     $route->setController(String::capitalise(array_shift($matches)));
                 }
                 # Set action, if null
                 if ($route->getAction() == null) {
                     # No more matches are available
                     if (count($matches) == 0) {
                         continue;
                     }
                     $route->setAction(String::camelise(array_shift($matches)));
                 }
                 # Merge any additional params
                 $route->setParams(array_merge($route->getParams(), $matches));
             }
             return $route;
         }
     }
     return null;
 }