Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 1.67 KB

howto.rst

File metadata and controls

63 lines (44 loc) · 1.67 KB

How-To

Using DefaultPageLocator

The default page locator uses the following strategy to locate pages:

  1. uppercases the first letter of each word and joining them to a CamelCase like class name
  2. prepending configured namespaces defined via page_namespace_prefix <configuration-options>
  3. 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.

Defining a custom locator

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');
...
?>