|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
btgmarco Smarty n00b
Joined: 14 Oct 2011 Posts: 1
|
Posted: Fri Oct 14, 2011 8:24 pm Post subject: Generic Accessing Functions |
|
|
I am working on a project, and on that I use smarty library, but on the development process I had to build too many smaty_functions and on many times that functions already exists on some helper, or something like this, so to avoid create all many functions, I and an friend we did this function, to call some static method or access some attr on some class, itīs quite simple to use, we donīt have noticed any kind of bugs.
Hope that hope.
ps: Sorry if we are posting on the wrong place
Code: |
<?php
/**
*
*
* function to call some static method or static attributes and return his value, if unable to access the method or attribute, returns null
*
* Calling a method
* {caller class="Foo" method="bar" param1="fooTest" param2="barTest""}
*
* Accessing a attribute
* {caller class="Foo" attr="bar"}
*
* Accessing a attribute passing an index
* {caller class="Foo" attr="bar" index="some_index"}
*
* @param class
* @return mixed
*
* @author Renato Neto <skapemr at gmail dot com>
* @author Marco Augusto <btgmarco at gmail dot com>
*
*
*/
function smarty_function_caller($params) {
extract($params);
if (!empty($class)) {
if (!empty($method)) {
unset($params['class']);
unset($params['method']);
$reflection = new ReflectionMethod($class, $method);
if ($reflection->isStatic()) {
return call_user_func_array(array($class, $method), $params);
}
} elseif (!empty($attr) ) {
if (isset($index)) {
$value = $class::$$attr;
if (isset($value[$index]) ) {
return $value[$index];
}
}else {
return $class::$$attr;
}
}
}
return null;
}
|
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|