isAbstract()) { // Make the extension abstract, too $extension = 'abstract '.$extension; } // Transparent class extensions are possible using eval. Not very // clean, but it can be avoided by creating empty extension files. eval($extension); } return TRUE; } /** * Provides simple file-based caching. All caches are serialized and * stored as a hash. * * // Set the "foo" cache * Kohana::cache('foo', 'hello, world'); * * // Get the "foo" cache * $foo = Kohana::cache('foo'); * * @param string name of the cache * @param mixed data to cache * @param integer number of seconds the cache is valid for * @return mixed for getting * @return boolean for setting */ public function cache($name, $data = NULL, $lifetime = 60) { // Cache file is a hash of the name $file = sha1($name); // Cache directories are split by keys $dir = APPPATH.'cache/'.$file[0].'/'; if ($data === NULL) { if (is_file($dir.$file)) { if ((time() - filemtime($dir.$file)) < $lifetime) { // Return the cache return unserialize(file_get_contents($dir.$file)); } else { // Cache has expired unlink($dir.$file); } } // Cache not found return NULL; } if ( ! is_dir($dir)) { // Create the cache directory mkdir($dir, 0777); } // Serialize the data and create the cache return (bool) file_put_contents($dir.$file, serialize($data)); } /** * Returns an HTML string of debugging information about any number of * variables, each wrapped in a
 tag:
	 *
	 *     // Displays the type and value of each variable
	 *     echo Kohana::debug($foo, $bar, $baz);
	 *
	 * @param   mixed   variable to debug
	 * @param   ...
	 * @return  string
	 */
	public static function debug()
	{
		if (func_num_args() === 0)
			return;

		// Get all passed variables
		$variables = func_get_args();

		$output = array();
		foreach ($variables as $var)
		{
			$output[] = '
('.gettype($var).') '.htmlspecialchars(print_r($var, TRUE), ENT_QUOTES, self::$charset, TRUE).'
'; } return implode("\n", $output); } /** * Removes application, system, modpath, or docroot from a filename, * replacing them with the plain text equivalents. Useful for debugging * when you want to display a shorter path. * * // Displays SYSPATH/classes/kohana.php * echo Kohana::debug_path(Kohana::find_file('classes', 'kohana')); * * @param string path to debug * @return string */ public static function debug_path($file) { if (strpos($file, APPPATH) === 0) { $file = 'APPPATH/'.substr($file, strlen(APPPATH)); } elseif (strpos($file, SYSPATH) === 0) { $file = 'SYSPATH/'.substr($file, strlen(SYSPATH)); } elseif (strpos($file, MODPATH) === 0) { $file = 'MODPATH/'.substr($file, strlen(MODPATH)); } elseif (strpos($file, DOCROOT) === 0) { $file = 'DOCROOT/'.substr($file, strlen(DOCROOT)); } return $file; } } // End Kohana