private function constructInternalRegularExpression($path, $routePattern)
    {
        if (empty($routePattern)) return false;

        $fullRoute = $path;

        if (substr($fullRoute, -1) == '/') {
            $fullRoute = substr($fullRoute, 0, -1);
        }

        $fullRoute .= $routePattern;

        $patternSegments = $this->urlSegmentsFromPath($fullRoute);

        $variableNumber = 0;
        $hasOptional = false;
        $lastSegmentRequired = true;

        foreach ($patternSegments as $pattern) {
            $variableNumber++;

            $isOptionalPattern = $this->stringIsWrapped($pattern, '[', ']');
            $isDynamicPattern = $this->stringIsWrapped($pattern, '{', '}');

            if (!$isDynamicPattern) {
                $validatorClass = new \Slab\Router\Validators\Value(); //@todo findClass

                $validatorClass->setChallenge($pattern);

                if ($isOptionalPattern)
                {
                    // Can't have optional value validators
                    //$validatorClass->setOptional(true);
                }
                else
                {
                    $this->requiredSegments++;
                }

                $this->validations[] = $validatorClass;

                continue;
            }

            if (!$isOptionalPattern && $hasOptional)
            {
                throw new \Exception("Route " . $path . " has required fields after optional fields.");
            }

            list($validatorClass, $variableName) = explode(':', $pattern);

            if ($validatorClass[0] != '\\')
            {
                $validatorClass = ucfirst($validatorClass);

                if (strcasecmp($validatorClass, 'String') == 0)
                {
                    $validatorClass = 'Text';
                }

                $validatorClassName = '\Slab\Router\Validators\\' . $validatorClass;
            }
            else
            {
                $validatorClassName = $validatorClass;
            }

            if (!class_exists($validatorClassName))
            {
                throw new \Exception("Route " . $path . " specified invalid validator class " . $validatorClass);
            }


            $validatorClass = new $validatorClassName;

            if (!$validatorClass instanceof \Slab\Router\Validators\ValidatorInterface)
            {
                throw new \Exception("Validator " . $validatorClass . " does not explicitly implement interface \Slab\Router\Validators\ValidatorInterface");
            }

            $this->validations[] = $validatorClass;

            $this->variableMapping[$variableNumber] = $variableName;

            if (!$isOptionalPattern)
            {
                ++$this->requiredSegments;
            }
        }

        return true;
    }
private function constructInternalRegularExpression($path, $routePattern)
    {
        if (empty($routePattern)) return false;

        $fullRoute = $path;

        if (substr($fullRoute, -1) == '/') {
            $fullRoute = substr($fullRoute, 0, -1);
        }

        $fullRoute .= $routePattern;

        $patternSegments = $this->urlSegmentsFromPath($fullRoute);

        $variableNumber = 0;
        $hasOptional = false;
        $lastSegmentRequired = true;

        foreach ($patternSegments as $pattern) {
            $variableNumber++;

            $isOptionalPattern = $this->stringIsWrapped($pattern, '[', ']');
            $isDynamicPattern = $this->stringIsWrapped($pattern, '{', '}');

            if (!$isDynamicPattern) {
                $validatorClass = new \Slab\Router\Validators\Value(); //@todo findClass

                $validatorClass->setChallenge($pattern);

                if ($isOptionalPattern)
                {
                    // Can't have optional value validators
                    //$validatorClass->setOptional(true);
                }
                else
                {
                    $this->requiredSegments++;
                }

                $this->validations[] = $validatorClass;

                continue;
            }

            if (!$isOptionalPattern && $hasOptional)
            {
                throw new \Exception("Route " . $path . " has required fields after optional fields.");
            }

            list($validatorClass, $variableName) = explode(':', $pattern);

            if ($validatorClass[0] != '\\')
            {
                $validatorClass = ucfirst($validatorClass);

                if (strcasecmp($validatorClass, 'String') == 0)
                {
                    $validatorClass = 'Text';
                }

                $validatorClassName = '\Slab\Router\Validators\\' . $validatorClass;
            }
            else
            {
                $validatorClassName = $validatorClass;
            }

            if (!class_exists($validatorClassName))
            {
                throw new \Exception("Route " . $path . " specified invalid validator class " . $validatorClass);
            }


            $validatorClass = new $validatorClassName;

            if (!$validatorClass instanceof \Slab\Router\Validators\ValidatorInterface)
            {
                throw new \Exception("Validator " . $validatorClass . " does not explicitly implement interface \Slab\Router\Validators\ValidatorInterface");
            }

            $this->validations[] = $validatorClass;

            $this->variableMapping[$variableNumber] = $variableName;

            if (!$isOptionalPattern)
            {
                ++$this->requiredSegments;
            }
        }

        return true;
    }
private function constructInternalRegularExpression ( $ path , $ routePattern ) { if ( empty ( $ routePattern ) ) return false ; $ fullRoute = $ path ; if ( substr ( $ fullRoute , - 1 ) == '/' ) { $ fullRoute = substr ( $ fullRoute , 0 , - 1 ) ; } $ fullRoute .= $ routePattern ; $ patternSegments = $ this -> urlSegmentsFromPath ( $ fullRoute ) ; $ variableNumber = 0 ; $ hasOptional = false ; $ lastSegmentRequired = true ; foreach ( $ patternSegments as $ pattern ) { $ variableNumber ++ ; $ isOptionalPattern = $ this -> stringIsWrapped ( $ pattern , '[' , ']' ) ; $ isDynamicPattern = $ this -> stringIsWrapped ( $ pattern , '{' , '}' ) ; if ( ! $ isDynamicPattern ) { $ validatorClass = new \ Slab \ Router \ Validators \ Value ( ) ; //@todo findClass $ validatorClass -> setChallenge ( $ pattern ) ; if ( $ isOptionalPattern ) { // Can't have optional value validators //$validatorClass->setOptional(true); } else { $ this -> requiredSegments ++ ; } $ this -> validations [ ] = $ validatorClass ; continue ; } if ( ! $ isOptionalPattern && $ hasOptional ) { throw new \ Exception ( "Route " . $ path . " has required fields after optional fields." ) ; } list ( $ validatorClass , $ variableName ) = explode ( ':' , $ pattern ) ; if ( $ validatorClass [ 0 ] != '\\' ) { $ validatorClass = ucfirst ( $ validatorClass ) ; if ( strcasecmp ( $ validatorClass , 'String' ) == 0 ) { $ validatorClass = 'Text' ; } $ validatorClassName = '\Slab\Router\Validators\\' . $ validatorClass ; } else { $ validatorClassName = $ validatorClass ; } if ( ! class_exists ( $ validatorClassName ) ) { throw new \ Exception ( "Route " . $ path . " specified invalid validator class " . $ validatorClass ) ; } $ validatorClass = new $ validatorClassName ; if ( ! $ validatorClass instanceof \ Slab \ Router \ Validators \ ValidatorInterface ) { throw new \ Exception ( "Validator " . $ validatorClass . " does not explicitly implement interface \Slab\Router\Validators\ValidatorInterface" ) ; } $ this -> validations [ ] = $ validatorClass ; $ this -> variableMapping [ $ variableNumber ] = $ variableName ; if ( ! $ isOptionalPattern ) { ++ $ this -> requiredSegments ; } } return true ; }
Construct the internal pattern to test the urls against

@param string $path
@param string $routePattern
@return boolean
@throws \Exception
Construct the internal pattern to test the urls against