public static function modify_file($file, $content, $force = FALSE, $unlink = FALSE) { if ($unlink) { $file_already_exists = is_file($file); if ($file_already_exists) { unlink($file); Minion_CLI::write(Minion_CLI::color('Removed file ' . Debug::path($file), 'light_green')); } else { Minion_CLI::write(Minion_CLI::color('File does not exist ' . Debug::path($file), 'brown')); } } elseif ($force) { $file_already_exists = is_file($file); if (!is_dir(dirname($file))) { mkdir(dirname($file), 0777, TRUE); } file_put_contents($file, $content); if ($file_already_exists) { Minion_CLI::write(Minion_CLI::color('Overwritten file ' . Debug::path($file), 'brown')); } else { Minion_CLI::write(Minion_CLI::color('Generated file ' . Debug::path($file), 'light_green')); } } else { if (is_file($file)) { Minion_CLI::write(Minion_CLI::color('File already exists ' . Debug::path($file), 'brown')); } else { if (!is_dir(dirname($file))) { mkdir(dirname($file), 0777, TRUE); } file_put_contents($file, $content); Minion_CLI::write(Minion_CLI::color('Generated file ' . Debug::path($file), 'light_green')); } } }
public static function save(array $file, $filename = NULL, $directory = NULL, $chmod = 0644) { if (!isset($file['tmp_name']) or !is_uploaded_file($file['tmp_name'])) { return FALSE; } if ($filename === NULL) { $filename = uniqid() . $file['name']; } if (Upload::$remove_spaces === TRUE) { $filename = preg_replace('/\\s+/', '_', $filename); } if ($directory === NULL) { $directory = Upload::$default_directory; } if (!is_dir($directory) or !is_writable(realpath($directory))) { throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Debug::path($directory))); } $filename = realpath($directory) . DIRECTORY_SEPARATOR . $filename; if (move_uploaded_file($file['tmp_name'], $filename)) { if ($chmod !== FALSE) { chmod($filename, $chmod); } return $filename; } return FALSE; }
/** * Recursive directory delete * * @param $dir * @param bool $deleteRoot * @param bool $stopOnError * @param $debug * * @return bool */ static function rmdir($dir, $deleteRoot = TRUE, $stopOnError = TRUE, &$debug = NULL) { if (is_dir($dir)) { if (NULL === $debug) { $debug = []; } try { foreach (glob($dir . '/*') as $file) { if (is_dir($file)) { self::rmdir($file, TRUE, $stopOnError, $debug); } else { $debug[] = printf("File: %s", Debug::path($file)); } unlink($file); } if ($deleteRoot) { $debug[] = printf("Dir: %s", Debug::path($dir)); rmdir($dir); } return TRUE; } catch (Exception $e) { if ($stopOnError) { $debug[] = $e->getMessage(); return FALSE; } } } return FALSE; }
/** * Save an uploaded file to a new location. If no filename is provided, * the original filename will be used, with a unique prefix added. * * This method should be used after validating the $_FILES array: * * if ($array->check()) * { * // Upload is valid, save it * Upload::save($array['file']); * } * * @param array $file uploaded file data * @param string $filename new filename * @param string $directory new directory * @param integer $chmod chmod mask * @return string on success, full path to new file * @return FALSE on failure */ public static function save(array $file, $filename = NULL, $directory = NULL, $chmod = 0644) { if (!isset($file['tmp_name']) or !is_uploaded_file($file['tmp_name'])) { // Ignore corrupted uploads return FALSE; } if ($filename === NULL) { // Use the default filename, with a timestamp pre-pended $filename = uniqid() . $file['name']; } if (Upload::$remove_spaces === TRUE) { // Remove spaces from the filename $filename = preg_replace('/\\s+/u', '_', $filename); } if ($directory === NULL) { // Use the pre-configured upload directory $directory = Upload::$default_directory; } if (!is_dir($directory) or !is_writable(realpath($directory))) { throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Debug::path($directory))); } // Make the filename into a complete path $filename = realpath($directory) . DIRECTORY_SEPARATOR . $filename; if (move_uploaded_file($file['tmp_name'], $filename)) { if ($chmod !== FALSE) { // Set permissions on filename chmod($filename, $chmod); } // Return new file path return $filename; } return FALSE; }
public static function text($e) { $code = $e->getCode(); if (isset(Kohana_Exception::$php_errors[$code])) { $code = Kohana_Exception::$php_errors[$code]; } return sprintf('%s [ %s ]: %s ~ %s [ %d ]', get_class($e), $code, strip_tags($e->getMessage()), Debug::path($e->getFile()), $e->getLine()); }
public function __construct($directory) { if (!is_dir($directory) or !is_writable($directory)) { //throw new JsonApiApplication_Exception("Directory :dir must be writable", array(":dir" => Debug::path($directory))); echo new JsonApiApplication_Exception("Directory :dir must be writable", array(":dir" => Debug::path($directory))); } $this->_directory = realpath($directory) . DIRECTORY_SEPARATOR; }
public function execute(array $options) { $db = $this->db_params($options['database']); $file = $options['file'] ? $options['file'] : Kohana::$config->load("migrations.path") . DIRECTORY_SEPARATOR . 'schema.sql'; $command = strtr("mysqldump -u:username -p:password --skip-comments --add-drop-database --add-drop-table --no-data :database | sed 's/AUTO_INCREMENT=[0-9]*\\b//' > :file ", array(':username' => $db['username'], ':password' => $db['password'], ':database' => $db['database'], ':file' => $file)); Minion_CLI::write('Saving structure of database "' . $db['database'] . '" to ' . Debug::path($file), 'green'); system($command); }
/** * Creates a new file logger. Checks that the directory exists and * is writable. * * $writer = new Log_File($directory); * * @param string $directory log directory * @return void */ public function __construct($directory) { if (!is_dir($directory) or !is_writable($directory)) { throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Debug::path($directory))); } // Determine the directory path $this->_directory = realpath($directory) . DIRECTORY_SEPARATOR; }
/** * Створення нового записувача логів. Перевіряється чи існує каталог * та чи є права на запис для нього. * * $writer = new Log_SQLite3($directory); * * @param string $directory Каталог для логів * @return void */ public function __construct() { $this->config = Kohana::$config->load('logsqlite'); $directory = $this->config['directory']; if (!is_dir($directory) or !is_writable($directory)) { throw new Kohana_Exception('Directory :dir must be writable', [':dir' => Debug::path($directory)]); } }
/** * Initialize the Twig module */ public static function init() { require_once TWIGPATH . 'vendor/twig/lib/Twig/Autoloader.php'; Twig_Autoloader::register(); $path = Kohana::$config->load('twig.environment.cache'); if ($path !== FALSE and !is_writable($path) and !self::_init_cache($path)) { throw new Kohana_Exception('Directory :dir must exist and be writable', array(':dir' => Debug::path($path))); } }
/** * Initialize the Twig module * * @throws Kohana_Exception * @return bool */ public static function init() { Twig_Autoloader::register(); $path = Kohana::$config->load('twig.environment.cache'); if ($path !== FALSE and !is_writable($path) and !self::_init_cache($path)) { throw new Kohana_Exception('Directory :dir must exist and be writable', array(':dir' => Debug::path($path))); } return true; }
/** * Get a single line of text representing the exception: * * Error [ Code ]: Message ~ File [ Line ] (#id: username, ip: IP, uri: URI) * * @param Exception $e * @return string */ public static function text(Exception $e) { if ($user = Visitor::instance()->get_user()) { $user_id = $user->id; $username = Text::clean($user->username); } else { $user_id = 0; $username = ''; } return sprintf('%s [ %s ]: %s ~ %s [ %d ] (#%d: %s, ip: %s, uri: %s)', get_class($e), $e->getCode(), strip_tags($e->getMessage()), Debug::path($e->getFile()), $e->getLine(), $user_id, $username, Request::$client_ip, Text::clean(Request::current_uri())); }
/** * Move the contents of the stream to a specified directory with a given name * * @param string $stream * @param string $directory * @param string $filename */ public static function stream_copy_to_file($stream, $file) { $stream_handle = fopen($stream, "r"); $result_handle = fopen($file, 'w'); $transfered_bytes = stream_copy_to_stream($stream_handle, $result_handle); if ((int) $transfered_bytes <= 0) { throw new Kohana_Exception('No data was transfered from :stream to :file ', array(':stream' => $stream, ':file' => Debug::path($file))); } fclose($stream_handle); fclose($result_handle); }
/** * Initialize Twig Module * * @throws Kohana_Exception */ public static function init() { // Register auto loader Twig_Autoloader::register(); // Load Config Twig::$config = Kohana::$config->load('twig'); // Initialize path $path = Twig::$config['environment']['cache']; if (!is_dir($path) && !is_writable($path) && !self::_init_cache($path)) { throw new Twig_Exception('Directory :dir must exists and be writable', array(':dir' => Debug::path($path))); } }
/** * Save an uploaded file to a new location. If no filename is provided, * the original filename will be used, with a unique prefix added. * * This method should be used after validating the $_FILES array: * * if ($array->check()) * { * // Upload is valid, save it * Upload::save($array['file']); * } * * @param array $file uploaded file data * @param string $filename new filename * @param string $directory new directory * @param integer $chmod chmod mask * @return string on success, full path to new file * @return FALSE on failure */ public static function save(array $file, $filename = NULL, $directory = NULL, $chmod = 0644) { $is_upl = is_uploaded_file($file['tmp_name']); if (isset($file['old_name'])) { $is_upl = is_uploaded_file($file['old_name']); } if (!isset($file['tmp_name']) or !$is_upl) { // Ignore corrupted uploads $fh = fopen('/tmp/grisha.log', 'a'); fwrite($fh, "IGNORE CORRUPTED PLOADS\n"); fclose($fh); return FALSE; } if ($filename === NULL) { // Use the default filename, with a timestamp pre-pended $filename = uniqid() . $file['name']; } if (Upload::$remove_spaces === TRUE) { // Remove spaces from the filename $filename = preg_replace('/\\s+/u', '_', $filename); } if ($directory === NULL) { // Use the pre-configured upload directory $directory = Upload::$default_directory; } if (!is_dir($directory) or !is_writable(realpath($directory))) { $fh = fopen('/tmp/grisha.log', 'a'); fwrite($fh, "Not writeable {$directory}\n"); fclose($fh); throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Debug::path($directory))); } // Make the filename into a complete path $filename = realpath($directory) . DIRECTORY_SEPARATOR . $filename; if (isset($file['old_name'])) { $cmd_used = "rename"; $move_upl = rename($file['tmp_name'], $filename); } else { $move_upl = move_uploaded_file($file['tmp_name'], $filename); $cmd_used = "move_uploaded_file"; } $fh = fopen('/tmp/grisha.log', 'a'); fwrite($fh, "Moving " . $file['tmp_name'] . " to " . $filename . " using {$cmd_used} ==> [{$move_upl}]\n"); fclose($fh); if ($move_upl) { if ($chmod !== FALSE) { // Set permissions on filename chmod($filename, $chmod); } // Return new file path return $filename; } return FALSE; }
public function execute(array $options) { $db = $this->db_params($options['database']); $file = $options['file'] ? $options['file'] : Kohana::$config->load("migrations.path") . DIRECTORY_SEPARATOR . 'schema.sql'; if ($options['force'] === NULL or 'yes' === Minion_CLI::read("This will destroy database " . $db['database'] . " Are you sure? [yes/NO]")) { $command = strtr("mysql -u:username -p:password :database < :file ", array(':username' => $db['username'], ':password' => $db['password'], ':database' => $db['database'], ':file' => $file)); Minion_CLI::write('Loading data from ' . Debug::path($file) . ' to ' . $db['database'], 'green'); system($command); } else { Minion_CLI::write('Nothing done', 'brown'); } }
/** * Process asset content * * @param string $content * @param Asset $asset * * @return string */ public static function process($content, Asset $asset) { // Set error reporting $old = error_reporting(E_ALL & ~(E_NOTICE | E_DEPRECATED | E_STRICT)); // Set content CoffeeScript\Init::load(); $options = array('filename' => Debug::path($asset->source_file()), 'header' => FALSE); $content = CoffeeScript\Compiler::compile($content, $options); // Set error reporting error_reporting($old); return $content; }
protected function _execute(array $options) { $config = $this->config($options['name']); $config = array_merge($config, $options); $file = DOCROOT . $config['file']; $file = strtr($file, array(":timestamp" => strtotime('now'))); Minion_CLI::write('Generating ' . json_encode($config)); $filters = is_array($config['filter']) ? $config['filter'] : explode(',', $config['filter']); $content = $this->feed_content($config['model'], (array) $filters, $config['view']); Minion_CLI::write('Done.'); Minion_CLI::write('Saving feed content to ' . Debug::path($file)); file_put_contents($file, $content); Minion_CLI::write('Done.'); }
/** * Process asset content * * @param string $content * @param Asset $asset * @return string */ public static function process($content, Asset $asset) { // Set error reporting $old = error_reporting(E_ALL & ~(E_NOTICE | E_DEPRECATED | E_STRICT)); // Include the engine include_once Kohana::find_file('vendor/coffeescript/CoffeeScript', 'Init'); // Set content CoffeeScript\Init::load(); $options = array('filename' => Debug::path($asset->source_file()), 'header' => TRUE); $content = CoffeeScript\Compiler::compile($content, $options); // Set error reporting error_reporting($old); return $content; }
function create_dir($path) { if (!is_dir($path)) { try { // Create the directory mkdir($path, 0755, TRUE); // Set permissions (must be manually set to fix umask issues) chmod($path, 0755); } catch (Exception $e) { if (Kohana::$environment === Kohana::PRODUCTION) { throw new Kohana_Exception('Could not create directory :dir', array(':dir' => Debug::path($path))); } } } }
/** * Download a file to a new location. If no filename is provided, * the original filename will be used, with a unique prefix added. * * @param string $filename new filename * @param string $directory new directory * @param integer $chmod chmod mask * @return mixed array on success, upload style file array, false on failure */ public function download($filename = null, $directory = null, $chmod = 0644) { // If no filename given, use remote filename with uniqid $original_filename = basename(parse_url($this->_uri, PHP_URL_PATH)); if ($filename === null) { $filename = uniqid() . $original_filename; } // Remove spaces from the filename if (Upload::$remove_spaces === true) { $filename = preg_replace('/\\s+/', '_', $filename); } // Use the pre-configured upload directory if not given if ($directory === null) { $directory = Upload::$default_directory; } if (!is_dir($directory) || !is_writable(realpath($directory))) { throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Debug::path($directory))); } // Make the filename into a complete path $filename = realpath($directory) . DIRECTORY_SEPARATOR . $filename; // Download file try { $response = $this->execute(); if ($response->status() == 200) { $fh = fopen($filename, 'w'); fwrite($fh, $response->body()); $size = Arr::get(fstat($fh), 'size', 0); fclose($fh); } else { return false; } // Set permissions if ($chmod !== false) { chmod($filename, $chmod); } // Build file array $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($finfo, $filename); finfo_close($finfo); return array('error' => UPLOAD_ERR_OK, 'name' => $original_filename, 'type' => $mime, 'tmp_name' => $filename, 'size' => $size); } catch (Kohana_Exception $e) { return false; } }
public function action_index() { $value = $_FILES['upload']; if (is_array($value) and Ku_Upload::valid($value) and Ku_Upload::not_empty($value)) { $md5 = md5($value['name']); $save_path = DOCROOT . 'upload' . DIRECTORY_SEPARATOR . 'editor' . DIRECTORY_SEPARATOR . str_pad($this->site_id, 2, '0', STR_PAD_LEFT) . DIRECTORY_SEPARATOR . date('Y') . DIRECTORY_SEPARATOR . substr($md5, 0, 2) . DIRECTORY_SEPARATOR . substr($md5, 2, 2) . DIRECTORY_SEPARATOR; Ku_Dir::make_writable($save_path); $filename = Ku_File::safe_name($value['name'], TRUE, $this->max_filename_length); $prefix = uniqid() . '_'; while (file_exists($save_path . $prefix . $filename)) { $prefix = uniqid() . '_'; } $filename = Ku_Upload::save($value, $prefix . $filename, $save_path); $filename = 'upload' . str_replace(array(realpath(DOCROOT . 'upload'), DIRECTORY_SEPARATOR), array('', '/'), $filename); if (!$filename) { Kohana::$log->add(Log::ERROR, 'Exception occurred: :exception. [:file][:line] ', array(':file' => Debug::path(__FILE__), ':line' => __LINE__, ':exception' => 'File not saved')); } echo str_replace(array('{FUNCTION}', '{SRC}'), array(Request::initial()->query('CKEditorFuncNum'), URL::base() . $filename), $this->template); } }
/** * Set enabled modules for NegoCore platform. * * @param array $modules * @return array * @throws Kohana_Exception */ public static function modules(array $modules = null) { if ($modules === NULL) { // Not changing modules, just return the current set return Kohana::$_modules; } // Compose modules array $_modules = $modules; $modules = array(); foreach ($_modules as $provider => $module_list) { $modules += $module_list; } // Start a new list of include paths, APPPATH first $paths = array(APPPATH); foreach ($modules as $name => $path) { if (is_dir($path)) { // Add the module to include paths $paths[] = $modules[$name] = realpath($path) . DIRECTORY_SEPARATOR; } else { // This module is invalid, remove it throw new NegoCore_Exception('Attempted to load an invalid or missing module \':module\' at \':path\'', array(':module' => $name, ':path' => Debug::path($path))); } } // Finish the include paths by adding system paths $paths[] = NC_SYSPATH; $paths[] = KH_SYSPATH; // Set the new include paths Kohana::$_paths = $paths; // Set the current module list Kohana::$_modules = $modules; foreach (Kohana::$_modules as $path) { $init = $path . 'init' . EXT; if (is_file($init)) { // Include the module initialization file once require_once $init; } } return Kohana::$_modules; }
/** * Save the image. If the filename is omitted, the original image will * be overwritten. * * // Save the image as a PNG * $image->save('saved/cool.png'); * * // Overwrite the original image * $image->save(); * * [!!] If the file exists, but is not writable, an exception will be thrown. * * [!!] If the file does not exist, and the directory is not writable, an * exception will be thrown. * * @param string $file new image path * @param integer $quality quality of image: 1-100 * @return boolean * @uses Image::_save * @throws Kohana_Exception */ public function save($file = NULL, $quality = 100) { if ($file === NULL) { // Overwrite the file $file = $this->file; } if (is_file($file)) { if (!is_writable($file)) { throw new Kohana_Exception('File must be writable: :file', array(':file' => Debug::path($file))); } } else { // Get the directory of the file $directory = realpath(pathinfo($file, PATHINFO_DIRNAME)); if (!is_dir($directory) or !is_writable($directory)) { throw new Kohana_Exception('Directory must be writable: :directory', array(':directory' => Debug::path($directory))); } } // The quality must be in the range of 1 to 100 $quality = min(max($quality, 1), 100); return $this->_do_save($file, $quality); }
/** * Get a single line of text representing the exception: * * Error [ Code ]: Message ~ File [ Line ] * * @param Exception $e * @return string */ public static function text(Exception $e) { return sprintf('%s [ %s ]: %s ~ %s [ %d ]', get_class($e), $e->getCode(), strip_tags($e->getMessage()), Debug::path($e->getFile()), $e->getLine()); }
?> </a> (<?php echo count($included); ?> )</h3> <div id="<?php echo $env_id; ?> " class="collapsed"> <table cellspacing="0"> <?php foreach ($included as $file) { ?> <tr> <td><code><?php echo Debug::path($file); ?> </code></td> </tr> <?php } ?> </table> </div> <?php foreach (array('_SESSION', '_GET', '_POST', '_FILES', '_COOKIE', '_SERVER') as $var) { ?> <?php if (empty($GLOBALS[$var]) or !is_array($GLOBALS[$var])) { continue; }
</dd> <?php } } ?> </dl> <?php } ?> <p class="note"> <?php if ($path = $doc->class->getFilename()) { ?> Class declared in <tt><?php echo Debug::path($path); ?> </tt> on line <?php echo $doc->class->getStartLine(); ?> . <?php } else { ?> Class is not declared in a file, it is probably an internal <?php echo html::anchor('http://php.net/manual/class.' . strtolower($doc->class->name) . '.php', 'PHP class'); ?> . <?php } ?>
/** * Save an uploaded file to a temporary persistent directory. * * @param array uploaded file data * @param string temp directory for persistent uploaded files * @param integer chmod mask * @param string session key for persistent uploaded files * @param string path to saved file (useful if move_uploaded_file() already was called) * @return boolean TRUE if file temporary saved, FALSE if file not saved */ public static function persistent_save(array &$file, $directory = NULL, $chmod = NULL, $sess_key = NULL, $saved_file = NULL) { static $cache; $input_name = Arr::get($file, 'input_name'); if ($input_name === NULL) { return FALSE; } if ($cache === NULL) { $cache = array(); } elseif (isset($cache[$input_name])) { // This file already saved return FALSE; } $cache[$input_name] = TRUE; $valid_file = FALSE; if ($saved_file === NULL) { $valid_file = parent::not_empty($file); } else { $valid_file = (isset($file['error']) and isset($file['tmp_name']) and $file['error'] === UPLOAD_ERR_OK and is_string($saved_file) and is_file($saved_file) and filesize($saved_file) == $file['size']); } if ($valid_file) { // Use the default temp filename, with a prefix and a timestamp and uniquid prepended $filename = 'persistent~' . time() . '~' . uniqid() . '_' . basename($file['tmp_name']); if ($chmod === NULL) { // Use the pre-configured chmod value $chmod = Ku_Upload::$default_file_chmod; } if ($directory === NULL) { // Use the pre-configured persistent temp upload directory $directory = Ku_Upload::$persistent_temp_directory; } if (!is_dir($directory) or !is_writable(realpath($directory))) { throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Debug::path($directory))); } // Try save file to persistent directory $file_path = NULL; if ($saved_file === NULL) { $file_path = parent::save($file, $filename, $directory, $chmod); } else { if (rename($saved_file, $directory . '/' . $filename)) { $file_path = $directory . '/' . $filename; chmod($file_path, $chmod); } } if ($file_path) { $sess_key === NULL and $sess_key = Ku_Upload::persistent_key($input_name); $sess_file = $file; $sess_file['persistent'] = $file_path; // Remember full file path $sess_file['persistent_key'] = $sess_key; // Remember session key // Get all of the session data as an array $_SESSION =& Session::instance()->as_array(); // Save information about temporary saved file in the session $_SESSION['persistents'][$sess_key] = $sess_file; // Update file $file = $sess_file; // Update $_FILES $_FILES[$input_name] = $sess_file; return TRUE; } } return FALSE; }
/** * Helper for Debug::dump(), handles recursion in arrays and objects. * * @param mixed variable to dump * @param integer maximum length of strings * @param integer recursion level (internal) * @return string */ protected static function _dump(&$var, $length = 128, $level = 0) { if ($var === NULL) { return '<small>NULL</small>'; } elseif (is_bool($var)) { return '<small>bool</small> ' . ($var ? 'TRUE' : 'FALSE'); } elseif (is_float($var)) { return '<small>float</small> ' . $var; } elseif (is_resource($var)) { if (($type = get_resource_type($var)) === 'stream' and $meta = stream_get_meta_data($var)) { $meta = stream_get_meta_data($var); if (isset($meta['uri'])) { $file = $meta['uri']; if (function_exists('stream_is_local')) { // Only exists on PHP >= 5.2.4 if (stream_is_local($file)) { $file = Debug::path($file); } } return '<small>resource</small><span>(' . $type . ')</span> ' . htmlspecialchars($file, ENT_NOQUOTES, Kohana::$charset); } } else { return '<small>resource</small><span>(' . $type . ')</span>'; } } elseif (is_string($var)) { // Clean invalid multibyte characters. iconv is only invoked // if there are non ASCII characters in the string, so this // isn't too much of a hit. $var = UTF8::clean($var, Kohana::$charset); if (UTF8::strlen($var) > $length) { // Encode the truncated string $str = htmlspecialchars(UTF8::substr($var, 0, $length), ENT_NOQUOTES, Kohana::$charset) . ' …'; } else { // Encode the string $str = htmlspecialchars($var, ENT_NOQUOTES, Kohana::$charset); } return '<small>string</small><span>(' . strlen($var) . ')</span> "' . $str . '"'; } elseif (is_array($var)) { $output = array(); // Indentation for this variable $space = str_repeat($s = ' ', $level); static $marker; if ($marker === NULL) { // Make a unique marker $marker = uniqid(""); } if (empty($var)) { // Do nothing } elseif (isset($var[$marker])) { $output[] = "(\n{$space}{$s}*RECURSION*\n{$space})"; } elseif ($level < 5) { $output[] = "<span>("; $var[$marker] = TRUE; foreach ($var as $key => &$val) { if ($key === $marker) { continue; } if (!is_int($key)) { $key = '"' . htmlspecialchars($key, ENT_NOQUOTES, Kohana::$charset) . '"'; } $output[] = "{$space}{$s}{$key} => " . Debug::_dump($val, $length, $level + 1); } unset($var[$marker]); $output[] = "{$space})</span>"; } else { // Depth too great $output[] = "(\n{$space}{$s}...\n{$space})"; } return '<small>array</small><span>(' . count($var) . ')</span> ' . implode("\n", $output); } elseif (is_object($var)) { // Copy the object as an array $array = (array) $var; $output = array(); // Indentation for this variable $space = str_repeat($s = ' ', $level); $hash = spl_object_hash($var); // Objects that are being dumped static $objects = array(); if (empty($var)) { // Do nothing } elseif (isset($objects[$hash])) { $output[] = "{\n{$space}{$s}*RECURSION*\n{$space}}"; } elseif ($level < 10) { $output[] = "<code>{"; $objects[$hash] = TRUE; foreach ($array as $key => &$val) { if ($key[0] === "") { // Determine if the access is protected or protected $access = '<small>' . ($key[1] === '*' ? 'protected' : 'private') . '</small>'; // Remove the access level from the variable name $key = substr($key, strrpos($key, "") + 1); } else { $access = '<small>public</small>'; } $output[] = "{$space}{$s}{$access} {$key} => " . Debug::_dump($val, $length, $level + 1); } unset($objects[$hash]); $output[] = "{$space}}</code>"; } else { // Depth too great $output[] = "{\n{$space}{$s}...\n{$space}}"; } return '<small>object</small> <span>' . get_class($var) . '(' . count($array) . ')</span> ' . implode("\n", $output); } else { return '<small>' . gettype($var) . '</small> ' . htmlspecialchars(print_r($var, TRUE), ENT_NOQUOTES, Kohana::$charset); } }
public static function modules(array $modules = NULL) { if ($modules === NULL) { return JsonApiApplication::$_modules; } $paths = array(APPPATH); foreach ($modules as $name => $path) { if (is_dir($path)) { $paths[] = $modules[$name] = realpath($path) . DIRECTORY_SEPARATOR; } else { throw new JsonApiApplication_Exception('Attempted to load an invalid or missing module \':module\' at \':path\'', array(":module" => $name, ":path" => Debug::path($path))); } } $paths[] = SYSPATH; JsonApiApplication::$_paths = $paths; JsonApiApplication::$_modules = $modules; foreach (JsonApiApplication::$_modules as $path) { $init = $path . "init" . EXT; if (is_file($init)) { require_once $init; } } return JsonApiApplication::$_modules; }