2017 © Pedro Peláez
 

library router

Router

image

webchemistry/router

Router

  • Wednesday, July 11, 2018
  • by Antik
  • Repository
  • 1 Watchers
  • 1 Stars
  • 195 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 4 % Grown

The README.md

WebChemistry/router

Overview

Installation

Install via composer., (*1)

composer require webchemistry/router

neon:, (*2)

extensions:
    routers: WebChemistry\Routing\DI\RouterExtension

Configuration

routers:
    modules:
        - Front
        - Admin
    routers:
        - App\MainRouter
        - YourRouter
        - HisRouter

Main router

<?php

namespace App

class MainRouter implements WebChemistry\Routing\IRouter {

    /**
     * @param RouteManager $routeManager
     */
    public function createRouter(RouteManager $routeManager) {
        $routeManager->addStyle('name');
        $routeManager->setStyleProperty('name', Route::FILTER_OUT, function($url) {
            return Strings::webalize($url);
        });
        $routeManager->setStyleProperty('name', Route::FILTER_IN, function($url) {
            return Strings::webalize($url);
        });

        // Admin
        $admin = $routeManager->getModule('Admin');
        $admin[] = new Route('admin/<presenter>[/<action>][/<id [0-9]+>[-<name [0-9a-zA-Z\-]+>]]', [
            'presenter' => 'Homepage',
            'action' => 'default',
        ]);

        // Front
        $front = $routeManager->getModule('Front');
        $front[] = new Route('<presenter>[/<action>][/<id [0-9]+>[-<name [0-9a-zA-Z\-]+>]]', [
            'presenter' => 'Homepage',
            'action' => 'default',
        ]);
    }

}

Usage autoregistration in own extension

<?php

namespace TestPackage\Test\DI;

use Nette\Application\IPresenterFactory;
use Nette\DI\CompilerExtension;

class TestExtension extends CompilerExtension
{


    public function loadConfiguration()
    {
        $builder = $this->getContainerBuilder();

        $builder->addDefinition($this->prefix('routers'))
            ->addTag('router')
            ->setFactory(\TestPackage\Test\TestRouter::class)
            ->setAutowired(true);

        $builder->getDefinition('routers.routerManager')
            ->addSetup('createModule', ['Test']);
    }

    public function beforeCompile()
    {
        $builder = $this->getContainerBuilder();

        $builder->getDefinition($builder->getByType(IPresenterFactory::class))
            ->addSetup(
                'setMapping',
                [['Test' => 'TestPackage\Test\Presenters\*Presenter']]
        );
    }
}
<?php

namespace TestPackage\Test;

use WebChemistry\Routing\IRouter;
use WebChemistry\Routing\RouteManager;
use Nette\Application\Routers\Route;

class TestRouter implements IRouter
{

    /**
     * @param RouteManager $routeManager
     */
    public function createRouter(RouteManager $routeManager): void
    {
        $app = $routeManager->getModule('Test');
        $app[] = new Route('/test/<presenter>/<action>[/<id>]', 'Default:default');
    }
}

app/config.neon:, (*3)

extensions:

    ...
    - TestPackage\Test\DI\TestExtension
    ...

For correct router orders, you have to list all routers in app/config.neon:, (*4)

extensions:
    ...
    routers: WebChemistry\Routing\DI\RouterExtension
    - TestPackage\Test\DI\TestExtension
    ...

routers:
    modules:
        ...
        - Test
        ...
        - App
    routers:
        ...
        - App\MainRouter

The Versions

11/07 2018

dev-master

9999999-dev

Router

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Avatar Antik

router webchemistry

17/06 2017

v2.0.1

2.0.1.0

Router

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Avatar Antik

router webchemistry

08/06 2017

2.0

2.0.0.0

Router

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Avatar Antik

router webchemistry

31/07 2016

1.0.1

1.0.1.0

Router

  Sources   Download

GPL-3.0

by Avatar Antik

router webchemistry

04/02 2016

1.0

1.0.0.0

Router

  Sources   Download

GPL-3.0

by Avatar Antik

router webchemistry