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:
Emmanuel BENOîT 2012-02-05 17:59:12 +01:00
parent dd87433f82
commit c5e30e4cc3
2 changed files with 49 additions and 0 deletions

View 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;
}
}

View file

@ -0,0 +1,4 @@
<?
$package[ 'files' ][] = 'hub-page';
$package[ 'extras' ][] = 'HubPage';