diff options
| author | 2017-12-17 20:28:04 +0100 | |
|---|---|---|
| committer | 2017-12-17 20:28:04 +0100 | |
| commit | 60f56539c3f30fd3f7ba4f2a3570f7029ac93e5f (patch) | |
| tree | 1e78bfac7042dceb63898e2215db8fb0c1d7745d /lib/Minz | |
| parent | ceda55c75b158fc1cf4813fe0f258527754b9289 (diff) | |
| parent | 0b1516af91792f86868689392f72ad4b6e32cdcf (diff) | |
Merge pull request #1720 from FreshRSS/dev
FreshRSS 1.9.0
Diffstat (limited to 'lib/Minz')
| -rw-r--r-- | lib/Minz/Dispatcher.php | 3 | ||||
| -rw-r--r-- | lib/Minz/ExtensionManager.php | 36 | ||||
| -rw-r--r-- | lib/Minz/Log.php | 34 |
3 files changed, 53 insertions, 20 deletions
diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php index bdb1c76f6..f05b285b5 100644 --- a/lib/Minz/Dispatcher.php +++ b/lib/Minz/Dispatcher.php @@ -10,7 +10,6 @@ * C'est un singleton */ class Minz_Dispatcher { - const CONTROLLERS_PATH_NAME = '/Controllers'; /* singleton */ private static $instance = null; @@ -149,7 +148,7 @@ class Minz_Dispatcher { */ private static function loadController($base_name) { $base_path = self::$registrations[$base_name]; - $controller_filename = $base_path . '/controllers/' . $base_name . 'Controller.php'; + $controller_filename = $base_path . '/Controllers/' . $base_name . 'Controller.php'; include_once $controller_filename; } diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php index c5c68a8d4..02a99701f 100644 --- a/lib/Minz/ExtensionManager.php +++ b/lib/Minz/ExtensionManager.php @@ -94,8 +94,8 @@ class Minz_ExtensionManager { * If the extension class name is `TestExtension`, entry point will be `Test`. * `entry_point` must be composed of alphanumeric characters. * - * @param $meta is an array of values. - * @return true if the array is valid, false else. + * @param array $meta is an array of values. + * @return bool true if the array is valid, false else. */ public static function isValidMetadata($meta) { $valid_chars = array('_'); @@ -107,8 +107,8 @@ class Minz_ExtensionManager { /** * Load the extension source code based on info metadata. * - * @param $info an array containing information about extension. - * @return an extension inheriting from Minz_Extension. + * @param array $info an array containing information about extension. + * @return Minz_Extension|null an extension inheriting from Minz_Extension. */ public static function load($info) { $entry_point_filename = $info['path'] . '/' . self::$ext_entry_point; @@ -127,9 +127,9 @@ class Minz_ExtensionManager { $extension = null; try { $extension = new $ext_class_name($info); - } catch (Minz_ExtensionException $e) { + } catch (Exception $e) { // We cannot load the extension? Invalid! - Minz_Log::warning('In `' . $metadata_filename . '`: ' . $e->getMessage()); + Minz_Log::warning('Invalid extension `' . $ext_class_name . '`: ' . $e->getMessage()); return null; } @@ -149,7 +149,7 @@ class Minz_ExtensionManager { * If the extension is present in $ext_auto_enabled and if its type is "system", * it will be enabled in the same time. * - * @param $ext a valid extension. + * @param Minz_Extension $ext a valid extension. */ public static function register($ext) { $name = $ext->getName(); @@ -168,7 +168,7 @@ class Minz_ExtensionManager { * * The extension init() method will be called. * - * @param $ext_name is the name of a valid extension present in $ext_list. + * @param Minz_Extension $ext_name is the name of a valid extension present in $ext_list. */ public static function enable($ext_name) { if (isset(self::$ext_list[$ext_name])) { @@ -182,7 +182,7 @@ class Minz_ExtensionManager { /** * Enable a list of extensions. * - * @param $ext_list the names of extensions we want to load. + * @param string[] $ext_list the names of extensions we want to load. */ public static function enableByList($ext_list) { foreach ($ext_list as $ext_name) { @@ -193,8 +193,8 @@ class Minz_ExtensionManager { /** * Return a list of extensions. * - * @param $only_enabled if true returns only the enabled extensions (false by default). - * @return an array of extensions. + * @param bool $only_enabled if true returns only the enabled extensions (false by default). + * @return Minz_Extension[] an array of extensions. */ public static function listExtensions($only_enabled = false) { if ($only_enabled) { @@ -207,8 +207,8 @@ class Minz_ExtensionManager { /** * Return an extension by its name. * - * @param $ext_name the name of the extension. - * @return the corresponding extension or null if it doesn't exist. + * @param string $ext_name the name of the extension. + * @return Minz_Extension|null the corresponding extension or null if it doesn't exist. */ public static function findExtension($ext_name) { if (!isset(self::$ext_list[$ext_name])) { @@ -224,9 +224,9 @@ class Minz_ExtensionManager { * The hook name must be a valid one. For the valid list, see self::$hook_list * array keys. * - * @param $hook_name the hook name (must exist). - * @param $hook_function the function name to call (must be callable). - * @param $ext the extension which register the hook. + * @param string $hook_name the hook name (must exist). + * @param callable $hook_function the function name to call (must be callable). + * @param Minz_Extension $ext the extension which register the hook. */ public static function addHook($hook_name, $hook_function, $ext) { if (isset(self::$hook_list[$hook_name]) && is_callable($hook_function)) { @@ -241,8 +241,8 @@ class Minz_ExtensionManager { * The hook name must be a valid one. For the valid list, see self::$hook_list * array keys. * - * @param $hook_name the hook to call. - * @param additionnal parameters (for signature, please see self::$hook_list). + * @param string $hook_name the hook to call. + * @param additional parameters (for signature, please see self::$hook_list). * @return the final result of the called hook. */ public static function callHook($hook_name) { diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php index 9559a0bd4..a8dbf8350 100644 --- a/lib/Minz/Log.php +++ b/lib/Minz/Log.php @@ -29,6 +29,7 @@ class Minz_Log { * @param $information message d'erreur / information à enregistrer * @param $level niveau d'erreur * @param $file_name fichier de log + * @throws Minz_PermissionDeniedException */ public static function record ($information, $level, $file_name = null) { try { @@ -70,6 +71,8 @@ class Minz_Log { . ' [' . $level_label . ']' . ' --- ' . $information . "\n"; + self::ensureMaxLogSize($file_name); + if (file_put_contents($file_name, $log, FILE_APPEND | LOCK_EX) === false) { throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR); } @@ -77,6 +80,37 @@ class Minz_Log { } /** + * Make sure we do not waste a huge amount of disk space with old log messages. + * + * This method can be called multiple times for one script execution, but its result will not change unless + * you call clearstatcache() in between. We won't due do that for performance reasons. + * + * @param $file_name + * @throws Minz_PermissionDeniedException + */ + protected static function ensureMaxLogSize($file_name) { + $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 1048576; + if ($maxSize > 0 && @filesize($file_name) > $maxSize) { + $fp = fopen($file_name, 'c+'); + if ($fp && flock($fp, LOCK_EX)) { + fseek($fp, -intval($maxSize / 2), SEEK_END); + $content = fread($fp, $maxSize); + rewind($fp); + ftruncate($fp, 0); + fwrite($fp, $content ? $content : ''); + fwrite($fp, sprintf("[%s] [notice] --- Log rotate.\n", date('r'))); + fflush($fp); + flock($fp, LOCK_UN); + } else { + throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR); + } + if ($fp) { + fclose($fp); + } + } + } + + /** * Automatise le log des variables globales $_GET et $_POST * Fait appel à la fonction record(...) * Ne fonctionne qu'en environnement "development" |
