src/Comodojo/Dispatcher/Router/Parser.php
public function read($folders = array(), Route $value = null, $regex = '') {

        if (is_null($value)) {

            $value = new Route();

        }

        // if the first 'folder' is empty is removed
        while (!empty($folders) && empty($folders[0])) {

            array_shift($folders);

        }

        // if the 'folder' array is empty, the route has been fully analyzed
        // this is the exit condition from the recursive loop.
        if (empty($folders)) {

            return '^'.$regex.'[\/]?$';

        } else {

            // The first element of the array 'folders' is taken in order to be analyzed
            $folder  = array_shift($folders);

            // All the parameters of the route must be json strings
            $decoded = json_decode($folder, true);

            if (!is_null($decoded) && is_array($decoded)) {

                $param_regex = '';

                $param_required = false;

                /* All the folders can include more than one parameter
                 * Eg: /service_name/{'param1': 'regex1', 'param2': 'regex2'}/
                 *     /calendar/{'ux_timestamp*': '\d{10}', 'microseconds': '\d{4}'}/
                 *
                 * The '*' at the end of the paramerter name implies that the parameter is required
                 * This example can be read as a calendar service that accepts both
                 * timestamps in unix or javascript format.
                 *
                 * This is the reason of the following 'foreach'
                 */
                foreach ($decoded as $key => $string) {

                    $this->logger->debug("Route parser - parameter key: $key");

                    $this->logger->debug("Route parser - parameter string: $string");

                    /* The key and the regex of every paramater is passed to the 'param'
                     * method which will build an appropriate regular expression and will understand
                     * if the parameter is required and will build the Route query object
                     */
                    $param_regex .= $this->param($key, $string, $value);

                    if ($value->isQueryRequired($key)) {
                        $param_required = true;
                    }

                    $this->logger->debug("Route parser - parameter regex: $param_regex");

                }
                // Once the parameter is analyzed, the result is passed to the next iteration
                return $this->read(
                    $folders,
                    $value,
                    $regex.'(?:\/'.$param_regex.')'.(($param_required) ? '{1}' : '?')
                );

            } else {
                // if the element is not a json string, I assume it's the service name
                $value->addService($folder);

                return $this->read(
                    $folders,
                    $value,
                    $regex.'\/'.$folder
                );

            }

        }

    }
public function read($folders = array(), Route $value = null, $regex = '') {

        if (is_null($value)) {

            $value = new Route();

        }

        // if the first 'folder' is empty is removed
        while (!empty($folders) && empty($folders[0])) {

            array_shift($folders);

        }

        // if the 'folder' array is empty, the route has been fully analyzed
        // this is the exit condition from the recursive loop.
        if (empty($folders)) {

            return '^'.$regex.'[\/]?$';

        } else {

            // The first element of the array 'folders' is taken in order to be analyzed
            $folder  = array_shift($folders);

            // All the parameters of the route must be json strings
            $decoded = json_decode($folder, true);

            if (!is_null($decoded) && is_array($decoded)) {

                $param_regex = '';

                $param_required = false;

                /* All the folders can include more than one parameter
                 * Eg: /service_name/{'param1': 'regex1', 'param2': 'regex2'}/
                 *     /calendar/{'ux_timestamp*': '\d{10}', 'microseconds': '\d{4}'}/
                 *
                 * The '*' at the end of the paramerter name implies that the parameter is required
                 * This example can be read as a calendar service that accepts both
                 * timestamps in unix or javascript format.
                 *
                 * This is the reason of the following 'foreach'
                 */
                foreach ($decoded as $key => $string) {

                    $this->logger->debug("Route parser - parameter key: $key");

                    $this->logger->debug("Route parser - parameter string: $string");

                    /* The key and the regex of every paramater is passed to the 'param'
                     * method which will build an appropriate regular expression and will understand
                     * if the parameter is required and will build the Route query object
                     */
                    $param_regex .= $this->param($key, $string, $value);

                    if ($value->isQueryRequired($key)) {
                        $param_required = true;
                    }

                    $this->logger->debug("Route parser - parameter regex: $param_regex");

                }
                // Once the parameter is analyzed, the result is passed to the next iteration
                return $this->read(
                    $folders,
                    $value,
                    $regex.'(?:\/'.$param_regex.')'.(($param_required) ? '{1}' : '?')
                );

            } else {
                // if the element is not a json string, I assume it's the service name
                $value->addService($folder);

                return $this->read(
                    $folders,
                    $value,
                    $regex.'\/'.$folder
                );

            }

        }

    }
public function read ( $ folders = array ( ) , Route $ value = null , $ regex = '' ) { if ( is_null ( $ value ) ) { $ value = new Route ( ) ; } // if the first 'folder' is empty is removed while ( ! empty ( $ folders ) && empty ( $ folders [ 0 ] ) ) { array_shift ( $ folders ) ; } // if the 'folder' array is empty, the route has been fully analyzed // this is the exit condition from the recursive loop. if ( empty ( $ folders ) ) { return '^' . $ regex . '[\/]?$' ; } else { // The first element of the array 'folders' is taken in order to be analyzed $ folder = array_shift ( $ folders ) ; // All the parameters of the route must be json strings $ decoded = json_decode ( $ folder , true ) ; if ( ! is_null ( $ decoded ) && is_array ( $ decoded ) ) { $ param_regex = '' ; $ param_required = false ; /* All the folders can include more than one parameter
                 * Eg: /service_name/{'param1': 'regex1', 'param2': 'regex2'}/
                 *     /calendar/{'ux_timestamp*': '\d{10}', 'microseconds': '\d{4}'}/
                 *
                 * The '*' at the end of the paramerter name implies that the parameter is required
                 * This example can be read as a calendar service that accepts both
                 * timestamps in unix or javascript format.
                 *
                 * This is the reason of the following 'foreach'
                 */ foreach ( $ decoded as $ key => $ string ) { $ this -> logger -> debug ( "Route parser - parameter key: $key" ) ; $ this -> logger -> debug ( "Route parser - parameter string: $string" ) ; /* The key and the regex of every paramater is passed to the 'param'
                     * method which will build an appropriate regular expression and will understand
                     * if the parameter is required and will build the Route query object
                     */ $ param_regex .= $ this -> param ( $ key , $ string , $ value ) ; if ( $ value -> isQueryRequired ( $ key ) ) { $ param_required = true ; } $ this -> logger -> debug ( "Route parser - parameter regex: $param_regex" ) ; } // Once the parameter is analyzed, the result is passed to the next iteration return $ this -> read ( $ folders , $ value , $ regex . '(?:\/' . $ param_regex . ')' . ( ( $ param_required ) ? '{1}' : '?' ) ) ; } else { // if the element is not a json string, I assume it's the service name $ value -> addService ( $ folder ) ; return $ this -> read ( $ folders , $ value , $ regex . '\/' . $ folder ) ; } } }
the global regular expression against which all the request URI will be compared
the global regular expression against which all the request URI will be compared