Commit: 37ef60aa24d1601adcbd5b6f9569b9986f44c03c

Author: Nate Abele | Date: 2010-09-06 21:33:20 -0400
Implemented core exceptions. Implemented `\core\Libraries::instance()` to wrap service-location and instantiation of classes.
diff --git a/libraries/lithium/action/DispatchException.php b/libraries/lithium/action/DispatchException.php index 74e99e0..e17fa47 100644 --- a/libraries/lithium/action/DispatchException.php +++ b/libraries/lithium/action/DispatchException.php @@ -14,6 +14,8 @@ namespace lithium\action; * which aren't callable, or un-routable (private) controller methods. */ class DispatchException extends \RuntimeException { + + protected $code = 404; } ?> \ No newline at end of file diff --git a/libraries/lithium/action/Response.php b/libraries/lithium/action/Response.php index dc67d13..46d84ac 100644 --- a/libraries/lithium/action/Response.php +++ b/libraries/lithium/action/Response.php @@ -8,7 +8,7 @@ namespace lithium\action; -use \Exception; +use UnexpectedValueException; /** * A `Response` object is typically instantiated automatically by the `Controller`. It is assigned @@ -103,7 +103,7 @@ class Response extends \lithium\net\http\Response { } if (!$status = $this->status($code)) { - throw new Exception('Invalid status code'); + throw new UnexpectedValueException('Invalid status code'); } $this->_writeHeader($status); diff --git a/libraries/lithium/analysis/logger/adapter/Growl.php b/libraries/lithium/analysis/logger/adapter/Growl.php index 9bed264..a18a71c 100644 --- a/libraries/lithium/analysis/logger/adapter/Growl.php +++ b/libraries/lithium/analysis/logger/adapter/Growl.php @@ -8,8 +8,8 @@ namespace lithium\analysis\logger\adapter; -use \Exception; -use \lithium\util\Inflector; +use lithium\util\Inflector; +use lithium\core\NetworkException; /** * The `Growl` logger implements support for the [ Growl](http://growl.info/) notification system @@ -90,7 +90,7 @@ class Growl extends \lithium\core\Object { if ($conn = fsockopen($host, $port, $message, $code)) { return $conn; } - throw new Exception("Growl connection failed: ({$code}) {$message}"); + throw new NetworkException("Growl connection failed: ({$code}) {$message}"); } ); parent::__construct($config + $defaults); @@ -149,7 +149,7 @@ class Growl extends \lithium\core\Object { $data .= pack('H32', md5($data . $this->_config['password'])); if (fwrite($this->connection, $data, strlen($data)) === false) { - throw new Exception('Could not send notification to Growl Server.'); + throw new NetworkException('Could not send notification to Growl Server.'); } return true; } @@ -184,7 +184,7 @@ class Growl extends \lithium\core\Object { $data .= $checksum; if (fwrite($this->connection, $data, strlen($data)) === false) { - throw new Exception('Could not send registration to Growl Server.'); + throw new NetworkException('Could not send registration to Growl Server.'); } return $this->_registered = true; } diff --git a/libraries/lithium/core/Adaptable.php b/libraries/lithium/core/Adaptable.php index 93e7f86..0e6a4bd 100644 --- a/libraries/lithium/core/Adaptable.php +++ b/libraries/lithium/core/Adaptable.php @@ -8,10 +8,10 @@ namespace lithium\core; -use \Exception; -use \lithium\util\Collection; -use \lithium\core\Environment; -use \SplDoublyLinkedList; +use lithium\util\Collection; +use lithium\core\Environment; +use SplDoublyLinkedList; +use lithium\core\ConfigException; /** * The `Adaptable` static class is the base class from which all adapter implementations extend. @@ -101,7 +101,7 @@ class Adaptable extends \lithium\core\StaticObject { $config = static::_config($name); if ($config === null) { - throw new Exception("Configuration '{$name}' has not been defined."); + throw new ConfigException("Configuration '{$name}' has not been defined."); } if (isset($config['object'])) { @@ -126,7 +126,7 @@ class Adaptable extends \lithium\core\StaticObject { $config = static::_config($name); if ($config === null) { - throw new Exception("Configuration '{$name}' has not been defined."); + throw new ConfigException("Configuration '{$name}' has not been defined."); } if (!isset($config['strategies'])) { return null; @@ -213,11 +213,11 @@ class Adaptable extends \lithium\core\StaticObject { protected static function _class($config, $paths = array()) { if (!$name = $config['adapter']) { $self = get_called_class(); - throw new Exception("No adapter set for configuration in class {$self}."); + throw new ConfigException("No adapter set for configuration in class {$self}."); } if (!$class = static::_locate($paths, $name)) { $self = get_called_class(); - throw new Exception("Could not find adapter '{$name}' in class {$self}."); + throw new ConfigException("Could not find adapter '{$name}' in class {$self}."); } return $class; } @@ -233,11 +233,11 @@ class Adaptable extends \lithium\core\StaticObject { protected static function _strategy($name, $paths = array()) { if (!$name) { $self = get_called_class(); - throw new Exception("No strategy set for configuration in class {$self}."); + throw new ConfigException("No strategy set for configuration in class {$self}."); } if (!$class = static::_locate($paths, $name)) { $self = get_called_class(); - throw new Exception("Could not find strategy '{$name}' in class {$self}."); + throw new ConfigException("Could not find strategy '{$name}' in class {$self}."); } return $class; } diff --git a/libraries/lithium/core/ClassNotFoundException.php b/libraries/lithium/core/ClassNotFoundException.php new file mode 100644 index 0000000..72c9904 --- /dev/null +++ b/libraries/lithium/core/ClassNotFoundException.php @@ -0,0 +1,20 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +namespace lithium\core; + +/** + * A `ClassNotFoundException` may be thrown when a configured adapter or other service class defined + * in configuration can't be located. + */ +class ClassNotFoundException extends \RuntimeException { + + protected $code = 500; +} + +?> \ No newline at end of file diff --git a/libraries/lithium/core/ConfigException.php b/libraries/lithium/core/ConfigException.php new file mode 100644 index 0000000..f78d3ec --- /dev/null +++ b/libraries/lithium/core/ConfigException.php @@ -0,0 +1,20 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +namespace lithium\core; + +/** + * A `ConfigException` is thrown when a request is made to render content in a format not + * supported. + */ +class ConfigException extends \RuntimeException { + + protected $code = 500; +} + +?> \ No newline at end of file diff --git a/libraries/lithium/core/Libraries.php b/libraries/lithium/core/Libraries.php index a2bb770..4e9f5f8 100644 --- a/libraries/lithium/core/Libraries.php +++ b/libraries/lithium/core/Libraries.php @@ -8,9 +8,10 @@ namespace lithium\core; -use \Exception; -use \lithium\util\String; -use \InvalidArgumentException; +use RuntimeException; +use lithium\util\String; +use lithium\core\ConfigException; +use lithium\core\ClassNotFoundException; /** * Manages all aspects of class and file location, naming and mapping. Implements auto-loading for @@ -262,7 +263,7 @@ class Libraries { 'app' => LITHIUM_APP_PATH, 'root' => LITHIUM_LIBRARY_PATH ); if (!$config['path'] = static::_locatePath('libraries', $params)) { - throw new InvalidArgumentException("Library '{$name}' not found."); + throw new ConfigException("Library '{$name}' not found."); } } $config['path'] = str_replace('\\', '/', $config['path']); @@ -392,7 +393,7 @@ class Libraries { static::$_cachedPaths[$class] = $path; method_exists($class, '__init') ? $class::__init() : null; } elseif ($require) { - throw new Exception("Failed to load {$class} from {$path}"); + throw new RuntimeException("Failed to load {$class} from {$path}"); } } @@ -477,6 +478,26 @@ class Libraries { } /** + * Uses service location (i.e. `Libraries::locate()`) to look up a named class of a particular + * type, and creates an instance of it, and passes an array of parameters to the constructor. + * + * If the given class can't be found, an exception is thrown. + * + * @param string $type The type of class as defined by `Libraries::$_paths`. + * @param string $name The un-namespaced name of the class to instantiate. + * @param array $options An array of constructor parameters to pass to the class. + * @return object If the class is found, returns an instance of it, otherwise throws an + * exception. + * @throws lithium\core\ClassNotFoundException Throws an exception if the class can't be found. + */ + public static function instance($type, $name, array $options = array()) { + if (!$class = static::locate($type, $name)) { + throw new ClassNotFoundException("Class '{$name}' of type '{$type}' not found."); + } + return new $class($options); + } + + /** * Performs service location for an object of a specific type. If `$name` is a string, finds the * first instance of a class with the given name in any registered library (i.e. apps, plugins * or vendor libraries registered via `Libraries::add()`), based on each library's order of diff --git a/libraries/lithium/core/NetworkException.php b/libraries/lithium/core/NetworkException.php new file mode 100644 index 0000000..3f573e4 --- /dev/null +++ b/libraries/lithium/core/NetworkException.php @@ -0,0 +1,21 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +namespace lithium\core; + +/** + * A `NetworkException` may be thrown whenever an unsuccessful attempt is made to connect to a + * remote service over the network. This may be a web service, a database, or another network + * resource. + */ +class NetworkException extends \RuntimeException { + + protected $code = 503; +} + +?> \ No newline at end of file diff --git a/libraries/lithium/data/Entity.php b/libraries/lithium/data/Entity.php index 53f55d4..f3b4548 100644 --- a/libraries/lithium/data/Entity.php +++ b/libraries/lithium/data/Entity.php @@ -8,9 +8,9 @@ namespace lithium\data; -use \RuntimeException; -use \lithium\data\Source; -use \lithium\util\Collection as Col; +use BadMethodCallException; +use lithium\data\Source; +use lithium\util\Collection as Col; /** * `Entity` is a smart data object which represents data such as a row or document in a @@ -183,7 +183,9 @@ class Entity extends \lithium\core\Object { */ public function __call($method, $params) { if (!($model = $this->_model) || !method_exists($model, $method)) { - throw new RuntimeException("No model bound or unhandled method call '{$method}'."); + throw new BadMethodCallException( + "No model bound or unhandled method call '{$method}'." + ); } array_unshift($params, $this); $class = $model::invokeMethod('_object'); diff --git a/libraries/lithium/data/Model.php b/libraries/lithium/data/Model.php index 2e80e4f..48f0b88 100644 --- a/libraries/lithium/data/Model.php +++ b/libraries/lithium/data/Model.php @@ -8,11 +8,10 @@ namespace lithium\data; -use \lithium\util\Set; -use \lithium\util\Inflector; -use \RuntimeException; -use \UnexpectedValueException; -use \BadMethodCallException; +use lithium\util\Set; +use lithium\util\Inflector; +use lithium\core\ConfigException; +use BadMethodCallException; /** * The `Model` class is the starting point for the domain logic of your application. @@ -569,7 +568,7 @@ class Model extends \lithium\core\StaticObject { $self = static::_object(); if (!isset($self->_relationTypes[$type])) { - throw new RuntimeException("Invalid relationship type '{$type}' specified."); + throw new ConfigException("Invalid relationship type '{$type}' specified."); } $rel = static::_connection()->relationship(get_called_class(), $type, $name, $config); return static::_object()->_relations[$name] = $rel; @@ -847,12 +846,12 @@ class Model extends \lithium\core\StaticObject { $name = isset($self->_meta['connection']) ? $self->_meta['connection'] : null; if (!$name) { - throw new UnexpectedValueException("Connection name not defined"); + throw new ConfigException("Connection name not defined"); } if ($conn = $connections::get($name)) { return $conn; } - throw new RuntimeException("The data connection {$name} is not configured"); + throw new ConfigException("The data connection {$name} is not configured"); } /** diff --git a/libraries/lithium/data/model/Query.php b/libraries/lithium/data/model/Query.php index 7ed3899..ed932bf 100644 --- a/libraries/lithium/data/model/Query.php +++ b/libraries/lithium/data/model/Query.php @@ -8,8 +8,8 @@ namespace lithium\data\model; -use \Exception; -use \lithium\data\Source; +use lithium\data\Source; +use lithium\data\model\QueryException; /** * The `Query` class acts as a container for all information necessary to perform a particular @@ -437,7 +437,7 @@ class Query extends \lithium\core\Object { $config = array(); } if (!$relation = $model::relations($name)) { - throw new Exception("Related model not found"); + throw new QueryException("Related model not found"); } $config += $relation->data(); } diff --git a/libraries/lithium/data/model/QueryException.php b/libraries/lithium/data/model/QueryException.php new file mode 100644 index 0000000..e941d4d --- /dev/null +++ b/libraries/lithium/data/model/QueryException.php @@ -0,0 +1,22 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +namespace lithium\data\model; + +/** + * The `MediaException` is thrown when a request is made to render content in a format not + * supported. + * + * @see lithium\net\http\Media + */ +class QueryException extends \RuntimeException { + + protected $code = 500; +} + +?> \ No newline at end of file diff --git a/libraries/lithium/data/source/Database.php b/libraries/lithium/data/source/Database.php index 6d696ba..e546506 100644 --- a/libraries/lithium/data/source/Database.php +++ b/libraries/lithium/data/source/Database.php @@ -8,10 +8,10 @@ namespace lithium\data\source; -use \lithium\util\String; -use \lithium\core\Libraries; -use \lithium\util\Inflector; -use \InvalidArgumentException; +use lithium\util\String; +use lithium\core\Libraries; +use lithium\util\Inflector; +use InvalidArgumentException; /** * The `Database` class provides the base-level abstraction for SQL-oriented relational databases. diff --git a/libraries/lithium/data/source/MongoDb.php b/libraries/lithium/data/source/MongoDb.php index 11d70d8..6fa1bce 100644 --- a/libraries/lithium/data/source/MongoDb.php +++ b/libraries/lithium/data/source/MongoDb.php @@ -8,14 +8,15 @@ namespace lithium\data\source; -use \Mongo; -use \MongoId; -use \MongoCode; -use \MongoDBRef; -use \MongoRegex; -use \MongoGridFSFile; -use \lithium\util\Inflector; -use \Exception; +use Mongo; +use MongoId; +use MongoCode; +use MongoDBRef; +use MongoRegex; +use MongoGridFSFile; +use lithium\util\Inflector; +use lithium\core\NetworkException; +use Exception; /** * A data source adapter which allows you to connect to the MongoDB database engine. MongoDB is an @@ -729,7 +730,7 @@ class MongoDb extends \lithium\data\Source { protected function _checkConnection() { if (!$this->_isConnected && !$this->connect()) { - throw new Exception("Could not connect to the database."); + throw new NetworkException("Could not connect to the database."); } } } diff --git a/libraries/lithium/data/source/database/adapter/MySql.php b/libraries/lithium/data/source/database/adapter/MySql.php index e88010f..3e1ca96 100644 --- a/libraries/lithium/data/source/database/adapter/MySql.php +++ b/libraries/lithium/data/source/database/adapter/MySql.php @@ -8,7 +8,7 @@ namespace lithium\data\source\database\adapter; -use \Exception; +use lithium\data\model\QueryException; /** * Extends the `Database` class to implement the necessary SQL-formatting and resultset-fetching @@ -328,7 +328,7 @@ class MySql extends \lithium\data\source\Database { return $result; } list($code, $error) = $self->error(); - throw new Exception("{$sql}: {$error}", $code); + throw new QueryException("{$sql}: {$error}", $code); }); } diff --git a/libraries/lithium/data/source/database/adapter/Sqlite3.php b/libraries/lithium/data/source/database/adapter/Sqlite3.php index 2cc6500..7fafc56 100644 --- a/libraries/lithium/data/source/database/adapter/Sqlite3.php +++ b/libraries/lithium/data/source/database/adapter/Sqlite3.php @@ -9,9 +9,9 @@ namespace lithium\data\source\database\adapter; -use \Exception; -use \SQLite3 as SQLite; -use \SQLite3Result; +use SQLite3 as SQLite; +use SQLite3Result; +use lithium\data\model\QueryException; /** * Sqlite database driver @@ -283,7 +283,7 @@ class Sqlite3 extends \lithium\data\source\Database { $result = $conn->query($sql); if ( !($result instanceof SQLite3Result) ) { list($code, $error) = $self->error(); - throw new Exception("$sql: $error", $code); + throw new QueryException("$sql: $error", $code); } return $result; }); diff --git a/libraries/lithium/data/source/http/adapter/CouchDb.php b/libraries/lithium/data/source/http/adapter/CouchDb.php index 1afe8fc..c039e51 100644 --- a/libraries/lithium/data/source/http/adapter/CouchDb.php +++ b/libraries/lithium/data/source/http/adapter/CouchDb.php @@ -8,7 +8,7 @@ namespace lithium\data\source\http\adapter; -use \Exception; +use lithium\core\ConfigException; /** * CouchDb adapter @@ -134,7 +134,7 @@ class CouchDb extends \lithium\data\source\Http { } } if (!$this->_db) { - throw new Exception("{$entity} is not available."); + throw new ConfigException("{$entity} is not available."); } } diff --git a/libraries/lithium/g11n/catalog/adapter/Code.php b/libraries/lithium/g11n/catalog/adapter/Code.php index aadf1dc..ccbd7b0 100644 --- a/libraries/lithium/g11n/catalog/adapter/Code.php +++ b/libraries/lithium/g11n/catalog/adapter/Code.php @@ -8,10 +8,10 @@ namespace lithium\g11n\catalog\adapter; -use \Exception; -use \RecursiveIteratorIterator; -use \RecursiveDirectoryIterator; -use \lithium\template\view\Compiler; +use RecursiveIteratorIterator; +use RecursiveDirectoryIterator; +use lithium\core\ConfigException; +use lithium\template\view\Compiler; /** * The `Code` class is an adapter which treats files containing code as just another source @@ -48,7 +48,9 @@ class Code extends \lithium\g11n\catalog\Adapter { protected function _init() { parent::_init(); if (!is_dir($this->_config['path'])) { - throw new Exception("Code directory does not exist at `{$this->_config['path']}`"); + throw new ConfigException( + "Code directory does not exist at `{$this->_config['path']}`" + ); } } diff --git a/libraries/lithium/g11n/catalog/adapter/Gettext.php b/libraries/lithium/g11n/catalog/adapter/Gettext.php index e844fee..4ade215 100644 --- a/libraries/lithium/g11n/catalog/adapter/Gettext.php +++ b/libraries/lithium/g11n/catalog/adapter/Gettext.php @@ -8,7 +8,8 @@ namespace lithium\g11n\catalog\adapter; -use \Exception; +use RangeException; +use lithium\core\ConfigException; /** * The `Gettext` class is an adapter for reading and writing PO and MO files without the @@ -86,12 +87,12 @@ class Gettext extends \lithium\g11n\catalog\Adapter { * Initializer. Checks if the configured path exists. * * @return void - * @throws \Exception + * @throws ConfigException */ protected function _init() { parent::_init(); if (!is_dir($this->_config['path'])) { - throw new Exception("Gettext directory does not exist at `{$this->_config['path']}`"); + throw new ConfigException("Gettext directory does not exist at `{$this->_config['path']}`"); } } @@ -258,13 +259,13 @@ class Gettext extends \lithium\g11n\catalog\Adapter { * * @param resource $stream * @return array - * @throws Exception If stream content has an invalid format. + * @throws RangeException If stream content has an invalid format. */ protected function _parseMo($stream) { $stat = fstat($stream); if ($stat['size'] < self::MO_HEADER_SIZE) { - throw new Exception("MO stream caontent has an invalid format"); + throw new RangeException("MO stream caontent has an invalid format"); } $magic = unpack('V1', fread($stream, 4)); $magic = hexdec(substr(dechex(current($magic)), -8)); @@ -274,7 +275,7 @@ class Gettext extends \lithium\g11n\catalog\Adapter { } elseif ($magic == self::MO_BIG_ENDIAN_MAGIC) { $isBigEndian = true; } else { - throw new Exception("MO stream content has an invalid format"); + throw new RangeException("MO stream content has an invalid format"); } $header = array( diff --git a/libraries/lithium/g11n/catalog/adapter/Php.php b/libraries/lithium/g11n/catalog/adapter/Php.php index 02b7aa3..8435e62 100644 --- a/libraries/lithium/g11n/catalog/adapter/Php.php +++ b/libraries/lithium/g11n/catalog/adapter/Php.php @@ -8,7 +8,7 @@ namespace lithium\g11n\catalog\adapter; -use \Exception; +use lithium\core\ConfigException; /** * The `Php` class is an adapter for reading from PHP files which hold g11n data @@ -25,7 +25,7 @@ use \Exception; * ); * ?> * }}} - + * * The adapter works with a directory structure below. The example shows the structure * for the directory as given by the `'path'` configuration setting. It is similar to * the one used by the the `Gettext` adapter. @@ -71,7 +71,7 @@ class Php extends \lithium\g11n\catalog\Adapter { protected function _init() { parent::_init(); if (!is_dir($this->_config['path'])) { - throw new Exception("Php directory does not exist at `{$this->_config['path']}`"); + throw new ConfigException("Php directory does not exist at `{$this->_config['path']}`"); } } diff --git a/libraries/lithium/net/http/Media.php b/libraries/lithium/net/http/Media.php index b008301..7697995 100644 --- a/libraries/lithium/net/http/Media.php +++ b/libraries/lithium/net/http/Media.php @@ -8,9 +8,9 @@ namespace lithium\net\http; -use \RuntimeException; -use \lithium\util\String; -use \lithium\core\Libraries; +use lithium\util\String; +use lithium\core\Libraries; +use lithium\net\http\MediaException; /** * The `Media` class facilitates content-type mapping (mapping between content-types and file @@ -404,7 +404,7 @@ class Media extends \lithium\core\StaticObject { $handler = array_filter($handler, $filter) + $handlers['default'] + $defaults; if (!$hasHandler) { - throw new RuntimeException("Unhandled media type '{$type}'"); + throw new MediaException("Unhandled media type '{$type}'"); } if (isset($types[$type])) { @@ -509,7 +509,7 @@ class Media extends \lithium\core\StaticObject { case ($handler['template'] === false) && is_string($data): return $data; default: - throw new RuntimeException("Could not interpret type settings for handler."); + throw new MediaException("Could not interpret type settings for handler."); } return $result; }); diff --git a/libraries/lithium/net/http/MediaException.php b/libraries/lithium/net/http/MediaException.php new file mode 100644 index 0000000..c4223a8 --- /dev/null +++ b/libraries/lithium/net/http/MediaException.php @@ -0,0 +1,22 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +namespace lithium\net\http; + +/** + * The `MediaException` is thrown when a request is made to render content in a format not + * supported. + * + * @see lithium\net\http\Media + */ +class MediaException extends \RuntimeException { + + protected $code = 415; +} + +?> \ No newline at end of file diff --git a/libraries/lithium/net/socket/Stream.php b/libraries/lithium/net/socket/Stream.php index d5ff896..9bd52f4 100644 --- a/libraries/lithium/net/socket/Stream.php +++ b/libraries/lithium/net/socket/Stream.php @@ -8,7 +8,7 @@ namespace lithium\net\socket; -use \Exception; +use lithium\core\NetworkException; /** * A PHP stream-based socket adapter. @@ -46,7 +46,7 @@ class Stream extends \lithium\net\Socket { ); if (!empty($errorCode) || !empty($errorMessage)) { - throw new Exception($errorMessage, $errorCode); + throw new NetworkException($errorMessage); } $this->timeout($config['timeout']); diff --git a/libraries/lithium/security/Auth.php b/libraries/lithium/security/Auth.php index 1d514f2..c3b2ab8 100644 --- a/libraries/lithium/security/Auth.php +++ b/libraries/lithium/security/Auth.php @@ -8,7 +8,7 @@ namespace lithium\security; -use \Exception; +use lithium\core\ConfigException; /** * The `Auth` class provides a common interface to authenticate user credentials from different @@ -113,7 +113,7 @@ class Auth extends \lithium\core\Adaptable { $config = $self::invokeMethod('_config', array($name)); if ($config === null) { - throw new Exception("Configuration '{$name}' has not been defined."); + throw new ConfigException("Configuration '{$name}' has not been defined."); } $session = $config['session']; diff --git a/libraries/lithium/storage/session/adapter/Cache.php b/libraries/lithium/storage/session/adapter/Cache.php index e4a43f5..2bcdabe 100644 --- a/libraries/lithium/storage/session/adapter/Cache.php +++ b/libraries/lithium/storage/session/adapter/Cache.php @@ -8,6 +8,9 @@ namespace lithium\storage\session\adapter; +use RuntimeException; +use lithium\core\ConfigException; + /** * The `Cache` adapter is a simple session adapter which allows session data to be written to a * cache configuration. @@ -79,7 +82,7 @@ class Cache extends \lithium\core\Object { foreach ($this->_defaults as $key => $config) { if (isset($this->_config[$key])) { if (ini_set("session.{$key}", $this->_config[$key]) === false) { - throw new RuntimeException("Could not initialize the session."); + throw new ConfigException("Could not initialize the session."); } } } diff --git a/libraries/lithium/storage/session/adapter/Php.php b/libraries/lithium/storage/session/adapter/Php.php index 99acb5a..71823d0 100644 --- a/libraries/lithium/storage/session/adapter/Php.php +++ b/libraries/lithium/storage/session/adapter/Php.php @@ -8,8 +8,9 @@ namespace lithium\storage\session\adapter; -use \lithium\util\Set; -use \RuntimeException; +use lithium\util\Set; +use RuntimeException; +use lithium\core\ConfigException; /** * A minimal adapter to interface with native PHP sessions. @@ -61,7 +62,7 @@ class Php extends \lithium\core\Object { continue; } if (ini_set($key, $value) === false) { - throw new RuntimeException("Could not initialize the session."); + throw new ConfigException("Could not initialize the session."); } } } diff --git a/libraries/lithium/storage/session/strategy/Hmac.php b/libraries/lithium/storage/session/strategy/Hmac.php index 8f9f9da..cb3bdb4 100644 --- a/libraries/lithium/storage/session/strategy/Hmac.php +++ b/libraries/lithium/storage/session/strategy/Hmac.php @@ -8,8 +8,8 @@ namespace lithium\storage\session\strategy; -use \Exception; -use \RuntimeException; +use RuntimeException; +use lithium\core\ConfigException; /** * This strategy allows you to sign your `Session` and/or `Cookie` data with a passphrase @@ -56,7 +56,7 @@ class Hmac extends \lithium\core\Object { */ public function __construct(array $config = array()) { if (!isset($config['secret'])) { - throw new Exception("HMAC strategy requires a secret key."); + throw new ConfigException("HMAC strategy requires a secret key."); } static::$_secret = $config['secret']; } diff --git a/libraries/lithium/template/TemplateException.php b/libraries/lithium/template/TemplateException.php new file mode 100644 index 0000000..138297f --- /dev/null +++ b/libraries/lithium/template/TemplateException.php @@ -0,0 +1,21 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +namespace lithium\template; + +/** + * A `NetworkException` may be thrown whenever an unsuccessful attempt is made to connect to a + * remote service over the network. This may be a web service, a database, or another network + * resource. + */ +class TemplateException extends \RuntimeException { + + protected $code = 500; +} + +?> \ No newline at end of file diff --git a/libraries/lithium/template/View.php b/libraries/lithium/template/View.php index af3f11f..9d74bb9 100644 --- a/libraries/lithium/template/View.php +++ b/libraries/lithium/template/View.php @@ -138,11 +138,9 @@ class View extends \lithium\core\Object { $this->{'_' . $key} = $this->_config[$key]; continue; } - - if (!$class = Libraries::locate('adapter.template.view', $this->_config[$key])) { - throw new RuntimeException("Template adapter {$this->_config[$key]} not found"); - } - $this->{'_' . $key} = new $class(array('view' => $this) + $this->_config); + $class = $this->_config[$key]; + $config = array('view' => $this) + $this->_config; + $this->{'_' . $key} = Libraries::instance('adapter.template.view', $class, $config); } $h = function($data) { return htmlspecialchars((string) $data); }; diff --git a/libraries/lithium/template/view/Compiler.php b/libraries/lithium/template/view/Compiler.php index 34c9e7c..38038c3 100644 --- a/libraries/lithium/template/view/Compiler.php +++ b/libraries/lithium/template/view/Compiler.php @@ -8,7 +8,7 @@ namespace lithium\template\view; -use \Exception; +use lithium\template\TemplateException; /** * The template compiler is a simple string replacement engine which allows PHP templates to be @@ -74,7 +74,7 @@ class Compiler extends \lithium\core\StaticObject { if ($options['fallback']) { return $file; } - throw new Exception("Could not write compiled template {$template} to cache"); + throw new TemplateException("Could not write compiled template {$template} to cache"); } /** diff --git a/libraries/lithium/template/view/Renderer.php b/libraries/lithium/template/view/Renderer.php index 951edbe..358d41d 100644 --- a/libraries/lithium/template/view/Renderer.php +++ b/libraries/lithium/template/view/Renderer.php @@ -8,8 +8,8 @@ namespace lithium\template\view; -use \RuntimeException; -use \lithium\core\Libraries; +use RuntimeException; +use lithium\core\Libraries; /** * The `Renderer` abstract class serves as a base for all concrete `Renderer` adapters. diff --git a/libraries/lithium/template/view/adapter/File.php b/libraries/lithium/template/view/adapter/File.php index 40f8fdb..2365ca2 100644 --- a/libraries/lithium/template/view/adapter/File.php +++ b/libraries/lithium/template/view/adapter/File.php @@ -8,9 +8,9 @@ namespace lithium\template\view\adapter; -use \Exception; -use \lithium\util\String; -use \lithium\core\Libraries; +use lithium\util\String; +use lithium\core\Libraries; +use lithium\template\TemplateException; /** * The File adapter implements both template loading and rendering, and uses the `view\Stream` class @@ -171,7 +171,7 @@ class File extends \lithium\template\view\Renderer implements \ArrayAccess { return $path; } } - throw new Exception("Template not found at {$path}"); + throw new TemplateException("Template not found at {$path}"); } } diff --git a/libraries/lithium/test/Report.php b/libraries/lithium/test/Report.php index 812ab23..d08dbe3 100644 --- a/libraries/lithium/test/Report.php +++ b/libraries/lithium/test/Report.php @@ -8,9 +8,9 @@ namespace lithium\test; -use \Exception; -use \lithium\core\Libraries; -use \lithium\util\Inflector; +use lithium\core\Libraries; +use lithium\util\Inflector; +use lithium\core\ClassNotFoundException; /** * This `Report` object aggregates tests in a group and allows you to run said tests to @@ -241,7 +241,7 @@ class Report extends \lithium\core\Object { $results = array(); foreach ($filters as $filter => $options) { if (!$class = Libraries::locate('test.filter', $filter)) { - throw new Exception("{$class} is not a valid test filter."); + throw new ClassNotFoundException("{$class} is not a valid test filter."); } $options['name'] = strtolower(join('', array_slice(explode("\\", $class), -1))); $results[$class] = $options + array('apply' => array(), 'analyze' => array()); diff --git a/libraries/lithium/tests/cases/template/ViewTest.php b/libraries/lithium/tests/cases/template/ViewTest.php index d73ef03..8b4e741 100644 --- a/libraries/lithium/tests/cases/template/ViewTest.php +++ b/libraries/lithium/tests/cases/template/ViewTest.php @@ -35,9 +35,9 @@ class ViewTest extends \lithium\test\Unit { } public function testInitializationWithBadClasses() { - $this->expectException('Template adapter Badness not found'); + $this->expectException("Class 'Badness' of type 'adapter.template.view' not found."); new View(array('loader' => 'Badness')); - $this->expectException('Template adapter Badness not found'); + $this->expectException("Class 'Badness' of type 'adapter.template.view' not found."); new View(array('renderer' => 'Badness')); }