]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_registerobject.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_method_registerobject.php
1 <?php
2
3 /**
4  * Smarty Method RegisterObject
5  *
6  * Smarty::registerObject() method
7  *
8  * @package    Smarty
9  * @subpackage PluginsInternal
10  * @author     Uwe Tews
11  */
12 class Smarty_Internal_Method_RegisterObject
13 {
14     /**
15      * Valid for Smarty and template object
16      *
17      * @var int
18      */
19     public $objMap = 3;
20
21     /**
22      * Registers object to be used in templates
23      *
24      * @api  Smarty::registerObject()
25      * @link http://www.smarty.net/docs/en/api.register.object.tpl
26      *
27      * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
28      * @param  string                                                         $object_name
29      * @param  object                                                         $object                     the
30      *                                                                                                    referenced
31      *                                                                                                    PHP object to
32      *                                                                                                    register
33      * @param  array                                                          $allowed_methods_properties list of
34      *                                                                                                    allowed
35      *                                                                                                    methods
36      *                                                                                                    (empty = all)
37      * @param  bool                                                           $format                     smarty
38      *                                                                                                    argument
39      *                                                                                                    format, else
40      *                                                                                                    traditional
41      * @param  array                                                          $block_methods              list of
42      *                                                                                                    block-methods
43      *
44      * @return \Smarty|\Smarty_Internal_Template
45      * @throws \SmartyException
46      */
47     public function registerObject(Smarty_Internal_TemplateBase $obj, $object_name, $object,
48                                    $allowed_methods_properties = array(), $format = true, $block_methods = array())
49     {
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");
56                 }
57             }
58         }
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");
64                 }
65             }
66         }
67         // register the object
68         $smarty->registered_objects[ $object_name ] =
69             array($object, (array) $allowed_methods_properties, (boolean) $format, (array) $block_methods);
70         return $obj;
71     }
72 }