nepttune / router
Customizable router factory
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 1 077
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- hashids/hashids: ^3.0
- nette/application: ^3.0
README
🔧 Customizable router factory
Introduction
Premade router factory with some basic module configuration.
Dependencies
How to use
- Register
\Nepttune\RouterFactory
as service in cofiguration file. Dont forget to inject neon parameters. - Create router by calling
@routerFactory::createRouter
method. - You can configure factory to create subdomain or standard router
- Subdomain router uses following pattern
//<module>.%domain%/[<locale>/]<presenter>/<action>[/<id>]
. - Standard router uses following pattern
/[<locale>/]<module>/<presenter>/<action>[/<id>]
. - Standard router also craetes route without
<module>
section and in this case uses configured default module.
- Subdomain router uses following pattern
- Locale parameter is validated against
[a-z]{2}
pattern. - Id parameter is validated agains
\d+
pattern - or hashed to string ifhashids
is set to true.
Example configuration
services:
routerFactory:
class: Nepttune\RouterFactory
arguments:
- %router%
router: @routerFactory::createRouter
parameters:
router:
subdomain: false
apimodule: true
defaultModule: 'Www'
hashids: true
hashidsSalt: 'x7royUaK0g'
modules:
admin: Admin
Configuration Options
hashids
(bool) - whether router should ise Hashids to hide real id parametershashidsSalt
(string) - salt passed to hashids, make your hashes unique across multiple applicationshashidsCharset
(string) - charset passed to hashids, set of possible charactershashidsPadding
(int) - padding passed to hashids, min length of hashessubdomain
(bool) - whether router should make subdomain router
Following options apply only for standard router - when subdomain
option is false.
defaultModule
(string) - name of default module, when none is provided in urlapimodule
(bool) - whether router should create simple api route without parameters -/api/<presenter>/<action>
modules
(associative array) - list of routes to create - eg.admin: Admin
to create admin route in addition to generic route