PHP code example of lumenpress / routing

1. Go to this page and download the library: Download lumenpress/routing 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/ */

    

lumenpress / routing example snippets


$app->register(LumenPress\Routing\ServiceProvider::class);

$router = app('wp.router');

use LumenPress\Routing\Facades\Route;

$router->is($condition, $callback);
$router->get($condition, $callback);
$router->post($condition, $callback);
$router->put($condition, $callback);
$router->patch($condition, $callback);
$router->delete($condition, $callback);
$router->options($condition, $callback);

$router->group([
        'middleware' => 'auth', 
        'namespace' => 'App\Http\Controllers'
    ], function ($router) {
        //
});

use LumenPress\Routing\Facades\Route;

Route::is($condition, $callback);
Route::get($condition, $callback);
Route::post($condition, $callback);
Route::put($condition, $callback);
Route::patch($condition, $callback);
Route::delete($condition, $callback);
Route::options($condition, $callback);

Route::group([
        'middleware' => 'auth', 
        'namespace' => 'App\Http\Controllers'
    ],function () {
    //
});

Route::is(string $condition, $callback);
Route::is([$condition => int|string|array $args], $callback);

// register templates
LumenPress\Nimble\Models\Post::registerTemplate([
    'home' => [
        'name' => 'Home Page'
    ],
    'contact' => [
        'name' => 'Contact Us'
    ],
    'about' => [
        'name' => 'Contact Us'
    ],
]);

Route::is(['template' => 'home'], function (\LumenPress\Nimble\Models\Post $post) {});

// Multiple
Route::is(['template' => 'contact', 'about'], $callback);

// page.php
Route::is('page', function (\LumenPress\Nimble\Models\Post $post) {});

// page-2.php
Route::is(['page' => 2], $callback);

// page-sample-page.php
Route::is(['page' => 'sample-page'], $callback);

// page-about.php or page-contact.php
Route::is(['page' => ['about', 'contact']], $callback);

// By path
Route::is(['page' => 'about/company'], $callback);
Route::is(['page' => 'about/staff'], $callback);

// single.php
Route::is('single', function (\LumenPress\Nimble\Models\Post $post) {});

// query by post id
Route::is(['single' => 1], $callback);

// single-book.php
Route::is(['single' => 'book'], $callback);

// single-book.php or single-newspaper.php
Route::is(['single' => ['book', 'newspaper']], $callback);

// single-book-foo.php 
// or single-book-bar.php 
// or single-newspaper-foo.php 
// or single-newspaper-bar.php
$single = [
    // $post_type,  $slug
    ['book',        'foo'],
    ['book',        'bar'],
    ['newspaper',   'foo'],
    ['newspaper',   'bar'],
];
Route::is(['single' => $single], $callback);

// singular.php
Route::is('singular', function (\LumenPress\Nimble\Models\Page $post) {});

// single-book.php
Route::is(['singular' => 'book'], $callback);

// single-book.php or single-newspaper.php
Route::is(['singular' => ['newspaper', 'book']], $callback);

// attachment.php
Route::is('attachment', $callback);

// embed.php
Route::is('embed', function (LumenPress\Nimble\Models\Post $post) {});

// archive.php
Route::is('archive', $callback);

// archive-book.php
Route::is(['archive' => 'book'], $callback);

// archive-newspaper.php or archive-book.php
Route::is(['archive' => ['newspaper', 'book']], function ($postType) {});

// taxonomy.php
Route::is('tax', function (\LumenPress\Nimble\Models\Taxonomy $taxonomy) {});

// taxonomy-channel.php
Route::is(['tax' => 'channel'], $callback);

// taxonomy-channel-bbc1.php
Route::is(['tax' => [['channel', 'bbc1']]], $callback);

// category.php
Route::is('category', function (\LumenPress\Nimble\Models\Category $category) {});

// category-9.php
Route::is(['category' => 9], $callback);

// category-news.php
Route::is(['category' => 'news'], $callback);

// by category name
Route::is(['category' => 'Stinky Cheeses'], $callback);

// by id, slug, name...
Route::is(['category' => [9, 'blue-cheese', 'Stinky Cheeses']], $callback);

// tag.php
Route::is('tag', function (\LumenPress\Nimble\Models\Tag $tag) {});

// tag-30.php
Route::is(['tag' => 30], $callback);

// tag-extreme.php
Route::is(['tag' => 'extreme'], $callback);
// tag-mild.php
Route::is(['tag' => 'mild'], $callback);

// by id, slug, name...
Route::is(['tag' => [30, 'mild', 'extreme']], $callback);

// author.php
Route::is('author', function (\LumenPress\Nimble\Models\User $user) {});

// author-4.php
Route::is(['author' => 4], $callback);

// author-john-jones.php
Route::is(['author' => 'john-jones'], $callback);

// by display name
Route::is(['author' => 'Vivian'], $callback);

// by mixed
Route::is(['author' => [4, 'john-jones', 'Vivian']], $callback);

// date.php
Route::is('date', function ($year = null, $month = null, $day = null) {});

// home.php
Route::is('home', $callback);

// front_page.php
Route::is('front', $callback);

// search.php
Route::is('search', $callback);

// 404.php
Route::is('404', $callback);

Route::registerCondition('author.role', function ($role) {
    if (! is_author()) {
        return false;
    }

    $author = get_queried_object();

    return $role == $author->roles[0];
});

Route::is(['author.role' => 'administrator'], $callback);