Added "hub page" package
This package provides the HubPage class which can be used to create pages that act as URL mappers.
This commit is contained in:
parent
dd87433f82
commit
c5e30e4cc3
2 changed files with 49 additions and 0 deletions
45
includes/hub-page/hub-page.inc.php
Normal file
45
includes/hub-page/hub-page.inc.php
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class HubPage
|
||||||
|
extends HTMLPage
|
||||||
|
implements PathAware
|
||||||
|
{
|
||||||
|
private static $pages;
|
||||||
|
|
||||||
|
public function __construct( $pages )
|
||||||
|
{
|
||||||
|
parent::__construct( );
|
||||||
|
$this->pages = $pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function setExtraPath( $extraPath )
|
||||||
|
{
|
||||||
|
if ( !is_array( $this->pages ) || ! array_key_exists( $extraPath , $this->pages ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$handler = $this->pages[ $extraPath ];
|
||||||
|
if ( ! is_array( $handler ) ) {
|
||||||
|
$handler = array( $handler );
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$toAdd = Loader::DirectCreate( 'ctrl' , true , $handler );
|
||||||
|
$this->addController( $toAdd );
|
||||||
|
} catch ( LoaderException $e ) {
|
||||||
|
try {
|
||||||
|
$toAdd = Loader::DirectCreate( 'view' , true , $handler );
|
||||||
|
$this->addView( $toAdd );
|
||||||
|
} catch ( LoaderException $e ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $toAdd instanceof TitleProvider ) {
|
||||||
|
$this->setTitle( $toAdd->getTitle( ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
4
includes/hub-page/package.inc.php
Normal file
4
includes/hub-page/package.inc.php
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?
|
||||||
|
|
||||||
|
$package[ 'files' ][] = 'hub-page';
|
||||||
|
$package[ 'extras' ][] = 'HubPage';
|
Loading…
Reference in a new issue