1: <?php
2:
3: /**
4: * Smarty Method GetRegisteredObject
5: *
6: * Smarty::getRegisteredObject() method
7: *
8: * @package Smarty
9: * @subpackage PluginsInternal
10: * @author Uwe Tews
11: */
12: class Smarty_Internal_Method_GetRegisteredObject
13: {
14: /**
15: * Valid for Smarty and template object
16: *
17: * @var int
18: */
19: public $objMap = 3;
20:
21: /**
22: * return a reference to a registered object
23: *
24: * @api Smarty::getRegisteredObject()
25: * @link http://www.smarty.net/docs/en/api.get.registered.object.tpl
26: *
27: * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
28: * @param string $object_name object name
29: *
30: * @return object
31: * @throws \SmartyException if no such object is found
32: */
33: public function getRegisteredObject(Smarty_Internal_TemplateBase $obj, $object_name)
34: {
35: $smarty = $obj->_getSmartyObj();
36: if (!isset($smarty->registered_objects[ $object_name ])) {
37: throw new SmartyException("'$object_name' is not a registered object");
38: }
39: if (!is_object($smarty->registered_objects[ $object_name ][ 0 ])) {
40: throw new SmartyException("registered '$object_name' is not an object");
41: }
42: return $smarty->registered_objects[ $object_name ][ 0 ];
43: }
44: }
45: