HookOverride__NAMEHERE_::__set_state()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 4
Ratio 66.67 %

Importance

Changes 0
Metric Value
dl 4
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
namespace SciActive;
3
4
/**
5
 * Dynamic HookOverride class.
6
 *
7
 * @version 2.1.0
8
 * @license https://www.gnu.org/licenses/lgpl.html
9
 * @author Hunter Perrin <[email protected]>
10
 * @copyright SciActive.com
11
 * @link http://requirephp.org
12
 */
13
14
/**
15
 * An object used to replace another object, so it can be hooked.
16
 *
17
 * This class is dynamically edited during the takeover of an object for
18
 * hooking.
19
 */
20
class HookOverride__NAMEHERE_ extends HookOverride implements \JsonSerializable {
21
  /**
22
   * Used to store the overridden class.
23
   * @var mixed $_hookObject
24
   */
25
  protected $_hookObject = null;
26
  /**
27
   * Used to store the prefix (the object's variable name).
28
   * @var string $_hookPrefix
29
   */
30
  protected $_hookPrefix = '';
31
32
  public function _hookObject() {
33
    return $this->_hookObject;
34
  }
35
36
  public function __construct(&$object, $prefix = '') {
37
    $this->_hookObject = $object;
38
    $this->_hookPrefix = $prefix;
39
  }
40
41
  public function &__get($name) {
42
    $val =& $this->_hookObject->$name;
43
    return $val;
44
  }
45
46
  public function __set($name, $value) {
47
    return $this->_hookObject->$name = $value;
48
  }
49
50
  public function __isset($name) {
51
    return isset($this->_hookObject->$name);
52
  }
53
54
  public function __unset($name) {
55
    unset($this->_hookObject->$name);
56
  }
57
58
  public function __toString() {
59
    return (string) $this->_hookObject;
60
  }
61
62
  public function __invoke() {
63 View Code Duplication
    if (method_exists($this->_hookObject, '__invoke')) {
64
      $args = func_get_args();
65
      return call_user_func_array(array($this->_hookObject, '__invoke'), $args);
66
    }
67
  }
68
69
  public function __set_state() {
70 View Code Duplication
    if (method_exists($this->_hookObject, '__set_state')) {
71
      $args = func_get_args();
72
      return call_user_func_array(array($this->_hookObject, '__set_state'), $args);
73
    }
74
  }
75
76
  public function __clone() {
77
    // TODO: Test this. Make sure cloning works properly.
78
    $newObject = clone $this->_hookObject;
79
    Hook::hookObject($newObject, get_class($newObject).'->', false);
80
    return $newObject;
81
  }
82
83
  public function jsonSerialize() {
84
    $_HOOK_arguments = func_get_args();
85
    $_HOOK_function = array($this->_hookObject, 'jsonSerialize');
86
    $_HOOK_data = array();
87
    \SciActive\Hook::runCallbacks($this->_hookPrefix.'jsonSerialize', $_HOOK_arguments, 'before', $this->_hookObject, $_HOOK_function, $_HOOK_data);
88
    if ($_HOOK_arguments !== false) {
89
      if (is_callable($this->_hookObject, 'jsonSerialize') && !empty($_HOOK_arguments)) {
90
        $_HOOK_return = array(call_user_func_array($_HOOK_function, $_HOOK_arguments));
91
      } else {
92
        $_HOOK_return = array($this->_hookObject);
93
      }
94
      \SciActive\Hook::runCallbacks($this->_hookPrefix.'jsonSerialize', $_HOOK_return, 'after', $this->_hookObject, $_HOOK_function, $_HOOK_data);
95
      if ((array) $_HOOK_return === $_HOOK_return) {
96
        return $_HOOK_return[0];
97
      }
98
    }
99
  }
100
101
//#CODEHERE#
102
}
103