smarty_internal_wrapper.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Project: Smarty: the PHP compiling template engine
  4. * File: smarty_internal_wrapper.php
  5. * SVN: $Id: $
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * For questions, help, comments, discussion, etc., please join the
  22. * Smarty mailing list. Send a blank e-mail to
  23. * smarty-discussion-subscribe@googlegroups.com
  24. *
  25. * @link http://www.smarty.net/
  26. * @copyright 2008 New Digital Group, Inc.
  27. * @author Monte Ohrt <monte at ohrt dot com>
  28. * @author Uwe Tews
  29. * @package Smarty
  30. * @subpackage PluginsInternal
  31. * @version 3-SVN$Rev: 3286 $
  32. */
  33. /*
  34. * Smarty Backward Compatability Wrapper
  35. */
  36. class Smarty_Internal_Wrapper {
  37. protected $smarty;
  38. function __construct($smarty) {
  39. $this->smarty = $smarty;
  40. }
  41. /**
  42. * Converts smarty2-style function call to smarty 3-style function call
  43. * This is expensive, be sure to port your code to Smarty 3!
  44. *
  45. * @param string $name Smarty 2 function name
  46. * @param array $args Smarty 2 function args
  47. */
  48. function convert($name, $args) {
  49. // throw notice about deprecated function
  50. if($this->smarty->deprecation_notices)
  51. trigger_error("function call '$name' is unknown or deprecated.",E_USER_NOTICE);
  52. // get first and last part of function name
  53. $name_parts = explode('_',$name,2);
  54. switch($name_parts[0]) {
  55. case 'register':
  56. case 'unregister':
  57. $myobj = $name_parts[0] == 'register' ? $this->smarty->register : $this->smarty->unregister;
  58. switch($name_parts[1]) {
  59. case 'function':
  60. return call_user_func_array(array($myobj,'templateFunction'),$args);
  61. break;
  62. case 'object':
  63. return call_user_func_array(array($myobj,'templateObject'),$args);
  64. break;
  65. case 'compiler_function':
  66. return call_user_func_array(array($myobj,'compilerFunction'),$args);
  67. break;
  68. default:
  69. return call_user_func_array(array($myobj,$name_parts[1]),$args);
  70. break;
  71. }
  72. break;
  73. case 'get':
  74. switch($name_parts[1]) {
  75. case 'template_vars':
  76. return call_user_func_array(array($this->smarty,'getTemplateVars'),$args);
  77. break;
  78. case 'config_vars':
  79. return call_user_func_array(array($this->smarty,'getConfigVars'),$args);
  80. break;
  81. default:
  82. return call_user_func_array(array($myobj,$name_parts[1]),$args);
  83. break;
  84. }
  85. break;
  86. case 'clear':
  87. switch($name_parts[1]) {
  88. case 'all_assign':
  89. return call_user_func_array(array($this->smarty,'clearAllAssign'),$args);
  90. break;
  91. }
  92. break;
  93. case 'config':
  94. switch($name_parts[1]) {
  95. case 'load':
  96. return call_user_func_array(array($this->smarty,'configLoad'),$args);
  97. break;
  98. }
  99. break;
  100. default:
  101. // convert foo_bar_baz to fooBarBaz style names
  102. $name_parts = explode('_',$name);
  103. foreach($name_parts as $idx=>$part) {
  104. if($idx==0)
  105. $name_parts[$idx] = strtolower($part);
  106. else
  107. $name_parts[$idx] = ucfirst($part);
  108. }
  109. $func_name = implode('',$name_parts);
  110. if(!method_exists($this->smarty,$func_name)) {
  111. throw new Exception("unknown method '$name'");
  112. return false;
  113. }
  114. return call_user_func_array(array($this->smarty,$func_name),$args);
  115. break;
  116. }
  117. return false;
  118. }
  119. }
  120. ?>