PHP code example of codeeverything / junction

1. Go to this page and download the library: Download codeeverything/junction library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codeeverything / junction example snippets


// define the route
$this->router->add('GET /hello', function () {
    // just return a string for the application to then work on
    return 'Hello, world';
});

// ... more routes ...

// handle the request, matching routes if possible
$response = $this->router->handleRequest();

// define the route - with ello/:name', function ($name) {
    // just return a string for the application to then work on
    return 'Hello, ' . $name;
});

// ... more routes ...

// handle the request, matching routes if possible
$response = $this->router->handleRequest();

// define the route - with optional variable "name"
$this->router->add('GET /hello/:name?', function ($name) {
    // just return a string for the application to then work on
    $name = isset($name) ? $name : 'world';
    return 'Hello, ' . $name;
});

// ... more routes ...

// handle the request, matching routes if possible
$response = $this->router->handleRequest();

$this->router->add('GET /hello/:name', [
    'name' => [
        function ($value) {
            // only accept short names
            return strlen($value) < 5;
        },
    ],
], function ($name) {
    return 'Hello, ' . $name;
});