mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Making all core classes throw CakeException subclasses, this allows developers to catch framework exceptions with one catch.
Adding package specific exceptions. Replacing generic exceptions in the codebase with CakeException + package exceptions.
This commit is contained in:
parent
6c0efb62e7
commit
44c080d5ad
28 changed files with 146 additions and 86 deletions
|
@ -116,7 +116,7 @@ class ConsoleInputArgument {
|
|||
return true;
|
||||
}
|
||||
if (!in_array($value, $this->_choices)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
throw new ConsoleException(sprintf(
|
||||
__('"%s" is not a valid value for %s. Please use one of "%s"'),
|
||||
$value, $this->_name, implode(', ', $this->_choices)
|
||||
));
|
||||
|
|
|
@ -142,7 +142,7 @@ class ConsoleInputOption {
|
|||
return true;
|
||||
}
|
||||
if (!in_array($value, $this->_choices)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
throw new ConsoleException(sprintf(
|
||||
__('"%s" is not a valid value for --%s. Please use one of "%s"'),
|
||||
$value, $this->_name, implode(', ', $this->_choices)
|
||||
));
|
||||
|
|
|
@ -457,7 +457,7 @@ class ConsoleOptionParser {
|
|||
}
|
||||
foreach ($this->_args as $i => $arg) {
|
||||
if ($arg->isRequired() && !isset($args[$i]) && empty($params['help'])) {
|
||||
throw new RuntimeException(
|
||||
throw new ConsoleException(
|
||||
__('Missing required arguments. %s is required.', $arg->name())
|
||||
);
|
||||
}
|
||||
|
@ -552,7 +552,7 @@ class ConsoleOptionParser {
|
|||
*/
|
||||
protected function _parseOption($name, $params) {
|
||||
if (!isset($this->_options[$name])) {
|
||||
throw new InvalidArgumentException(__('Unknown option `%s`', $name));
|
||||
throw new ConsoleException(__('Unknown option `%s`', $name));
|
||||
}
|
||||
$option = $this->_options[$name];
|
||||
$isBoolean = $option->isBoolean();
|
||||
|
@ -586,7 +586,7 @@ class ConsoleOptionParser {
|
|||
}
|
||||
$next = count($args);
|
||||
if (!isset($this->_args[$next])) {
|
||||
throw new InvalidArgumentException(__('Too many arguments.'));
|
||||
throw new ConsoleException(__('Too many arguments.'));
|
||||
}
|
||||
|
||||
if ($this->_args[$next]->validChoice($argument)) {
|
||||
|
|
|
@ -102,7 +102,7 @@ class ShellDispatcher {
|
|||
protected function _initEnvironment() {
|
||||
if (!$this->__bootstrap()) {
|
||||
$message = "Unable to load CakePHP core.\nMake sure " . DS . 'cake' . DS . 'libs exists in ' . CAKE_CORE_INCLUDE_PATH;
|
||||
throw new RuntimeException($message);
|
||||
throw new CakeException($message);
|
||||
}
|
||||
|
||||
if (!isset($this->args[0]) || !isset($this->params['working'])) {
|
||||
|
@ -110,7 +110,7 @@ class ShellDispatcher {
|
|||
"Please make sure that " . DIRECTORY_SEPARATOR . "cake" . DIRECTORY_SEPARATOR . "console is in your system path,\n" .
|
||||
"and check the cookbook for the correct usage of this command.\n" .
|
||||
"(http://book.cakephp.org/)";
|
||||
throw new RuntimeException($message);
|
||||
throw new CakeException($message);
|
||||
}
|
||||
|
||||
$this->shiftArgs();
|
||||
|
|
|
@ -67,7 +67,7 @@ class Cache {
|
|||
* @param string $name Name of the configuration
|
||||
* @param array $settings Optional associative array of settings passed to the engine
|
||||
* @return array(engine, settings) on success, false on failure
|
||||
* @throws Exception
|
||||
* @throws CacheException
|
||||
*/
|
||||
public static function config($name = null, $settings = array()) {
|
||||
if (is_array($name)) {
|
||||
|
@ -113,10 +113,10 @@ class Cache {
|
|||
return false;
|
||||
}
|
||||
$cacheClass = $class . 'Engine';
|
||||
self::$_engines[$name] = new $cacheClass();
|
||||
if (!self::$_engines[$name] instanceof CacheEngine) {
|
||||
throw new Exception(__('Cache engines must use CacheEngine as a base class.'));
|
||||
if (!is_subclass_of($cacheClass, 'CacheEngine')) {
|
||||
throw new CacheException(__('Cache engines must use CacheEngine as a base class.'));
|
||||
}
|
||||
self::$_engines[$name] = new $cacheClass();
|
||||
if (self::$_engines[$name]->init($config)) {
|
||||
if (time() % self::$_engines[$name]->settings['probability'] === 0) {
|
||||
self::$_engines[$name]->gc();
|
||||
|
|
8
cake/libs/cache/file.php
vendored
8
cake/libs/cache/file.php
vendored
|
@ -249,20 +249,20 @@ class FileEngine extends CacheEngine {
|
|||
* Not implemented
|
||||
*
|
||||
* @return void
|
||||
* @throws BadMethodCallException
|
||||
* @throws CacheException
|
||||
*/
|
||||
public function decrement($key, $offset = 1) {
|
||||
throw new BadMethodCallException(__('Files cannot be atomically decremented.'));
|
||||
throw new CacheException(__('Files cannot be atomically decremented.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not implemented
|
||||
*
|
||||
* @return void
|
||||
* @throws BadMethodCallException
|
||||
* @throws CacheException
|
||||
*/
|
||||
public function increment($key, $offset = 1) {
|
||||
throw new BadMethodCallException(__('Files cannot be atomically incremented.'));
|
||||
throw new CacheException(__('Files cannot be atomically incremented.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
8
cake/libs/cache/memcache.php
vendored
8
cake/libs/cache/memcache.php
vendored
|
@ -148,11 +148,11 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @param integer $offset How much to increment
|
||||
* @param integer $duration How long to cache the data, in seconds
|
||||
* @return New incremented value, false otherwise
|
||||
* @throws RuntimeException when you try to increment with compress = true
|
||||
* @throws CacheException when you try to increment with compress = true
|
||||
*/
|
||||
public function increment($key, $offset = 1) {
|
||||
if ($this->settings['compress']) {
|
||||
throw new RuntimeException(
|
||||
throw new CacheException(
|
||||
__('Method increment() not implemented for compressed cache in %s', __CLASS__)
|
||||
);
|
||||
}
|
||||
|
@ -166,11 +166,11 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @param integer $offset How much to substract
|
||||
* @param integer $duration How long to cache the data, in seconds
|
||||
* @return New decremented value, false otherwise
|
||||
* @throws RuntimeException when you try to decrement with compress = true
|
||||
* @throws CacheException when you try to decrement with compress = true
|
||||
*/
|
||||
public function decrement($key, $offset = 1) {
|
||||
if ($this->settings['compress']) {
|
||||
throw new RuntimeException(
|
||||
throw new CacheException(
|
||||
__('Method decrement() not implemented for compressed cache in %s', __CLASS__)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -97,18 +97,18 @@ class CakeLog {
|
|||
* @param string $key The keyname for this logger, used to remove the logger later.
|
||||
* @param array $config Array of configuration information for the logger
|
||||
* @return boolean success of configuration.
|
||||
* @throws Exception
|
||||
* @throws CakeLogException
|
||||
*/
|
||||
public static function config($key, $config) {
|
||||
if (empty($config['engine'])) {
|
||||
throw new Exception(__('Missing logger classname'));
|
||||
throw new CakeLogException(__('Missing logger classname'));
|
||||
}
|
||||
$loggerName = $config['engine'];
|
||||
unset($config['engine']);
|
||||
$className = self::_getLogger($loggerName);
|
||||
$logger = new $className($config);
|
||||
if (!$logger instanceof CakeLogInterface) {
|
||||
throw new Exception(sprintf(
|
||||
throw new CakeLogException(sprintf(
|
||||
__('logger class %s does not implement a write method.'), $loggerName
|
||||
));
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ class CakeLog {
|
|||
}
|
||||
}
|
||||
if (!class_exists($loggerName)) {
|
||||
throw new Exception(__('Could not load class %s', $loggerName));
|
||||
throw new CakeLogException(__('Could not load class %s', $loggerName));
|
||||
}
|
||||
return $loggerName;
|
||||
}
|
||||
|
|
|
@ -426,7 +426,7 @@ class CakeRequest implements ArrayAccess {
|
|||
$type = strtolower(substr($name, 2));
|
||||
return $this->is($type);
|
||||
}
|
||||
throw new BadMethodCallException(sprintf('Method %s does not exist', $name));
|
||||
throw new CakeException(__('Method %s does not exist', $name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -448,13 +448,14 @@ class CakeResponse {
|
|||
*
|
||||
* @param integer $code
|
||||
* @return integer current status code
|
||||
* @throws CakeException When an unknown status code is reached.
|
||||
*/
|
||||
public function statusCode($code = null) {
|
||||
if (is_null($code)) {
|
||||
return $this->_status;
|
||||
}
|
||||
if (!isset($this->_statusCodes[$code])) {
|
||||
throw new OutOfRangeException(__('Unknown status code'));
|
||||
throw new CakeException(__('Unknown status code'));
|
||||
}
|
||||
return $this->_status = $code;
|
||||
}
|
||||
|
|
|
@ -265,7 +265,7 @@ class CakeSession {
|
|||
public static function delete($name) {
|
||||
if (self::check($name)) {
|
||||
if (in_array($name, self::$watchKeys)) {
|
||||
trigger_error(__('Deleting session key {%s}', $name), E_USER_NOTICE);
|
||||
throw new CakeSessionException(__('Deleting session key {%s}', $name));
|
||||
}
|
||||
self::__overwrite($_SESSION, Set::remove($_SESSION, $name));
|
||||
return (self::check($name) == false);
|
||||
|
@ -426,7 +426,6 @@ class CakeSession {
|
|||
*/
|
||||
public static function ignore($var) {
|
||||
if (!in_array($var, self::$watchKeys)) {
|
||||
debug("NOT");
|
||||
return;
|
||||
}
|
||||
foreach (self::$watchKeys as $i => $key) {
|
||||
|
@ -455,7 +454,7 @@ class CakeSession {
|
|||
}
|
||||
foreach ($write as $key => $val) {
|
||||
if (in_array($key, self::$watchKeys)) {
|
||||
trigger_error(__('Writing session key {%s}: %s', $key, var_export($val, true)), E_USER_NOTICE);
|
||||
throw new CakeSessionException(__('Writing session key {%s}: %s', $key, var_export($val, true)));
|
||||
}
|
||||
self::__overwrite($_SESSION, Set::insert($_SESSION, $key, $val));
|
||||
if (Set::classicExtract($_SESSION, $key) !== $val) {
|
||||
|
@ -495,7 +494,7 @@ class CakeSession {
|
|||
* Sessions can be configured with a few shortcut names as well as have any number of ini settings declared.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception Throws exceptions when ini_set() fails.
|
||||
* @throws CakeSessionException Throws exceptions when ini_set() fails.
|
||||
*/
|
||||
protected static function _configureSession() {
|
||||
$sessionConfig = Configure::read('Session');
|
||||
|
@ -527,7 +526,7 @@ class CakeSession {
|
|||
if (!empty($sessionConfig['ini']) && is_array($sessionConfig['ini'])) {
|
||||
foreach ($sessionConfig['ini'] as $setting => $value) {
|
||||
if (ini_set($setting, $value) === false) {
|
||||
throw new Exception(sprintf(
|
||||
throw new CakeSessionException(sprintf(
|
||||
__('Unable to configure the session, setting %s failed.'),
|
||||
$setting
|
||||
));
|
||||
|
@ -565,13 +564,13 @@ class CakeSession {
|
|||
App::import('Core', 'session/' . $class);
|
||||
}
|
||||
if (!class_exists($class)) {
|
||||
throw new Exception(__('Could not load %s to handle the session.', $class));
|
||||
throw new CakeSessionException(__('Could not load %s to handle the session.', $class));
|
||||
}
|
||||
$handler = new $class();
|
||||
if ($handler instanceof CakeSessionHandlerInterface) {
|
||||
return $handler;
|
||||
}
|
||||
throw new Exception(__('Chosen SessionHandler does not implement CakeSessionHandlerInterface it cannot be used with an engine key.'));
|
||||
throw new CakeSessionException(__('Chosen SessionHandler does not implement CakeSessionHandlerInterface it cannot be used with an engine key.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,12 +51,12 @@ class PhpReader implements ConfigReaderInterface {
|
|||
* @param string $key The identifier to read from. If the key has a . it will be treated
|
||||
* as a plugin prefix.
|
||||
* @return array Parsed configuration values.
|
||||
* @throws RuntimeException when files don't exist or they don't contain `$config`.
|
||||
* InvalidArgumentException when files contain '..' as this could lead to abusive reads.
|
||||
* @throws ConfigureException when files don't exist or they don't contain `$config`.
|
||||
* Or when files contain '..' as this could lead to abusive reads.
|
||||
*/
|
||||
public function read($key) {
|
||||
if (strpos($key, '..') !== false) {
|
||||
throw new InvalidArgumentException(__('Cannot load configuration files with ../ in them.'));
|
||||
throw new ConfigureException(__('Cannot load configuration files with ../ in them.'));
|
||||
}
|
||||
list($plugin, $key) = pluginSplit($key);
|
||||
|
||||
|
@ -66,11 +66,11 @@ class PhpReader implements ConfigReaderInterface {
|
|||
$file = $this->_path . $key . '.php';
|
||||
}
|
||||
if (!file_exists($file)) {
|
||||
throw new RuntimeException(__('Could not load configuration file: ') . $file);
|
||||
throw new ConfigureException(__('Could not load configuration file: ') . $file);
|
||||
}
|
||||
include $file;
|
||||
if (!isset($config)) {
|
||||
throw new RuntimeException(
|
||||
throw new ConfigureException(
|
||||
sprintf(__('No variable $config found in %s.php'), $file)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -325,7 +325,7 @@ class Configure {
|
|||
* @param string $key name of configuration resource to load.
|
||||
* @param string $config Name of the configured reader to use to read the resource identfied by $key.
|
||||
* @return mixed false if file not found, void if load successful.
|
||||
* @throws Exception Will throw any exceptions the reader raises.
|
||||
* @throws ConfigureException Will throw any exceptions the reader raises.
|
||||
*/
|
||||
public static function load($key, $config = 'default') {
|
||||
if (!isset(self::$_readers[$config])) {
|
||||
|
|
|
@ -58,7 +58,7 @@ class AclComponent extends Component {
|
|||
/**
|
||||
* Constructor. Will return an instance of the correct ACL class as defined in `Configure::read('Acl.classname')`
|
||||
*
|
||||
* @throws Exception when Acl.classname could not be loaded.
|
||||
* @throws CakeException when Acl.classname could not be loaded.
|
||||
*/
|
||||
public function __construct(ComponentCollection $collection, $settings = array()) {
|
||||
parent::__construct($collection, $settings);
|
||||
|
@ -68,7 +68,7 @@ class AclComponent extends Component {
|
|||
list($plugin, $name) = pluginSplit($name);
|
||||
$name .= 'Component';
|
||||
} else {
|
||||
throw new Exception(__('Could not find %s.', $name));
|
||||
throw new CakeException(__('Could not find %s.', $name));
|
||||
}
|
||||
}
|
||||
$this->adapter($name);
|
||||
|
@ -84,7 +84,7 @@ class AclComponent extends Component {
|
|||
*
|
||||
* @param mixed $adapter Instance of AclBase or a string name of the class to use. (optional)
|
||||
* @return mixed either null, or instance of AclBase
|
||||
* @throws Exception when the given class is not an AclBase
|
||||
* @throws CakeException when the given class is not an AclBase
|
||||
*/
|
||||
public function adapter($adapter = null) {
|
||||
if ($adapter) {
|
||||
|
@ -92,7 +92,7 @@ class AclComponent extends Component {
|
|||
$adapter = new $adapter();
|
||||
}
|
||||
if (!$adapter instanceof AclInterface) {
|
||||
throw new Exception(__('AclComponent adapters must implement AclInterface'));
|
||||
throw new CakeException(__('AclComponent adapters must implement AclInterface'));
|
||||
}
|
||||
$this->_Instance = $adapter;
|
||||
$this->_Instance->initialize($this);
|
||||
|
|
|
@ -388,3 +388,61 @@ class MissingTableException extends CakeException {
|
|||
class MissingModelException extends CakeException {
|
||||
protected $_messageTemplate = 'Model %s could not be found.';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Exception class for Cache. This exception will be thrown from Cache when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package cake.libs
|
||||
*/
|
||||
class CacheException extends CakeException { }
|
||||
|
||||
/**
|
||||
* Exception class for Router. This exception will be thrown from Router when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package cake.libs
|
||||
*/
|
||||
class RouterException extends CakeException { }
|
||||
|
||||
/**
|
||||
* Exception class for CakeLog. This exception will be thrown from CakeLog when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package cake.libs
|
||||
*/
|
||||
class CakeLogException extends CakeException { }
|
||||
|
||||
/**
|
||||
* Exception class for CakeSession. This exception will be thrown from CakeSession when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package cake.libs
|
||||
*/
|
||||
class CakeSessionException extends CakeException { }
|
||||
|
||||
/**
|
||||
* Exception class for Configure. This exception will be thrown from Configure when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package cake.libs
|
||||
*/
|
||||
class ConfigureException extends CakeException { }
|
||||
|
||||
/**
|
||||
* Exception class for Xml. This exception will be thrown from Xml when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package cake.libs
|
||||
*/
|
||||
class XmlException extends CakeException { }
|
||||
|
||||
/**
|
||||
* Exception class for Console libraries. This exception will be thrown from Console library
|
||||
* classes when they encounter an error.
|
||||
*
|
||||
* @package cake.libs
|
||||
*/
|
||||
class ConsoleException extends CakeException { }
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@ class Router {
|
|||
* shifted into the passed arguments. As well as supplying patterns for routing parameters.
|
||||
* @see routes
|
||||
* @return array Array of routes
|
||||
* @throws Exception
|
||||
* @throws RouterException
|
||||
*/
|
||||
public static function connect($route, $defaults = array(), $options = array()) {
|
||||
foreach (self::$_prefixes as $prefix) {
|
||||
|
@ -246,13 +246,12 @@ class Router {
|
|||
$routeClass = 'CakeRoute';
|
||||
if (isset($options['routeClass'])) {
|
||||
$routeClass = $options['routeClass'];
|
||||
if (!is_subclass_of($routeClass, 'CakeRoute')) {
|
||||
throw new RouterException(__('Route classes must extend CakeRoute'));
|
||||
}
|
||||
unset($options['routeClass']);
|
||||
}
|
||||
$Route = new $routeClass($route, $defaults, $options);
|
||||
if (!$Route instanceof CakeRoute) {
|
||||
throw new Exception(__('Route classes must extend CakeRoute'));
|
||||
}
|
||||
self::$routes[] =& $Route;
|
||||
self::$routes[] = new $routeClass($route, $defaults, $options);
|
||||
return self::$routes;
|
||||
}
|
||||
|
||||
|
|
|
@ -1136,11 +1136,12 @@ class FormHelper extends AppHelper {
|
|||
* @param string $method Method name / input type to make.
|
||||
* @param array $params Parameters for the method call
|
||||
* @return string Formatted input method.
|
||||
* @throws CakeException When there are no params for the method call.
|
||||
*/
|
||||
public function __call($method, $params) {
|
||||
$options = array();
|
||||
if (empty($params)) {
|
||||
throw new Exception(__('Missing field name for FormHelper::%s', $method));
|
||||
throw new CakeException(__('Missing field name for FormHelper::%s', $method));
|
||||
}
|
||||
if (isset($params[1])) {
|
||||
$options = $params[1];
|
||||
|
|
|
@ -87,7 +87,7 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* @param View $View the view object the helper is attached to.
|
||||
* @param array $settings Array of settings.
|
||||
* @return void
|
||||
* @throws CakeException When the AjaxProvider helper does not implement a link method.
|
||||
*/
|
||||
function __construct(View $View, $settings = array()) {
|
||||
parent::__construct($View, $settings);
|
||||
|
@ -99,7 +99,7 @@ class PaginatorHelper extends AppHelper {
|
|||
}
|
||||
$classname = $ajaxProvider . 'Helper';
|
||||
if (!method_exists($classname, 'link')) {
|
||||
throw new Exception(sprintf(
|
||||
throw new CakeException(sprintf(
|
||||
__('%s does not implement a link() method, it is incompatible with PaginatorHelper'), $classname
|
||||
));
|
||||
}
|
||||
|
|
|
@ -385,6 +385,7 @@ class View extends Object {
|
|||
* @param string $layout Layout to use
|
||||
* @param string $file Custom filename for view
|
||||
* @return string Rendered Element
|
||||
* @throws CakeException if there is an error in the view.
|
||||
*/
|
||||
public function render($action = null, $layout = null, $file = null) {
|
||||
if ($this->hasRendered) {
|
||||
|
@ -409,7 +410,7 @@ class View extends Object {
|
|||
$layout = $this->layout;
|
||||
}
|
||||
if ($this->output === false) {
|
||||
throw new RuntimeException(__("Error in view %s, got no content.", $viewFileName));
|
||||
throw new CakeException(__("Error in view %s, got no content.", $viewFileName));
|
||||
}
|
||||
if ($layout && $this->autoLayout) {
|
||||
$this->output = $this->renderLayout($this->output, $layout);
|
||||
|
@ -428,6 +429,7 @@ class View extends Object {
|
|||
*
|
||||
* @param string $content_for_layout Content to render in a view, wrapped by the surrounding layout.
|
||||
* @return mixed Rendered output, or false on error
|
||||
* @throws CakeException if there is an error in the view.
|
||||
*/
|
||||
public function renderLayout($content_for_layout, $layout = null) {
|
||||
$layoutFileName = $this->_getLayoutFileName($layout);
|
||||
|
@ -451,7 +453,7 @@ class View extends Object {
|
|||
$this->output = $this->_render($layoutFileName);
|
||||
|
||||
if ($this->output === false) {
|
||||
throw new RuntimeException(__("Error in layout %s, got no content.", $layoutFileName));
|
||||
throw new CakeException(__("Error in layout %s, got no content.", $layoutFileName));
|
||||
}
|
||||
|
||||
$this->Helpers->trigger('afterLayout', array($layoutFileName));
|
||||
|
|
|
@ -73,7 +73,7 @@ class Xml {
|
|||
* @param mixed $input XML string, a path to a file, an URL or an array
|
||||
* @param array $options The options to use
|
||||
* @return object SimpleXMLElement or DOMDocument
|
||||
* @throws Exception
|
||||
* @throws XmlException
|
||||
*/
|
||||
public static function build($input, $options = array()) {
|
||||
if (!is_array($options)) {
|
||||
|
@ -101,9 +101,9 @@ class Xml {
|
|||
$dom->load($input);
|
||||
return $dom;
|
||||
} elseif (!is_string($input)) {
|
||||
throw new Exception(__('Invalid input.'));
|
||||
throw new XmlException(__('Invalid input.'));
|
||||
}
|
||||
throw new Exception(__('XML cannot be read.'));
|
||||
throw new XmlException(__('XML cannot be read.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,14 +141,15 @@ class Xml {
|
|||
* @param array $input Array with data
|
||||
* @param array $options The options to use
|
||||
* @return object SimpleXMLElement or DOMDocument
|
||||
* @throws XmlException
|
||||
*/
|
||||
public static function fromArray($input, $options = array()) {
|
||||
if (!is_array($input) || count($input) !== 1) {
|
||||
throw new Exception(__('Invalid input.'));
|
||||
throw new XmlException(__('Invalid input.'));
|
||||
}
|
||||
$key = key($input);
|
||||
if (is_integer($key)) {
|
||||
throw new Exception(__('The key of input must be alphanumeric'));
|
||||
throw new XmlException(__('The key of input must be alphanumeric'));
|
||||
}
|
||||
|
||||
if (!is_array($options)) {
|
||||
|
@ -212,7 +213,7 @@ class Xml {
|
|||
}
|
||||
} else {
|
||||
if ($key[0] === '@') {
|
||||
throw new Exception(__('Invalid array'));
|
||||
throw new XmlException(__('Invalid array'));
|
||||
}
|
||||
if (array_keys($value) === range(0, count($value) - 1)) { // List
|
||||
foreach ($value as $item) {
|
||||
|
@ -225,7 +226,7 @@ class Xml {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
throw new Exception(__('Invalid array'));
|
||||
throw new XmlException(__('Invalid array'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -270,13 +271,14 @@ class Xml {
|
|||
*
|
||||
* @param object $obj SimpleXMLElement, DOMDocument or DOMNode instance
|
||||
* @return array Array representation of the XML structure.
|
||||
* @throws XmlException
|
||||
*/
|
||||
public static function toArray($obj) {
|
||||
if ($obj instanceof DOMNode) {
|
||||
$obj = simplexml_import_dom($obj);
|
||||
}
|
||||
if (!($obj instanceof SimpleXMLElement)) {
|
||||
throw new Exception(__('The input is not instance of SimpleXMLElement, DOMDocument or DOMNode.'));
|
||||
throw new XmlException(__('The input is not instance of SimpleXMLElement, DOMDocument or DOMNode.'));
|
||||
}
|
||||
$result = array();
|
||||
$namespaces = array_merge(array('' => ''), $obj->getNamespaces(true));
|
||||
|
|
|
@ -230,7 +230,7 @@ class ConsoleOptionParserTest extends CakeTestCase {
|
|||
/**
|
||||
* test parsing options that do not exist.
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedException ConsoleException
|
||||
*/
|
||||
function testOptionThatDoesNotExist() {
|
||||
$parser = new ConsoleOptionParser('test', false);
|
||||
|
@ -242,7 +242,7 @@ class ConsoleOptionParserTest extends CakeTestCase {
|
|||
/**
|
||||
* test that options with choices enforce them.
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedException ConsoleException
|
||||
* @return void
|
||||
*/
|
||||
function testOptionWithChoices() {
|
||||
|
@ -297,7 +297,7 @@ class ConsoleOptionParserTest extends CakeTestCase {
|
|||
/**
|
||||
* test parsing arguments.
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedException ConsoleException
|
||||
* @return void
|
||||
*/
|
||||
function testParseArgumentTooMany() {
|
||||
|
@ -315,7 +315,7 @@ class ConsoleOptionParserTest extends CakeTestCase {
|
|||
/**
|
||||
* test that when there are not enough arguments an exception is raised
|
||||
*
|
||||
* @expectedException RuntimeException
|
||||
* @expectedException ConsoleException
|
||||
* @return void
|
||||
*/
|
||||
function testPositionalArgNotEnough() {
|
||||
|
@ -329,7 +329,7 @@ class ConsoleOptionParserTest extends CakeTestCase {
|
|||
/**
|
||||
* test that arguments with choices enforce them.
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedException ConsoleException
|
||||
* @return void
|
||||
*/
|
||||
function testPositionalArgWithChoices() {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* @since CakePHP(tm) v 1.2.0.5432
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', 'Log');
|
||||
App::import('Core', 'CakeLog');
|
||||
App::import('Core', 'log/FileLog');
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
/**
|
||||
* test all the errors from failed logger imports
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedException CakeLogException
|
||||
* @return void
|
||||
*/
|
||||
function testImportingLoggerFailure() {
|
||||
|
@ -80,7 +80,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
/**
|
||||
* test that loggers have to implement the correct interface.
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedException CakeLogException
|
||||
* @return void
|
||||
*/
|
||||
function testNotImplementingInterface() {
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
if (!class_exists('dispatcher')) {
|
||||
require CAKE . 'dispatcher.php';
|
||||
}
|
||||
App::import('Core', 'Dispatcher');
|
||||
App::import('Core', 'CakeRequest');
|
||||
|
||||
class CakeRequestTestCase extends CakeTestCase {
|
||||
|
@ -614,7 +612,7 @@ class CakeRequestTestCase extends CakeTestCase {
|
|||
/**
|
||||
* test __call expcetions
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedException CakeException
|
||||
* @return void
|
||||
*/
|
||||
function test__callExceptionOnUnknownMethod() {
|
||||
|
|
|
@ -55,7 +55,7 @@ class CakeResponseTestCase extends CakeTestCase {
|
|||
/**
|
||||
* Tests the statusCode method
|
||||
*
|
||||
* @expectedException OutOfRangeException
|
||||
* @expectedException CakeException
|
||||
*/
|
||||
public function testStatusCode() {
|
||||
$response = new CakeResponse();
|
||||
|
|
|
@ -367,7 +367,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
/**
|
||||
* testWatchVar method
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedException CakeSessionException
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -380,16 +380,16 @@ class CakeSessionTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
* Test that deleting watched vars causes exceptions
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedException CakeSessionException
|
||||
* @return void
|
||||
*/
|
||||
function testWatchVarDelete() {
|
||||
TestCakeSession::write('Watching', 'I am watching you.');
|
||||
|
||||
TestCakeSession::watch('Watching');
|
||||
TestCakeSession::delete('Watching');
|
||||
|
||||
$this->assertFalse(TestCakeSession::watch('Invalid.key'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,7 +44,7 @@ class PhpReaderTest extends CakeTestCase {
|
|||
/**
|
||||
* Test an exception is thrown by reading files that don't exist.
|
||||
*
|
||||
* @expectedException RuntimeException
|
||||
* @expectedException ConfigureException
|
||||
* @return void
|
||||
*/
|
||||
function testReadWithNonExistantFile() {
|
||||
|
@ -66,7 +66,7 @@ class PhpReaderTest extends CakeTestCase {
|
|||
/**
|
||||
* test reading keys with ../ doesn't work
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedException ConfigureException
|
||||
* @return void
|
||||
*/
|
||||
function testReadWithDots() {
|
||||
|
|
|
@ -218,7 +218,7 @@ class AclComponentTest extends CakeTestCase {
|
|||
* test that construtor throws an exception when Acl.classname is a
|
||||
* non-existant class
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedException CakeException
|
||||
* @return void
|
||||
*/
|
||||
function testConstrutorException() {
|
||||
|
@ -243,7 +243,7 @@ class AclComponentTest extends CakeTestCase {
|
|||
/**
|
||||
* test that adapter() whines when the class is not an AclBase
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedException CakeException
|
||||
* @return void
|
||||
*/
|
||||
function testAdapterException() {
|
||||
|
|
|
@ -6700,7 +6700,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
|
||||
/**
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedException CakeException
|
||||
* @return void
|
||||
*/
|
||||
function testHtml5InputException() {
|
||||
|
|
Loading…
Reference in a new issue