PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/component/actions/HandlerDelegate.php

https://github.com/jcorbinredtree/framework
PHP | 65 lines | 31 code | 9 blank | 25 comment | 3 complexity | 6df9c0d6eeea90d1fcf4198ced76dd39 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * LICENSE: The contents of this file are subject to the Mozilla Public License Version 1.1
  4. * (the "License"); you may not use this file except in compliance with the
  5. * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS IS" basis,
  8. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  9. * the specific language governing rights and limitations under the License.
  10. *
  11. * The Original Code is Red Tree Systems Code.
  12. *
  13. * The Initial Developer of the Original Code is Red Tree Systems, LLC. All Rights Reserved.
  14. *
  15. * This class, meant to be subclassed, is constructed
  16. * as a utility to allow components to further break
  17. * down delegates to manage large parts of functionality.
  18. * A Ford component, for instance, might have a HRHandler,
  19. * a PartsHandler, and so forth.
  20. *
  21. */
  22. abstract class HandlerDelegate
  23. {
  24. /**
  25. * The component this delegate is tied to
  26. *
  27. * @var Component
  28. */
  29. public $component;
  30. final public function __construct(Component &$component)
  31. {
  32. $this->component =& $component;
  33. }
  34. public function __get($property)
  35. {
  36. if (!property_exists($this->component, $property)) {
  37. throw new Exception("unknown property $property");
  38. }
  39. return $this->component->$property;
  40. }
  41. public function __set($property, $value)
  42. {
  43. if (!property_exists($this->component, $property)) {
  44. throw new Exception("unknown property $property");
  45. }
  46. $this->component->$property = $value;
  47. }
  48. public function __call($name, $args)
  49. {
  50. if (!method_exists($this->component, $name)) {
  51. throw new Exception("unknown method $name");
  52. }
  53. return call_user_func_array(array($this->component, $name), $args);
  54. }
  55. }
  56. ?>