PageRenderTime 45ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/protected/extensions/yii-debug-toolbar/components/ProxyComponent.php

https://bitbucket.org/negge/tlklan2
PHP | 118 lines | 88 code | 15 blank | 15 comment | 30 complexity | c9af52a469279e37611e83e2bcc50fff MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, BSD-2-Clause, GPL-3.0
  1. <?php
  2. /**
  3. * ProxyComponent class file.
  4. *
  5. * @author Sergey Malyshev <malyshev.php@gmail.com>
  6. */
  7. /**
  8. * ProxyComponent represents an ...
  9. *
  10. * Description of ProxyComponent
  11. *
  12. * @author Sergey Malyshev <malyshev.php@gmail.com>
  13. * @version $Id$
  14. * @package
  15. * @since 1.1.7
  16. */
  17. class ProxyComponent extends CComponent
  18. {
  19. private $_instance;
  20. private $_isProxy;
  21. protected $abstract = array();
  22. public function init()
  23. {
  24. }
  25. public function getIsProxy()
  26. {
  27. if (null === $this->_isProxy)
  28. {
  29. $this->_isProxy = (null !== $this->_instance && !($this->_instance instanceof $this));
  30. }
  31. return $this->_isProxy;
  32. }
  33. public function setInstance($value)
  34. {
  35. if (null === $this->_instance && false !== is_object($value))
  36. {
  37. $this->abstract = array_merge($this->abstract, get_object_vars($value));
  38. $this->_instance = $value;
  39. }
  40. }
  41. public function getInstance()
  42. {
  43. return $this->_instance;
  44. }
  45. public function __call($name, $parameters)
  46. {
  47. if (false !== $this->getIsProxy() && false !== method_exists($this->_instance, $name))
  48. {
  49. return call_user_func_array(array($this->_instance, $name), $parameters);
  50. }
  51. return parent::__call($name, $parameters);
  52. }
  53. public function __set($name, $value)
  54. {
  55. $setter='set'.$name;
  56. if (false !== method_exists($this, $setter))
  57. {
  58. return call_user_func_array(array($this, $setter), array($value));
  59. }
  60. else if (false !== property_exists($this, $name))
  61. {
  62. return $this->$name = $value;
  63. }
  64. else if (false !== $this->getIsProxy() && false !== method_exists($this->_instance, $setter))
  65. {
  66. return call_user_func_array(array($this->_instance, $setter), array($value));
  67. }
  68. else if (false !== $this->getIsProxy() && false !== property_exists($this->_instance, $name))
  69. {
  70. return $this->_instance->$name = $value;
  71. }
  72. else if (false === $this->getIsProxy() && false !== array_key_exists ($name, $this->abstract))
  73. {
  74. return $this->abstract[$name] = $value;
  75. }
  76. return parent::__set($name, $value);
  77. }
  78. public function __get($name)
  79. {
  80. $getter='get'.$name;
  81. if (false !== method_exists($this, $getter))
  82. {
  83. return call_user_func(array($this, $getter));
  84. }
  85. else if (false !== property_exists($this, $name))
  86. {
  87. return $this->$name;
  88. }
  89. else if (false !== $this->getIsProxy() && false !== method_exists($this->_instance, $getter))
  90. {
  91. return call_user_func(array($this->_instance, $getter));
  92. }
  93. else if (false !== $this->getIsProxy() && false !== property_exists($this->_instance, $name))
  94. {
  95. return $this->_instance->$name;
  96. }
  97. else if (false === $this->getIsProxy() && false !== array_key_exists ($name, $this->abstract))
  98. {
  99. return $this->abstract[$name];
  100. }
  101. return parent::__get($name);
  102. }
  103. }