4 * Smarty Method RegisterObject
6 * Smarty::registerObject() method
9 * @subpackage PluginsInternal
12 class Smarty_Internal_Method_RegisterObject
15 * Valid for Smarty and template object
22 * Registers object to be used in templates
24 * @api Smarty::registerObject()
25 * @link http://www.smarty.net/docs/en/api.register.object.tpl
27 * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
28 * @param string $object_name
29 * @param object $object the
33 * @param array $allowed_methods_properties list of
37 * @param bool $format smarty
41 * @param array $block_methods list of
44 * @return \Smarty|\Smarty_Internal_Template
45 * @throws \SmartyException
47 public function registerObject(Smarty_Internal_TemplateBase $obj, $object_name, $object,
48 $allowed_methods_properties = array(), $format = true, $block_methods = array())
50 $smarty = $obj->_getSmartyObj();
51 // test if allowed methods callable
52 if (!empty($allowed_methods_properties)) {
53 foreach ((array) $allowed_methods_properties as $method) {
54 if (!is_callable(array($object, $method)) && !property_exists($object, $method)) {
55 throw new SmartyException("Undefined method or property '$method' in registered object");
59 // test if block methods callable
60 if (!empty($block_methods)) {
61 foreach ((array) $block_methods as $method) {
62 if (!is_callable(array($object, $method))) {
63 throw new SmartyException("Undefined method '$method' in registered object");
67 // register the object
68 $smarty->registered_objects[ $object_name ] =
69 array($object, (array) $allowed_methods_properties, (boolean) $format, (array) $block_methods);