Skip to content

Instantly share code, notes, and snippets.

@ohpauleez
Created January 30, 2012 22:15
Show Gist options
  • Save ohpauleez/1707145 to your computer and use it in GitHub Desktop.
Save ohpauleez/1707145 to your computer and use it in GitHub Desktop.
<?php namespace cacher;
class CacheMixin
{
public static $default_cache_settings = array();
public static function __callStatic($name, $args)
{
echo "\nHello, $name\n";
$cache_settings = static::$default_cache_settings;
$potential_cache = array_pop($args);
if (isset($potential_cache) && is_array($potential_cache) && array_key_exists('__cache', $potential_cache)){
// this should all be in its own method
$cache_settings = !empty($potential_cache['__cache']) ? $potential_cache['__cache'] : $cache_settings;
} else {
// We need to put that arg back
$args[] = $potential_cache;
}
print_r($cache_settings);
//forward_static_call_array('cm_'.$name, $args);
call_user_func_array("static::cm_$name", $args);
}
}
class SomeDAL extends CacheMixin
{
public static $default_cache_settings = array(2);
public static function cm_getAllThings()
{
echo "\ngetAllThings\n";
}
}
SomeDAL::getAllThings(array('__cache'=>array(1))); // Sends the caching arg `1`
echo "\n----\n";
SomeDAL::getAllThings(); // uses the `SomeDAL` default setting of `2`
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment