Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SeedDMS_Core_Decorator
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __call
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2declare(strict_types=1);
3
4/**
5 * Implementation of the decorator pattern
6 *
7 * @category   DMS
8 * @package    SeedDMS_Core
9 * @license    GPL 2
10 * @version    @version@
11 * @author     Uwe Steinmann <uwe@steinmann.cx>
12 * @copyright  Copyright (C) 2010-2024 Uwe Steinmann
13 * @version    Release: @package_version@
14 */
15
16
17/**
18 * Class which implements a simple decorator pattern
19 *
20 * @category   DMS
21 * @package    SeedDMS_Core
22 * @version    @version@
23 * @author     Uwe Steinmann <uwe@steinmann.cx>
24 * @copyright  Copyright (C) 2010-2024 Uwe Steinmann
25 * @version    Release: @package_version@
26 */
27class SeedDMS_Core_Decorator {
28    protected $o;
29
30    public function __construct($object) {
31        $this->o = $object;
32    }
33
34    public function __call($method, $args)
35    {
36        if (!method_exists($this->o, $method)) {
37            throw new Exception("Undefined method $method attempt.");
38        }
39        /* In case the called method returns the object itself, then return this object */
40        $result = call_user_func_array(array($this->o, $method), $args);
41         return $result === $this->o ? $this : $result;
42    }   
43}
44