src/Path.php
public function bindRoute(string $templateDir)
    {
        $this->routeBindings = [];
        if (strlen($templateDir) === 0) return;

        // $dirsOrVars contains directories or variables like this: ['blog', '$year', '$month', '$day'].
        $dirsOrVars = explode('/', trim($templateDir, '/'));

        // $varValues contains values to be bound like ['blog', '2017', '12', '02', 'some-id']
        // it may be longer than $dirsOrVars as the last value in $varValues may be the resource ID or "index".
        $varValues = explode('/', trim($this->path, '/'));

        for ($i = 0; $i < count($dirsOrVars); $i++) {
            $dirOrVar = $dirsOrVars[$i];
            if ($dirOrVar[0] !== '$') continue; // Only bind variables like "$year", and ignore literals like "blog".

            $boundVar = substr($dirOrVar, 1); // Drop the dollar sign.

            // If this is matched with a file, it might look like "$page.twig", so we need to drop the extension.
            $extStart = strpos($boundVar, '.');
            if ($extStart !== false) {
                $boundVar = substr($boundVar, 0, $extStart);
            }

            $this->routeBindings[$boundVar] = $varValues[$i];
        }
    }
public function bindRoute(string $templateDir)
    {
        $this->routeBindings = [];
        if (strlen($templateDir) === 0) return;

        // $dirsOrVars contains directories or variables like this: ['blog', '$year', '$month', '$day'].
        $dirsOrVars = explode('/', trim($templateDir, '/'));

        // $varValues contains values to be bound like ['blog', '2017', '12', '02', 'some-id']
        // it may be longer than $dirsOrVars as the last value in $varValues may be the resource ID or "index".
        $varValues = explode('/', trim($this->path, '/'));

        for ($i = 0; $i < count($dirsOrVars); $i++) {
            $dirOrVar = $dirsOrVars[$i];
            if ($dirOrVar[0] !== '$') continue; // Only bind variables like "$year", and ignore literals like "blog".

            $boundVar = substr($dirOrVar, 1); // Drop the dollar sign.

            // If this is matched with a file, it might look like "$page.twig", so we need to drop the extension.
            $extStart = strpos($boundVar, '.');
            if ($extStart !== false) {
                $boundVar = substr($boundVar, 0, $extStart);
            }

            $this->routeBindings[$boundVar] = $varValues[$i];
        }
    }
public function bindRoute ( string $ templateDir ) { $ this -> routeBindings = [ ] ; if ( strlen ( $ templateDir ) === 0 ) return ; // $dirsOrVars contains directories or variables like this: ['blog', '$year', '$month', '$day']. $ dirsOrVars = explode ( '/' , trim ( $ templateDir , '/' ) ) ; // $varValues contains values to be bound like ['blog', '2017', '12', '02', 'some-id'] // it may be longer than $dirsOrVars as the last value in $varValues may be the resource ID or "index". $ varValues = explode ( '/' , trim ( $ this -> path , '/' ) ) ; for ( $ i = 0 ; $ i < count ( $ dirsOrVars ) ; $ i ++ ) { $ dirOrVar = $ dirsOrVars [ $ i ] ; if ( $ dirOrVar [ 0 ] !== '$' ) continue ; // Only bind variables like "$year", and ignore literals like "blog". $ boundVar = substr ( $ dirOrVar , 1 ) ; // Drop the dollar sign. // If this is matched with a file, it might look like "$page.twig", so we need to drop the extension. $ extStart = strpos ( $ boundVar , '.' ) ; if ( $ extStart !== false ) { $ boundVar = substr ( $ boundVar , 0 , $ extStart ) ; } $ this -> routeBindings [ $ boundVar ] = $ varValues [ $ i ] ; } }
Takes in a template directory and matches variables with values in the path.
Should not be called outside Babble core!

@param string $templateDir
Takes in a template directory and matches variables with values in the path . Should not be called outside Babble core!