Welcome dear user!

Pampoo is a lightweight php Model-View-Controller (aka MVC) framework.

Pampoo allows you to create complex, robust, fully-featured web applications easily and rapidly using the Model-View-Controller (MVC) design pattern. This open-source framework performs the common, tedious tasks of parsing web requests, handling session data, and assembling HTTP output, so you can focus on business logic and presentation elements specific to your project. Thanks to the modularity of the MVC design pattern, your code will also be well-organized and easier for you and others to understand and maintain.

Before you can take full advantage of Pampoo, you should be familiar with the following:

  • Programming with PHP
  • Model-View-Controller (MVC) design pattern for Web applications
  • XSL Transformations (XSLT) Version 1.0

Pampoo 2.0.1 released

Version 2.0.1!

A new version of Pampoo was released. Current stable version is 2.0.1. 

This release includes a major update to avoid use of .htaccess file. Idea was taken from dan.thoughts as http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/ 

Another improvement concerns operations flow: the sitemap is loaded in memory an shared are added to chosen command. Default command for no matching pattern is defined in sitemap. This a valid sample sitemap:  
<?xml version="1.0" encoding="utf-8"?>
<sitemap>

<configs>
	<config name="defaultcommand">home</config>
</configs>
	
<includes>
	<!-- View included in all commands -->
	<views>
		<view name="INTERNAL_REDIRECT" type="handler"  
                           command="Frontend_Handlers_Redirect/RedirectTo" />
		<view name="ERROR" type="static"  page="views/static/error.html" />	
	</views>
</includes>

<commands> 

	<command id="auth" pattern="login">
		<controller value="Frontend_BLL_Auth"/>
	</command>
	
	<command id="admin" pattern="admin">
		<controller value="Frontend_BLL_Admin"/>
		<view name="SUCCESS" type="trasformation">
			<trasform>views/xslt/admin.xsl</trasform>
		</view>
	</command>

	<command id="home" pattern="home">
		<controller value="Frontend_BLL_Home"/>
		<view name="SUCCESS" type="trasformation">
			<trasform>views/xslt/home.xsl</trasform>
		</view>
		<view name="DWOO" type="dwoo">
			<trasform>views/php/home.tpl</trasform>
		</view>
	</command>

	<command id="post" pattern="post/:id/:title">
		<condition key="id" value="[\d]{1,9}" />
		<condition key="title" value="[\w]*" />
		<controller value="Frontend_BLL_Post"/>
		<view name="SUCCESS" type="trasformation">
			<trasform>views/xslt/post.xsl</trasform>
		</view>
	</command>

	<command id="page" pattern="page/:id/:title">
		<condition key="id" value="[\d]{1,9}" />
		<condition key="title" value="[\w]+(\.html)" />
		<controller value="Frontend_BLL_Post"/>
		<view name="SUCCESS" type="trasformation">
			<trasform>views/xslt/post.xsl</trasform>
		</view>
	</command>
	
	<command id="tag" pattern="tag/:id/:title">
		<condition key="id" value="[\d]{1,9}" />
		<condition key="title" value="[\w]*" />
		<controller value="Frontend_BLL_Tag"/>
		<view name="SUCCESS" type="trasformation">
			<trasform>views/xslt/tag.xsl</trasform>
		</view>
	</command>
		
	<command id="ajaxservices" pattern="services/:class/:method">
		<condition key="class" value="[\w]*" />
		<condition key="method" value="[\w]*" />
		<controller value="Frontend_BLL_Ajax"/>
		<view name="SUCCESS" type="json"/>
	</command>
		
</commands>

</sitemap>
This application sitemap refers to Pampoo web site here at http://pampoo.sf.net
GOF Patterns
Pampoo make intensive use of GOF (Gang of Four) patterns. Pampoo makes available to overlying projects three of those patterns to help you integrate these practices without reinventing the wheel. More informations here

Command chain

Building on the loose-coupling theme, the chain-of-command pattern routes a message, command, request, or whatever you like through a set of handlers. Each handler decides for itself whether it can handle the request. If it can, the request is handled, and the process stops. You can add or remove handlers from the system without influencing other handlers
class Pampoo_GOF_CommandChain
{
  private $_commands = array();

  public function addCommand( Pampoo_GOF_ICommand $cmd )
  {
    $this->_commands []= $cmd;
  }

  public function runCommand( $name, $args )
  {
    foreach( $this->_commands as $cmd )
    {
      if ( $cmd->onCommand( $name, $args ) )
        return;
    }
  }
}

interface Pampoo_GOF_ICommand
{
  function onCommand( $name, $args );
}

This is a sample of use of that pattern taken from the static method Run inside the main Pampoo class (Pampoo.php):
$ap = new Pampoo_Framework_Application(self::$sitemap, $ErrorObserver);
$cc = new Pampoo_GOF_CommandChain();

$cc->addCommand( new Pampoo_Framework_Command_UrlParseCommand($Observers) );
$cc->addCommand( new Pampoo_Framework_Command_ActionCommand($Observers) );
$cc->addCommand( new Pampoo_Framework_Command_BLLCommand($Observers) );
$cc->addCommand( new Pampoo_Framework_Command_DataCommand($Observers) );

$cc->runCommand( 'urlparse', $ap );
$cc->runCommand( 'action', $ap );
$cc->runCommand( 'bll', $ap );
$cc->runCommand( 'data', $ap );

Observer

The observer pattern gives you another way to avoid tight coupling between components. This pattern is simple: One object makes itself observable by adding a method that allows another object, the observer, to register itself. When the observable object changes, it sends a message to the registered observers. What those observers do with that information isn't relevant or important to the observable object. The result is a way for objects to talk with each other without necessarily understanding why.
interface Pampoo_GOF_IObservable
{
  function addObserver( $observer );
}

interface Pampoo_GOF_IObserver
{
  function onChanged( Pampoo_GOF_IObservable $sender, $type, $args );
}

abstract class Pampoo_GOF_AbstractObservable implements Pampoo_GOF_IObservable
{
    protected $_observers = array();	
	
	public function fireEvent( $type, $name )
	{
		foreach( $this->_observers as $obs )
			$obs->onChanged( $this, $type, $name );
	}

	public function addObserver( $observer )
	{
		$this->_observers []= $observer;
	}
}

Singleton

Some application resources are exclusive in that there is one and only one of this type of resource.
abstract class Pampoo_GOF_Singleton {
 
    protected function __Construct() { }
 
    private function __Clone() { }
 
    static public function getInstance($ClassName = null) {
        static $Instance;
   
        if ($Instance) 
            return $Instance;
        elseif ($ClassName)
            {
            $Instance = new $ClassName;
            return $Instance;
            }
        else 
            return null;
    } 
}
Dwoo as template engine
What is Dwoo?
Dwoo is a PHP5 template engine which is (almost) fully compatible with Smarty templates and plugins, but is written from scratch for PHP5, and adds many features. --Taken from dwoo.org--

You can use php templates in your Pampoo powered application. This is an example action containing a view that will use dwoo template engine:
<action id="home">
	<controller value="Controllers_Home"/>
	<view name="SUCCESS" type="dwoo">
		<trasform>Views/Home.tpl</trasform>
	</view>
</action>

Dwoo is very powerful and has many features including:
  • Template Inheritance, a fresh look at complex template structures, now built without includes
  • Sub-template declaration within templates to allow recursive templates.
  • Smarty syntax compatibility with several additions and shortcuts to speed up template writing
  • Flexible plugin creation, plugins can be wrapped in classes or simple functions, they can be precompiled to optimize the load time of the template, etc.
  • Scope aware engine, allowing for shorter templates
  • Unicode / UTF-8 support for string manipulation functions.
  • Generally faster than Smarty with variable speed improvements depending on the features used.
  • E_STRICT compliant code that does not throw PHP warnings.
First use
To install pampoo you need the following requirements:
php 5.2 or later 

Pampoo is designed to divide application classes and well manage code update. It requires a sitemap to decide how to route web request and some classes called controllers to handle those requests

This is  a sample  sitemap file:
<?xml version="1.0" encoding="utf-8"?>
<config>
<actions> 
	<action id="home">
		<controller value="Controllers_Home"/>
		<view name="SUCCESS" type="trasformation">
			<trasform>Views/Home.xsl</trasform>
		</view>
	</action>
</actions>
</config>

This is the example controller associated with this sitemap :
<?php
class Controllers_Home extends Pampoo_BLL_Serializable {
     
   public function InitController() {		
	$this->model->Message = "Hello world!";
	return "SUCCESS";
	}
}
?>
Now you need a view to render (output to browser) the message; this view is defined in <transform> tag in the sitemap. The example rendering view is Views/Home.xsl. This is the content:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="/">
	<html>
	<head>
		<title>My first web page with Pampoo</title>
	</head>
	<body>
		<h2><xsl:value-of select="//Message"/></h2>
	</body>
	</html>	
	</xsl:template>

</xsl:stylesheet>

Now that you have created the controller and the view you need an application entry point (e.g.: index.php) where you can initialize the framework. Assuming the directory containing the application is /var/www/html (and Pampoo framework is located under /var/www/html/lib/Pampoo) this is a valid example application entry point:
<?php
session_start();
ob_start();
date_default_timezone_set('Europe/Rome');
  
require_once "/var/www/html/lib/Pampoo/Pampoo.php";

require_once "Controllers/Home.php";

Pampoo::init("/var/www/html/", "/var/www/html/sitemap.xml");
Pampoo::Run(); 
?>
Assuming your webserver address is http://localhost point your browser to http://localhost/index.php?action=home you should view the magic words "Hello world"!

Download the application sample at Sourceforge

From Wikipedia: Model–View–Controller (MVC) is a software architecture, currently considered as an architectural pattern used in software engineering. The pattern isolates "domain logic" (the application logic for the user) from input and presentation (GUI), permitting independent development, testing and maintenance of each.

Chiudi