Skip to content
Browse files

Implemented core exceptions. Implemented `\core\Libraries::instance()…

…` to wrap service-location and instantiation of classes.
  • Loading branch information...
1 parent e0417e5 commit 00ce46c5918545e5879d2b3880512bd4eebc218c @nateabele nateabele committed Sep 6, 2010
Showing with 263 additions and 107 deletions.
  1. +2 −0 libraries/lithium/action/DispatchException.php
  2. +2 −2 libraries/lithium/action/Response.php
  3. +5 −5 libraries/lithium/analysis/logger/adapter/Growl.php
  4. +10 −10 libraries/lithium/core/Adaptable.php
  5. +20 −0 libraries/lithium/core/ClassNotFoundException.php
  6. +20 −0 libraries/lithium/core/ConfigException.php
  7. +26 −5 libraries/lithium/core/Libraries.php
  8. +21 −0 libraries/lithium/core/NetworkException.php
  9. +6 −4 libraries/lithium/data/Entity.php
  10. +7 −8 libraries/lithium/data/Model.php
  11. +3 −3 libraries/lithium/data/model/Query.php
  12. +22 −0 libraries/lithium/data/model/QueryException.php
  13. +4 −4 libraries/lithium/data/source/Database.php
  14. +10 −9 libraries/lithium/data/source/MongoDb.php
  15. +2 −2 libraries/lithium/data/source/database/adapter/MySql.php
  16. +4 −4 libraries/lithium/data/source/database/adapter/Sqlite3.php
  17. +2 −2 libraries/lithium/data/source/http/adapter/CouchDb.php
  18. +7 −5 libraries/lithium/g11n/catalog/adapter/Code.php
  19. +7 −6 libraries/lithium/g11n/catalog/adapter/Gettext.php
  20. +3 −3 libraries/lithium/g11n/catalog/adapter/Php.php
  21. +5 −5 libraries/lithium/net/http/Media.php
  22. +22 −0 libraries/lithium/net/http/MediaException.php
  23. +2 −2 libraries/lithium/net/socket/Stream.php
  24. +2 −2 libraries/lithium/security/Auth.php
  25. +4 −1 libraries/lithium/storage/session/adapter/Cache.php
  26. +4 −3 libraries/lithium/storage/session/adapter/Php.php
  27. +3 −3 libraries/lithium/storage/session/strategy/Hmac.php
  28. +21 −0 libraries/lithium/template/TemplateException.php
  29. +3 −5 libraries/lithium/template/View.php
  30. +2 −2 libraries/lithium/template/view/Compiler.php
  31. +2 −2 libraries/lithium/template/view/Renderer.php
  32. +4 −4 libraries/lithium/template/view/adapter/File.php
  33. +4 −4 libraries/lithium/test/Report.php
  34. +2 −2 libraries/lithium/tests/cases/template/ViewTest.php
View
2 libraries/lithium/action/DispatchException.php
@@ -14,6 +14,8 @@
* which aren't callable, or un-routable (private) controller methods.
*/
class DispatchException extends \RuntimeException {
+
+ protected $code = 404;
}
?>
View
4 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 @@ public function render() {
}
if (!$status = $this->status($code)) {
- throw new Exception('Invalid status code');
+ throw new UnexpectedValueException('Invalid status code');
}
$this->_writeHeader($status);
View
10 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 @@ public function __construct(array $config = array()) {
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 @@ public function notify($description = '', $options = array()) {
$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 @@ protected function _register() {
$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;
}
View
20 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 @@ public static function adapter($name = null) {
$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 @@ public static function strategies($name) {
$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 @@ public static function enabled($name) {
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 @@ protected static function _class($config, $paths = array()) {
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;
}
View
20 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;
+}
+
+?>
View
20 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;
+}
+
+?>
View
31 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 @@ public static function add($name, array $config = array()) {
'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 @@ public static function load($class, $require = false) {
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 @@ protected static function _transformPath($transform, $class, array $options = ar
}
/**
+ * 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
View
21 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;
+}
+
+?>
View
10 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 @@ public function __isset($name) {
*/
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');
View
15 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 @@ public static function bind($type, $name, array $config = array()) {
$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 @@ protected static function &_connection() {
$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");
}
/**
View
6 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 @@ protected function _associate($related) {
$config = array();
}
if (!$relation = $model::relations($name)) {
- throw new Exception("Related model not found");
+ throw new QueryException("Related model not found");
}
$config += $relation->data();
}
View
22 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;
+}
+
+?>
View
8 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.
View
19 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 @@ protected function _toMongoId($data) {
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.");
}
}
}
View
4 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 @@ protected function _execute($sql, array $options = array()) {
return $result;
}
list($code, $error) = $self->error();
- throw new Exception("{$sql}: {$error}", $code);
+ throw new QueryException("{$sql}: {$error}", $code);
});
}
View
8 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 @@ protected function _execute($sql, array $options = array()) {
$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;
});
View
4 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 @@ public function describe($entity, array $meta = array()) {
}
}
if (!$this->_db) {
- throw new Exception("{$entity} is not available.");
+ throw new ConfigException("{$entity} is not available.");
}
}
View
12 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 @@ public function __construct(array $config = array()) {
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']}`"
+ );
}
}
View
13 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 @@ public function __construct(array $config = array()) {
* 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 @@ protected function _parsePot($stream) {
*
* @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 @@ protected function _parseMo($stream) {
} 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(
View
6 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 @@
* );
* ?>
* }}}
-
+ *
* 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 @@ public function __construct(array $config = array()) {
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']}`");
}
}
View
10 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 @@ public static function render(&$response, $data = null, array $options = array()
$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 @@ protected static function _handle($handler, $data, $options) {
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;
});
View
22 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;
+}
+
+?>
View
4 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 @@ public function open() {
);
if (!empty($errorCode) || !empty($errorMessage)) {
- throw new Exception($errorMessage, $errorCode);
+ throw new NetworkException($errorMessage);
}
$this->timeout($config['timeout']);
View
4 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 @@ public static function check($name, $credentials = null, array $options = array(
$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'];
View
5 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 @@ protected function _init() {
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.");
}
}
}
View
7 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 @@ protected function _init() {
continue;
}
if (ini_set($key, $value) === false) {
- throw new RuntimeException("Could not initialize the session.");
+ throw new ConfigException("Could not initialize the session.");
}
}
}
View
6 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'];
}
View
21 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;
+}
+
+?>
View
8 libraries/lithium/template/View.php
@@ -138,11 +138,9 @@ protected function _init() {
$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); };
View
4 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 @@ public static function template($file, array $options = array()) {
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");
}
/**
View
4 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.
View
8 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 @@ protected function _paths($paths, $options) {
return $path;
}
}
- throw new Exception("Template not found at {$path}");
+ throw new TemplateException("Template not found at {$path}");
}
}
View
8 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 @@ public function filters(array $filters = array()) {
$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());
View
4 libraries/lithium/tests/cases/template/ViewTest.php
@@ -35,9 +35,9 @@ public function testInitialization() {
}
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'));
}

0 comments on commit 00ce46c

Please sign in to comment.
Something went wrong with that request. Please try again.