Skip to content
Bob Magic II edited this page Aug 23, 2022 · 6 revisions

About the Configuration Object

This library uses a configuration object which you could build into your application as project-wide settings storage. If you're committing to a Nether based application then this is highly suggested.

// get a default config object if this is your first Nether lib.
$Config = Nether\Avenue\Library::PrepareDefaultConfig();

// if you wish to pass in your own and have the default settings applied.
$Config = new Nether\Object\Datastore;
Nether\Avenue\Library::PrepareDefaultConfig($Config);

Valid configuration values have constants which are defined on the Library class to help avoid typos that the IDE cannot assist with when just using the string keys.

public const
ConfRouteFile = 'Nether.Avenue.RouteFile',
ConfRouteRoot = 'Nether.Avenue.RouteRoot',
ConfWebRoot   = 'Nether.Avenue.WebRoot',
ConfDomainLvl = 'Nether.Avenue.DomainLvl',
ConfDomainSep = 'Nether.Avenue.DomainSep';
// if you trust you can read and type.
var_dump($Config['Nether.Avenue.RouteFile']);

// or tab bash ide autocomplete idk.
var_dump($Config[Nether\Avenue\Library::ConfRouteFile]);

Default Values

The default configuration values are set assuming the following example project structure.

MyProject/
	routes/
		Home.php

	www/
		index.php

	composer.json
	routes.phson

Nether.Avenue.RouteFile (Library::ConfRouteFile)

(string) '../routes.phson'

This points to the cached routing map file created by the vendor/bin/netherave gen command. If this file is not found the Router will fall back to a directory scan. This default RouteFile is relative to the index.php file. It accepts absolute paths too.

Nether.Avenue.RouteRoot (Library::ConfRouteRoot)

(string) '../routes'

This points to the directory that should be scanned to generate the routing map. The default RouteRoot is relative to the index.php file. It accepts absolute paths too.

Nether.Avenue.DomainLvl (Library::ConfDomainLvl)

(int) 2

This is how many domain segments will be considered by the route matching system. The default (2) means it will only consider "normal" domains. A Value of 3 would enable considering of subdomains as well.

Example DomainLvl = 2

$Router->Request->ParseRequest('GET', 'pegasusgate.net', '/');
var_dump($Router->Request->Domain);
// string(15) "pegasusgate.net"

$Router->Request->ParseRequest('GET', 'www.pegasusgate.net', '/');
var_dump($Router->Request->Domain);
// string(15) "pegasusgate.net"

$Router->Request->ParseRequest('GET', 'herp.derp.pegasusgate.net', '/');
var_dump($Router->Request->Domain);
// string(15) "pegasusgate.net"

Example DomainLvl = 3

$Router->Request->ParseRequest('GET', 'pegasusgate.net', '/');
var_dump($Router->Request->Domain);
// string(15) "pegasusgate.net"

$Router->Request->ParseRequest('GET', 'www.pegasusgate.net', '/');
var_dump($Router->Request->Domain);
// string(19) "www.pegasusgate.net"

$Router->Request->ParseRequest('GET', 'herp.derp.pegasusgate.net', '/');
var_dump($Router->Request->Domain);
// string(20) "derp.pegasusgate.net"