The default page locator uses the following strategy to locate pages:
- uppercases the first letter of each word and joining them to a CamelCase like class name
- prepending configured namespaces defined via
page_namespace_prefix <configuration-options>
- returning first found class
<?php
...
$page_locator = new DefaultPageLocator(array('\\shop\\pages', '\\shop\\account\\pages'));
$page_class = $page_locator->resolvePage('Login Page');
$page = new $page_class($page_factory);
...
?>
Depending on existence either \shop\pages\LoginPage
or \shop\account\pages\LoginPage
will be returned.
In some cases it might be necessary to build a custom page locator. For example to map page names to specific classes.
examples/custom_page_locator.php
Now it is possible to either locate the page manually by its name:
<?php
...
$page_locator = new MappingPageLocator();
$registration_page_class = $page_locator->resolvePage('Registration Page');
$registration_page = new $registration_page_class($page_factory);
...
?>
or replace default locator with new one during PageFactory
construction time.
<?php
...
$container = new Container();
$container['page_locator'] = function () {
return new MappingPageLocator();
};
$page_factory = new PageFactory($session, $container);
$registration_page = $page_factory->getPage('Registration Page');
...
?>