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{
29    protected $o;
30
31    public function __construct($object) {
32        $this->o = $object;
33    }
34
35    public function __call($method, $args)
36    {
37        if (!method_exists($this->o, $method)) {
38            throw new Exception("Undefined method $method attempt.");
39        }
40        /* In case the called method returns the object itself, then return this object */
41        $result = call_user_func_array(array($this->o, $method), $args);
42        return $result === $this->o ? $this : $result;
43    }
44}