Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Warning BC break, remove the automatic `__init()` calling from `lithi…

…um\core\Libraries`.
  • Loading branch information...
commit fa4ef11f88da7fd793e570f67db029a195c9602e 1 parent 81c873a
Simon JAILLET jails authored
89 core/ErrorHandler.php
View
@@ -57,49 +57,6 @@ class ErrorHandler extends \lithium\core\StaticObject {
protected static $_runOptions = array();
/**
- * Setup basic error handling checks/types, as well as register the error and exception
- * handlers.
- *
- * Called on static class initialization (i.e. when first loaded).
- *
- * @return void
- */
- public static function __init() {
- static::$_checks = array(
- 'type' => function($config, $info) {
- return (boolean) array_filter((array) $config['type'], function($type) use ($info) {
- return $type === $info['type'] || is_subclass_of($info['type'], $type);
- });
- },
- 'code' => function($config, $info) {
- return ($config['code'] & $info['code']);
- },
- 'stack' => function($config, $info) {
- return (boolean) array_intersect((array) $config['stack'], $info['stack']);
- },
- 'message' => function($config, $info) {
- return preg_match($config['message'], $info['message']);
- }
- );
- $self = get_called_class();
-
- static::$_exceptionHandler = function($exception, $return = false) use ($self) {
- if (ob_get_length()) {
- ob_end_clean();
- }
- $info = compact('exception') + array(
- 'type' => get_class($exception),
- 'stack' => $self::trace($exception->getTrace())
- );
- foreach (array('message', 'file', 'line', 'trace') as $key) {
- $method = 'get' . ucfirst($key);
- $info[$key] = $exception->{$method}();
- }
- return $return ? $info : $self::handle($info);
- };
- }
-
- /**
* Configure the `ErrorHandler`.
*
* @param array $config Configuration directives.
@@ -125,7 +82,6 @@ public static function config($config = array()) {
* where the error occurred. The exception will be caught at the first point in
* the stack trace inside a matching `try`/`catch` block, or that has a matching
* error handler applied using the `apply()` method.
- * @return void
*/
public static function run(array $config = array()) {
$defaults = array('trapErrors' => false, 'convertErrors' => true);
@@ -158,8 +114,6 @@ public static function run(array $config = array()) {
/**
* Returns the state of the `ErrorHandler`, indicating whether or not custom error/exception
* handers have been regsitered.
- *
- * @return void
*/
public static function isRunning() {
return static::$_isRunning;
@@ -169,8 +123,6 @@ public static function isRunning() {
* Unooks `ErrorHandler`'s exception and error handlers, and restores PHP's defaults. May have
* unexpected results if it is not matched with a prior call to `run()`, or if other error
* handlers are set after a call to `run()`.
- *
- * @return void
*/
public static function stop() {
restore_error_handler();
@@ -179,16 +131,46 @@ public static function stop() {
}
/**
- * Wipes out all configuration and resets the error handler to its initial state when loaded.
- * Mainly used for testing.
- *
- * @return void
+ * Setup basic error handling checks/types, as well as register the error and exception
+ * handlers and wipes out all configuration and resets the error handler to its initial state
+ * when loaded. Mainly used for testing.
*/
public static function reset() {
static::$_config = array();
static::$_checks = array();
static::$_exceptionHandler = null;
- static::__init();
+ static::$_checks = array(
+ 'type' => function($config, $info) {
+ return (boolean) array_filter((array) $config['type'], function($type) use ($info) {
+ return $type === $info['type'] || is_subclass_of($info['type'], $type);
+ });
+ },
+ 'code' => function($config, $info) {
+ return ($config['code'] & $info['code']);
+ },
+ 'stack' => function($config, $info) {
+ return (boolean) array_intersect((array) $config['stack'], $info['stack']);
+ },
+ 'message' => function($config, $info) {
+ return preg_match($config['message'], $info['message']);
+ }
+ );
+ $self = get_called_class();
+
+ static::$_exceptionHandler = function($exception, $return = false) use ($self) {
+ if (ob_get_length()) {
+ ob_end_clean();
+ }
+ $info = compact('exception') + array(
+ 'type' => get_class($exception),
+ 'stack' => $self::trace($exception->getTrace())
+ );
+ foreach (array('message', 'file', 'line', 'trace') as $key) {
+ $method = 'get' . ucfirst($key);
+ $info[$key] = $exception->{$method}();
+ }
+ return $return ? $info : $self::handle($info);
+ };
}
/**
@@ -323,4 +305,5 @@ public static function trace(array $stack) {
}
}
+ErrorHandler::reset();
?>
10 core/Libraries.php
View
@@ -484,9 +484,8 @@ public static function find($library, array $options = array()) {
}
/**
- * Loads the class definition specified by `$class`. Also calls the `__init()` method on the
- * class, if defined. Looks through the list of libraries defined in `$_configurations`, which
- * are added through `lithium\core\Libraries::add()`.
+ * Loads the class definition specified by `$class`. Looks through the list of libraries
+ * defined in `$_configurations`, which are added through `lithium\core\Libraries::add()`.
*
* @see lithium\core\Libraries::add()
* @see lithium\core\Libraries::path()
@@ -501,7 +500,10 @@ public static function load($class, $require = false) {
if ($path && include $path) {
static::$_cachedPaths[$class] = $path;
- method_exists($class, '__init') ? $class::__init() : null;
+ if (method_exists($class, '__init')) {
+ $msg = "Deprecated `{$class}::__init()` method, needs to be called it manually.";
+ throw new RuntimeException($msg);
+ }
} elseif ($require) {
throw new RuntimeException("Failed to load class `{$class}` from path `{$path}`.");
}
5 test/filter/Profiler.php
View
@@ -51,10 +51,8 @@ class Profiler extends \lithium\test\Filter {
/**
* Verifies that the corresponding function exists for each built-in profiler check.
* Initializes display formatters.
- *
- * @return void
*/
- public static function __init() {
+ public static function reset() {
foreach (static::$_metrics as $name => $check) {
$function = current((array) $check['function']);
@@ -243,4 +241,5 @@ public static function collect($filterResults) {
}
}
+Profiler::reset();
?>
6 tests/cases/core/LibrariesTest.php
View
@@ -12,6 +12,7 @@
use SplFileInfo;
use lithium\util\Inflector;
use lithium\core\Libraries;
+use lithium\tests\mocks\core\MockInitMethod;
class LibrariesTest extends \lithium\test\Unit {
@@ -773,6 +774,11 @@ public function testMe() {
$result = $object->testMe();
$this->assertEqual('patched class', $result);
}
+
+ public function testDeprectatedInit() {
+ $this->expectException("/Deprecated/");
+ MockInitMethod::li3();
+ }
}
?>
9 tests/cases/util/ValidatorTest.php
View
@@ -13,11 +13,10 @@
class ValidatorTest extends \lithium\test\Unit {
- public function setUp() {
- Validator::__init();
- }
+ public function setUp() {}
public function tearDown() {
+ Validator::reset();
Mocker::overwriteFunction(false);
}
@@ -85,7 +84,7 @@ public function testAddCustomRegexMethods() {
}
/**
- * Tests that the rules state is reset when calling `Validator::__init()`.
+ * Tests that the rules state is reset when calling `Validator::reset()`.
*/
public function testStateReset() {
$this->assertNull(Validator::rules('foo'));
@@ -93,7 +92,7 @@ public function testStateReset() {
Validator::add('foo', '/foo/');
$this->assertEqual('/foo/', Validator::rules('foo'));
- Validator::__init();
+ Validator::reset();
$this->assertNull(Validator::rules('foo'));
}
1  tests/integration/g11n/CatalogInflectorTest.php
View
@@ -18,7 +18,6 @@ class CatalogInflectorTest extends \lithium\test\Integration {
public function setUp() {
$this->_backup['catalogConfig'] = Catalog::config();
- Catalog::reset();
Catalog::config(array(
'runtime' => array('adapter' => new Memory())
));
3  tests/integration/g11n/CatalogValidatorTest.php
View
@@ -18,15 +18,14 @@ class CatalogValidatorTest extends \lithium\test\Integration {
public function setUp() {
$this->_backup['catalogConfig'] = Catalog::config();
- Catalog::reset();
Catalog::config(array(
'runtime' => array('adapter' => new Memory())
));
- Validator::__init();
}
public function tearDown() {
Catalog::reset();
+ Validator::reset();
Catalog::config($this->_backup['catalogConfig']);
}
1  tests/integration/g11n/ResourcesMessageTest.php
View
@@ -23,7 +23,6 @@ class ResourcesMessageTest extends \lithium\test\Integration {
public function setUp() {
$this->_backup['catalogConfig'] = Catalog::config();
- Catalog::reset();
Catalog::config(array(
'lithium' => array(
'adapter' => 'Php',
3  tests/integration/g11n/ResourcesValidatorTest.php
View
@@ -18,18 +18,17 @@ class ResourcesValidatorTest extends \lithium\test\Integration {
public function setUp() {
$this->_backup['catalogConfig'] = Catalog::config();
- Catalog::reset();
Catalog::config(array(
'lithium' => array(
'adapter' => 'Php',
'path' => Libraries::get('lithium', 'path') . '/g11n/resources/php'
)
));
- Validator::__init();
}
public function tearDown() {
Catalog::reset();
+ Validator::reset();
Catalog::config($this->_backup['catalogConfig']);
}
18 tests/mocks/core/MockInitMethod.php
View
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace lithium\tests\mocks\core;
+
+class MockInitMethod extends \lithium\core\StaticObject {
+
+ public static function __init() {}
+
+ public static function li3() {}
+}
+
+?>
4 tests/mocks/data/MockPostForValidates.php
View
@@ -35,7 +35,7 @@ class MockPostForValidates extends \lithium\data\Model {
)
);
- public static function __init() {
+ public static function init() {
$class = __CLASS__;
Validator::add('modelIsSet', function($value, $format, $options) use ($class) {
if (isset($options['model']) && $options['model'] = $class) {
@@ -46,4 +46,6 @@ public static function __init() {
}
}
+MockPostForValidates::init();
+
?>
7 util/Validator.php
View
@@ -172,10 +172,8 @@ class Validator extends \lithium\core\StaticObject {
/**
* Initializes the list of default validation rules.
- *
- * @return void
*/
- public static function __init() {
+ public static function reset() {
$alnum = '[A-Fa-f0-9]';
$class = get_called_class();
static::$_methodFilters[$class] = array();
@@ -444,7 +442,7 @@ public static function respondsTo($method, $internal = false) {
* will cause the validation rule to be skipped if the corresponding value
* is empty (an empty string or `null`). Defaults to `false`.
* - `'format'` _string_: If the validation rule has multiple format definitions
- * (see the `add()` or `__init()` methods), the name of the format to be used
+ * (see the `add()` or `init()` methods), the name of the format to be used
* can be specified here. Additionally, two special values can be used:
* either `'any'`, which means that all formats will be checked and the rule
* will pass if any format passes, or `'all'`, which requires all formats to
@@ -672,4 +670,5 @@ protected static function _checkFormats($rules) {
}
}
+Validator::reset();
?>
Please sign in to comment.
Something went wrong with that request. Please try again.