mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-03-12 00:45:34 +00:00
add generic decorator class
This commit is contained in:
parent
9a0b6c4d3d
commit
cebf0e3796
|
@ -26,6 +26,11 @@ else
|
|||
*/
|
||||
require_once('Core/inc.ClassDMS.php');
|
||||
|
||||
/**
|
||||
* @uses SeedDMS_Decorator
|
||||
*/
|
||||
require_once('Core/inc.ClassDecorator.php');
|
||||
|
||||
/**
|
||||
* @uses SeedDMS_Object
|
||||
*/
|
||||
|
|
42
SeedDMS_Core/Core/inc.ClassDecorator.php
Normal file
42
SeedDMS_Core/Core/inc.ClassDecorator.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Implementation of the decorator pattern
|
||||
*
|
||||
* @category DMS
|
||||
* @package SeedDMS_Core
|
||||
* @license GPL 2
|
||||
* @version @version@
|
||||
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||
* @copyright Copyright (C) 2010, Uwe Steinmann
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Class which implements a simple decorator pattern
|
||||
*
|
||||
* @category DMS
|
||||
* @package SeedDMS_Core
|
||||
* @version @version@
|
||||
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||
* @copyright Copyright (C) 2010, Uwe Steinmann
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class SeedDMS_Core_Decorator {
|
||||
protected $o;
|
||||
|
||||
public function __construct($object) {
|
||||
$this->o = $object;
|
||||
}
|
||||
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if (!method_exists($this->o, $method)) {
|
||||
throw new Exception("Undefined method $method attempt.");
|
||||
}
|
||||
/* In case the called method returns the object itself, then return this object */
|
||||
$result = call_user_func_array(array($this->o, $method), $args);
|
||||
return $result === $this->o ? $this : $result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user