## Class TPageService

Description

TPageService class.

TPageService implements the service for serving user page requests.

Pages that are available to client users are stored under a directory specified by BasePath. The directory may contain subdirectories. Pages serving for a similar goal are usually placed under the same directory. A directory may contain a configuration file config.xml whose content is similar to that of application configuration file.

A page is requested via page path, which is a dot-connected directory names appended by the page name. Assume '<BasePath>/Users/Admin' is the directory containing the page 'Update'. Then the page can be requested via 'Users.Admin.Update'. By default, the BasePath of the page service is the "pages" directory under the application base path. You may change this default by setting BasePath with a different path you prefer.

Page name refers to the file name (without extension) of the page template. In order to differentiate from the common control template files, the extension name of the page template files must be '.page'. If there is a PHP file with the same page name under the same directory as the template file, that file will be considered as the page class file and the file name is the page class name. If such a file is not found, the page class is assumed as TPage.

Modules can be configured and loaded in page directory configurations. Configuration of a module in a subdirectory will overwrite its parent directory's configuration, if both configurations refer to the same module.

By default, TPageService will automatically load two modules:

- TTemplateManager : manages page and control templates
- TThemeManager : manages themes used in a Prado application

In page directory configurations, static authorization rules can also be specified, which governs who and which roles can access particular pages. Refer to TAuthorizationRule for more details about authorization rules. Page authorization rules can be configured within an <authorization> tag in each page directory configuration as follows, <authorization> <deny pages="Update" users="?" /> <allow pages="Admin" roles="administrator" /> <deny pages="Admin" users="*" /> </authorization> where the 'pages' attribute may be filled with a sequence of comma-separated page IDs. If 'pages' attribute does not appear in a rule, the rule will be applied to all pages in this directory and all subdirectories (recursively). Application of authorization rules are in a bottom-up fashion, starting from the directory containing the requested page up to all parent directories. The first matching rule will be used. The last rule always allows all users accessing to any resources.

- since: 3.0
- version: $Id: TPageService.php 2737 2009-11-08 07:33:48Z godzilla80@gmx.net $
- author: Qiang Xue <qiang.xue@gmail.com>

Located in /Web/Services/TPageService.php (line 76)

    TComponent
       |
       --TApplicationComponent
          |
          --TService
             |
             --TPageService

Class Constant Summary
CONFIG_CACHE_PREFIX = 'prado:pageservice:'
CONFIG_FILE = 'config.xml'
DEFAULT_BASEPATH = 'pages'
PAGE_FILE_EXT = '.page'
Method Summary
void applyConfiguration (TPageConfiguration $config)
string constructUrl (string $pagePath, [array $getParams = null], [boolean $encodeAmpersand = true], [boolean $encodeGetItems = true])
TPage createPage (string $pagePath)
string determineRequestedPagePath ()
string getBasePageClass ()
string getBasePath ()
string getClientScriptManagerClass ()
string getDefaultPage ()
string getDefaultPageUrl ()
TPage getRequestedPage ()
string getRequestedPagePath ()
TTemplateManager getTemplateManager ()
TThemeManager getThemeManager ()
void init (TXmlElement $config)
void initPageContext (TPageConfiguration $pageConfig)
TPageConfiguration loadPageConfig (TXmlElement $config)
void run ()
void runPage (TPage $page, array $properties)
void setBasePageClass (string $value)
void setBasePath (string $value)
void setClientScriptManagerClass (string $value)
void setDefaultPage (string $value)
void setTemplateManager (TTemplateManager $value)
void setThemeManager (TThemeManager $value)
Methods
applyConfiguration (line 172)

Applies a page configuration.

- access: protected

void applyConfiguration (TPageConfiguration $config)

- TPageConfiguration $config: the configuration

constructUrl (line 509)

Constructs a URL with specified page path and GET parameters.

- return: URL for the page and GET parameters
- access: public

string constructUrl (string $pagePath, [array $getParams = null], [boolean $encodeAmpersand = true], [boolean $encodeGetItems = true])

- string $pagePath: page path
- array $getParams: list of GET parameters, null if no GET parameters required
- boolean $encodeAmpersand: whether to encode the ampersand in URL, defaults to true.
- boolean $encodeGetItems: whether to encode the GET parameters (their names and values), defaults to true.

createPage (line 454)

Creates a page instance based on requested page path.

- return: the requested page instance
- access: protected
- throws: THttpException if requested page path is invalid
- throws: TConfigurationException if the page class cannot be found

TPage createPage (string $pagePath)

- string $pagePath: requested page path

determineRequestedPagePath (line 200)

Determines the requested page path.

- return: page path requested
- access: protected

string determineRequestedPagePath ()
getBasePageClass (line 411)

- return: base page class name in namespace format. Defaults to 'TPage'.
- access: public

string getBasePageClass ()
getBasePath (line 373)

- return: the root directory for storing pages. Defaults to the 'pages' directory under the application base path.
- access: public

string getBasePath ()
getClientScriptManagerClass (line 430)

- return: clientscript manager class in namespace format. Defaults to 'System.Web.UI.TClientScriptManager'.
- access: public
- since: 3.1.7

string getClientScriptManagerClass ()
getDefaultPage (line 345)

- return: default page path to be served if no explicit page is request. Defaults to 'Home'.
- access: public

string getDefaultPage ()
getDefaultPageUrl (line 365)

- return: the URL for the default page
- access: public

string getDefaultPageUrl ()
getRequestedPage (line 337)

- return: the requested page
- access: public

TPage getRequestedPage ()
getRequestedPagePath (line 323)

- return: the requested page path
- access: public

string getRequestedPagePath ()
getTemplateManager (line 281)

- return: template manager
- access: public

TTemplateManager getTemplateManager ()
getThemeManager (line 302)

- return: theme manager
- access: public

TThemeManager getThemeManager ()
init (line 141)

Initializes the service.

This method is required by IService interface and is invoked by application.

- access: public

void init (TXmlElement $config)

- TXmlElement $config: service configuration

Redefinition of:

TService::init()
  Initializes the service and attaches run to the RunService event of application.

initPageContext (line 159)

Initializes page context.

Page context includes path alias settings, namespace usages, parameter initialization, module loadings, page initial properties and authorization rules.

- access: protected

void initPageContext (TPageConfiguration $pageConfig)

- TPageConfiguration $pageConfig

loadPageConfig (line 213)

Collects configuration for a page.

- access: protected

TPageConfiguration loadPageConfig (TXmlElement $config)

- TXmlElement $config: additional configuration specified in the application configuration

run (line 440)

Runs the service.

This will create the requested page, initializes it with the property values specified in the configuration, and executes the page.

- access: public

void run ()

Redefinition of:

TService::run()
  Runs the service.

runPage (line 494)

Executes a page.

- access: protected

void runPage (TPage $page, array $properties)

- TPage $page: the page instance to be run
- array $properties: list of initial page properties

setBasePageClass (line 403)

Sets the base page class name (in namespace format).

If a page only has a template file without page class file, this base page class will be instantiated.

- access: public

void setBasePageClass (string $value)

- string $value: class name

setBasePath (line 388)

- access: public
- throws: TInvalidOperationException if the service is initialized already or basepath is invalid

void setBasePath (string $value)

- string $value: root directory (in namespace form) storing pages

setClientScriptManagerClass (line 421)

Sets the clientscript manager class (in namespace format).

- access: public
- since: 3.1.7

void setClientScriptManagerClass (string $value)

- string $value: class name

setDefaultPage (line 354)

- access: public
- throws: TInvalidOperationException if the page service is initialized

void setDefaultPage (string $value)

- string $value: default page path to be served if no explicit page is request

setTemplateManager (line 294)

- access: public

void setTemplateManager (TTemplateManager $value)

- TTemplateManager $value: template manager

setThemeManager (line 315)

- access: public

void setThemeManager (TThemeManager $value)

- TThemeManager $value: theme manager

#### Inherited Methods

Inherited From TService

> TService::getEnabled()
> TService::getID()
> TService::init()
> TService::run()
> TService::setEnabled()
> TService::setID()

Inherited From TApplicationComponent

> TApplicationComponent::getApplication()
> TApplicationComponent::getRequest()
> TApplicationComponent::getResponse()
> TApplicationComponent::getService()
> TApplicationComponent::getSession()
> TApplicationComponent::getUser()
> TApplicationComponent::publishAsset()
> TApplicationComponent::publishFilePath()

Inherited From TComponent

> TComponent::addParsedObject()
> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> TComponent::createdOnTemplate()
> TComponent::detachEventHandler()
> TComponent::evaluateExpression()
> TComponent::evaluateStatements()
> TComponent::getEventHandlers()
> TComponent::getSubProperty()
> TComponent::hasEvent()
> TComponent::hasEventHandler()
> TComponent::hasProperty()
> TComponent::raiseEvent()
> TComponent::setSubProperty()
> TComponent::__get()
> TComponent::__set()

Class Constants
CONFIG_CACHE_PREFIX = 'prado:pageservice:' (line 89)

Prefix of ID used for storing parsed configuration in cache

CONFIG_FILE = 'config.xml' (line 81)

Configuration file name

DEFAULT_BASEPATH = 'pages' (line 85)

Default base path

PAGE_FILE_EXT = '.page' (line 93)

Page template file extension

Documentation generated on Mon, 22 Feb 2010 12:18:21 +0000 by phpDocumentor 1.3.0RC4