• 0
    Posted by bkrukowski 3 years ago

    Added support for converting parameters in new version (see example):

    <?php
    
    use Awesomite\Chariot\Pattern\PatternRouter;
    use Awesomite\Chariot\Pattern\Patterns;
    use Awesomite\Chariot\Pattern\StdPatterns\DatePattern;
    
    /*
     * Create router with default settings
     */
    $router = PatternRouter::createDefault();
    
    /*
     * Add new route
     */
    $router->get('/day/{{ day :date }}', 'showDay');
    
    $route = $router->match('GET', '/day/2017-01-01');
    /** @var \DateTimeImmutable $day */
    $day = $route->getParams()['day'];
    echo 'Day from URL: ', $day->format('Y-m-d'), "\n\n";
    /*
     * Output:
     *
     * Day from URL: 2017-01-01
     */
    
    echo $router->linkTo('showDay')->withParam('day', new \DateTime('2017-01-01')), "\n";
    /*
     * Output:
     *
     * /day/2017-01-01
     */