Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

smarty_internal_method_registerobject.php 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Smarty Method RegisterObject
  4. *
  5. * Smarty::registerObject() method
  6. *
  7. * @package Smarty
  8. * @subpackage PluginsInternal
  9. * @author Uwe Tews
  10. */
  11. class Smarty_Internal_Method_RegisterObject
  12. {
  13. /**
  14. * Valid for Smarty and template object
  15. *
  16. * @var int
  17. */
  18. public $objMap = 3;
  19. /**
  20. * Registers object to be used in templates
  21. *
  22. * @api Smarty::registerObject()
  23. * @link http://www.smarty.net/docs/en/api.register.object.tpl
  24. *
  25. * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
  26. * @param string $object_name
  27. * @param object $object the
  28. * referenced
  29. * PHP object to
  30. * register
  31. * @param array $allowed_methods_properties list of
  32. * allowed
  33. * methods
  34. * (empty = all)
  35. * @param bool $format smarty
  36. * argument
  37. * format, else
  38. * traditional
  39. * @param array $block_methods list of
  40. * block-methods
  41. *
  42. * @return \Smarty|\Smarty_Internal_Template
  43. * @throws \SmartyException
  44. */
  45. public function registerObject(Smarty_Internal_TemplateBase $obj, $object_name, $object, $allowed_methods_properties = array(), $format = true, $block_methods = array())
  46. {
  47. $smarty = isset($obj->smarty) ? $obj->smarty : $obj;
  48. // test if allowed methods callable
  49. if (!empty($allowed_methods_properties)) {
  50. foreach ((array) $allowed_methods_properties as $method) {
  51. if (!is_callable(array($object, $method)) && !property_exists($object, $method)) {
  52. throw new SmartyException("Undefined method or property '$method' in registered object");
  53. }
  54. }
  55. }
  56. // test if block methods callable
  57. if (!empty($block_methods)) {
  58. foreach ((array) $block_methods as $method) {
  59. if (!is_callable(array($object, $method))) {
  60. throw new SmartyException("Undefined method '$method' in registered object");
  61. }
  62. }
  63. }
  64. // register the object
  65. $smarty->registered_objects[$object_name] = array($object, (array) $allowed_methods_properties,
  66. (boolean) $format, (array) $block_methods);
  67. return $obj;
  68. }
  69. }