Source code for file /joomla/cache/handlers/callback.php
Documentation is available at callback.php
* @version $Id: callback.php 6673 2007-02-19 05:12:48Z louis $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* Joomla! Cache callback type object
* @package Joomla.Framework
* Executes a cacheable callback if not found in cache else returns cached output and result
* Since arguments to this function are read with func_get_args you can pass any number of arguments to this method
* as long as the first argument passed is the callback definition.
* The callback definition can be in several forms:
* - Standard PHP Callback array <http://php.net/callback> [recommended]
* - Function name as a string eg. 'foo' for function foo()
* - Static method name as a string eg. 'MyClass::myMethod' for method myMethod() of class MyClass
* @return mixed Result of the callback
// Get callback and arguments
return $this->get( $callback, $args );
* Executes a cacheable callback if not found in cache else returns cached output and result
* @param mixed Callback or string shorthand for a callback
* @param array Callback arguments
* @return mixed Result of the callback
function get( $callback, $args, $id=
false )
// We have a standard php callback array -- do nothing
} elseif (strstr( $callback, '::' )) {
// This is shorthand for a static method callback classname::methodname
list
( $class, $method ) =
explode( '::', $callback );
$callback =
array( trim($class), trim($method) );
} elseif (strstr( $callback, '->' )) {
* This is a really not so smart way of doing this... we provide this for backward compatability but this
* WILL!!! disappear in a future version. If you are using this syntax change your code to use the standard
* PHP callback array syntax: <http://php.net/callback>
* We have to use some silly global notation to pull it off and this is very unreliable
list
( $object_123456789, $method ) =
explode('->', $callback);
global $
$object_123456789;
$callback =
array( $
$object_123456789, $method );
// We have just a standard function -- do nothing
$id =
$this->_makeId($callback, $args);
// Get the storage handler and get callback cache data by id and group
$data =
parent::get($id);
$output =
$cached['output'];
$result =
$cached['result'];
$cached['output'] =
$output;
$cached['result'] =
$result;
* Generate a callback cache id
* @param callback $callback Callback to cache
* @param array $args Arguments to the callback method to cache
* @return string MD5 Hash : function cache id
function _makeId($callback, $args)