Broadcast on Broadcast off
The Documentation for Project Zero has moved. Please update your bookmarks to: http://www.projectzero.org/documentation/
Table of
Contents...
Hide
 

Advanced concepts

This article outlines some advanced concepts that might be required in building robust secure applications using the Zero platform. The following sections introduce the approach taken in Project Zero to handle these concepts, but do not cover any of these topics in depth:

Security

The Zero platform provides basic security infrastructure to begin introducing security into your application. There is support for basic and form based authentication to file based and LDAP based registries. Authorization can be configured through the zero.config file. Security is discussed in depth in the Security section of the Core Developer's Guide.

Events

Events are fundamental to the Zero platform but are hidden to a certain extent in the scripting environment as each script is treated as an event handler. The PHP support in Zero allows you to create and fire events you define in the context of running a request using the fire_event() function.

User defined events have to be configured in the zero.config file with an event handler specified relative to the application's root directory. The following example declares the myevent event to be handled by the myeventhandler.php script in the public directory of the application.

config/zero.config

/config/handlers += [{
   "events" : "myevent",
   "handler" : "public/event/myeventhandler.php"
}]

In PHP, the event handler is a regular PHP script that uses the global context to share contextual information about the event with the invoker. The script below sets a value in the global context for use by the handler that fired the event.

public/myeventhandler.php

<?php
// Event Handler for "myevent"
$arr = array('foo' => 'bar');
put('/request/somekey', $arr);

?>

The following script illustrates firing the specified event with contextual information that can be accessed by the event handlers.

fireevent.php

<?php

// Fire a user defined event (myevent) from a php script. 
$eventctxt = array('otherctxt' => 'foobar');
fire_event('myevent', $eventctxt);

// Get a value stored by the event handler for verification
$arr = zget('/request/somekey');

zput('/request/headers/out/Content-Type', 'text/plain');
foreach($arr as $key => $value) {
        echo " $key $value";
}

?>

Views

Views are used in Zero to render data according to a specific template. There are some built in templates such as those for JSON and ATOM where the format of the data to be rendered are well know. Additionally it is possible to have user defined scripts that behave as templates for data to be rendered. The PHP support uses the render_view() function to render responses. Rendering responses is discussed in detail in this article in the core developer's guide.

-- madhu - 29 Jun 2007

r7 - 08 Feb 2008 - 11:25:38 - owenb
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site