Exemple #1
0
 /**
  * Parses the url in the elements controller, action and query.
  *
  * @param string $url
  *
  * @throws WrongParamCountException
  */
 public function parseUrl($url)
 {
     if ($url) {
         $controller = '';
         $controllerDirectories = $this->routes->getControllerDirectories();
         foreach ($controllerDirectories as $path => $target) {
             if (strpos($url, $path) === 0) {
                 $url = str_replace($path, '', $url);
                 $controller = $target;
             }
         }
         $urlArray = explode('/', ltrim($url, '/'));
         if (!$controller) {
             $controller = ClassHelper::toCamel(array_shift($urlArray), '/_|-/');
         }
         $this->controller = $controller;
         $this->action = ClassHelper::toCamel(array_shift($urlArray), '/_|-/', true);
         $c = count($urlArray);
         if ($c % 2 === 1) {
             throw new WrongParamCountException('Wrong count of query elements.');
         }
         while (count($urlArray) > 0) {
             $this->queryData[array_shift($urlArray)] = array_shift($urlArray);
         }
     }
 }
 /**
  * @param string $string
  * @param string $excepted
  * @dataProvider dataProviderAllCases
  */
 public function testDashAndSnakeToCamel($string, $excepted)
 {
     $this->assertEquals($excepted, ClassHelper::toCamel($string, '/-|_/'));
 }