Inheritance: use trait Webiny\Component\StdLib\StdLibTrait
 /**
  * @dataProvider classNameToUrlProvider
  *
  * @param $class
  * @param $expected
  */
 public function testClassNameToUrl($class, $expected)
 {
     $this->assertSame($expected, PathTransformations::classNameToUrl($class, true));
     $classData = explode('\\', $class);
     $className = end($classData);
     if ($className == '\\') {
         $className = $class;
     }
     $this->assertSame($className, PathTransformations::classNameToUrl($class, false));
 }
Example #2
0
 /**
  * This method adds the default values for missing parameters and tries to do the match again.
  * Note: this works only with standard urls and not with resource naming
  *
  *
  * @param string $pattern Pattern that will be used for matching.
  * @param array  $data    An array holding the information about the parameters.
  * @param string $url     Url upon we will try to do the match.
  *
  * @return bool True is returned if $pattern matches $url, otherwise false.
  */
 private function tryMatchingOptionalParams($pattern, $data, $url)
 {
     // first we check if we have any default params
     $hasDefaultParams = false;
     foreach ($data['params'] as $p) {
         if (!is_null($p['default'])) {
             $hasDefaultParams = true;
         }
     }
     if (!$hasDefaultParams) {
         return false;
     }
     // get parameters that we already have in the url
     $methodUrlName = $data['method'];
     if ($this->normalize) {
         $methodUrlName = PathTransformations::methodNameToUrl($methodUrlName);
     }
     $urlParts = explode('/', $url);
     $numIncludedParams = count($urlParts) - (array_search($methodUrlName, $urlParts) + 2);
     $numAddedParams = 0;
     $requiredParamNum = count($data['params']);
     $loopIndex = 0;
     foreach ($data['params'] as $p) {
         if ($loopIndex >= $numIncludedParams) {
             if (!is_null($p['default'])) {
                 $url .= $p['default'] . '/';
                 $numAddedParams++;
             }
         }
         $loopIndex++;
     }
     if ($numIncludedParams + $numAddedParams != $requiredParamNum) {
         return false;
     }
     return $this->doesPatternMatch($pattern, $data, $url);
 }
Example #3
0
 /**
  * Builds the url match pattern for each of the method inside the api.
  *
  * @param string $methodName Method name.
  * @param array  $parameters List of the ParsedParameter instances.
  *
  * @return string The url pattern.
  */
 private function buildUrlPatternStandard($methodName, array $parameters)
 {
     $url = $methodName;
     if ($this->normalize) {
         $url = PathTransformations::methodNameToUrl($methodName);
     }
     foreach ($parameters as $p) {
         $matchType = $p->matchPattern;
         $url = $url . '/' . $matchType;
     }
     return $url . '/';
 }