[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/cache/ -> sfFunctionCache.class.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the symfony package.
   5   * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
   6   * 
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  /**
  12   * This class can be used to cache the result and output of functions/methods.
  13   *
  14   * This class is based on the PEAR_Cache_Lite class.
  15   * All cache files are stored in files in the [sf_root_dir].'/cache/'.[sf_app].'/function' directory.
  16   * To disable all caching, you can set to false [sf_cache] constant.
  17   *
  18   * @package    symfony
  19   * @subpackage cache
  20   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  21   * @author     Fabien Marty <fab@php.net>
  22   * @version    SVN: $Id: sfFunctionCache.class.php 3452 2007-02-14 15:03:08Z francois $
  23   */
  24  class sfFunctionCache extends sfFileCache
  25  {
  26    /**
  27     * Calls a cacheable function or method (or not if there is already a cache for it).
  28     *
  29     * Arguments of this method are read with func_get_args. So it doesn't appear in the function definition. Synopsis : 
  30     * call('functionName', $arg1, $arg2, ...)
  31     * (arg1, arg2... are arguments of 'functionName')
  32     *
  33     * @return mixed The result of the function/method
  34     */
  35    public function call()
  36    {
  37      $arguments = func_get_args();
  38  
  39      // Generate a cache id
  40      $id = md5(serialize($arguments));
  41  
  42      $data = $this->get($id);
  43      if ($data !== null)
  44      {
  45        $array = unserialize($data);
  46        $output = $array['output'];
  47        $result = $array['result'];
  48      }
  49      else
  50      {
  51        $target = array_shift($arguments);
  52        ob_start();
  53        ob_implicit_flush(false);
  54        if (is_string($target) && strstr($target, '::'))
  55        {
  56          // classname::staticMethod
  57          list($class, $method) = explode('::', $target);
  58          try
  59          {
  60            $result = call_user_func_array(array($class, $method), $arguments);
  61          }
  62          catch (Exception $e)
  63          {
  64            ob_end_clean();
  65            throw $e;
  66          }
  67        }
  68        else if (is_string($target) && strstr($target, '->'))
  69        {
  70          // object->method
  71          // use a stupid name ($objet_123456789 because) of problems when the object
  72          // name is the same as this var name
  73          list($object_123456789, $method) = explode('->', $target);
  74          global $$object_123456789;
  75          try
  76          {
  77            $result = call_user_func_array(array($$object_123456789, $method), $arguments);
  78          }
  79          catch (Exception $e)
  80          {
  81            ob_end_clean();
  82            throw $e;
  83          }
  84        }
  85        else
  86        {
  87          // function
  88          $result = call_user_func_array($target, $arguments);
  89        }
  90        $output = ob_get_contents();
  91        ob_end_clean();
  92  
  93        $array['output'] = $output;
  94        $array['result'] = $result;
  95  
  96        $this->set($id, '', serialize($array));
  97      }
  98  
  99      echo($output);
 100      return $result;
 101    }
 102  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7