/usr/share/php/Cache/Function.php is in php-cache 1.5.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | <?php
// +----------------------------------------------------------------------+
// | PEAR :: Cache |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
// $Id: Function.php 174777 2004-12-15 09:09:33Z dufuz $
require_once 'Cache.php';
/**
* Function_Cache
*
* Purpose:
*
* Caching the result and output of functions.
*
* Example:
*
* require_once 'Cache/Function.php';
*
* class foo {
* function bar($test) {
* echo "foo::bar($test)<br>";
* }
* }
*
* class bar {
* function foobar($object) {
* echo '$'.$object.'->foobar('.$object.')<br>';
* }
* }
*
* $bar = new bar;
*
* function foobar() {
* echo 'foobar()';
* }
*
* $cache = new Cache_Function();
*
* $cache->call('foo::bar', 'test');
* $cache->call('bar->foobar', 'bar');
* $cache->call('foobar');
*
* Note:
*
* You cannot cache every function. You should only cache
* functions that only depend on their arguments and don't use
* global or static variables, don't rely on database queries or
* files, and so on.
*
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @module Function_Cache
* @modulegroup Function_Cache
* @package Cache
* @version $Revision: 174777 $
* @access public
*/
class Cache_Function extends Cache
{
var $expires;
/**
* Constructor
*
* @param string Name of container class
* @param array Array with container class options
* @param integer Number of seconds for which to cache
*/
function Cache_Function($container = 'file',
$container_options = array('cache_dir' => '.',
'filename_prefix' => 'cache_'
),
$expires = 3600
)
{
$this->Cache($container, $container_options);
$this->expires = $expires;
}
/**
* PEAR-Deconstructor
* Call deconstructor of parent
*/
function _Cache_Function()
{
$this->_Cache();
}
/**
* Calls a cacheable function or method.
*
* @return mixed $result
* @access public
*/
function call()
{
// get arguments
$arguments = func_get_args();
// generate cache id
$id = md5(serialize($arguments));
// query cache
$cached_object = $this->get($id, 'function_cache');
if ($cached_object != null) {
// cache hit: return cached output and result
$output = $cached_object[0];
$result = $cached_object[1];
} else {
// cache miss: call function, store output and result in cache
ob_start();
$target = array_shift($arguments);
// classname::staticMethod
if (strstr($target, '::')) {
list($class, $method) = explode('::', $target);
$result = call_user_func_array(array($class, $method), $arguments);
} elseif (strstr($target, '->')) {
// object->method
list($object, $method) = explode('->', $target);
global $$object;
$result = call_user_func_array(array($$object, $method), $arguments);
} else {
// function
$result = call_user_func_array($target, $arguments);
}
$output = ob_get_contents();
ob_end_clean();
$this->save($id, array($output, $result), $this->expires, 'function_cache');
}
echo $output;
return $result;
}
}
?>
|