Browse Source

renamed exception classes.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
ed8b795295
  1. 6
      framework/base/Application.php
  2. 21
      framework/base/BadPropertyException.php
  3. 18
      framework/base/Component.php
  4. 8
      framework/base/Dictionary.php
  5. 6
      framework/base/InvalidCallException.php
  6. 6
      framework/base/InvalidConfigException.php
  7. 18
      framework/base/Object.php
  8. 6
      framework/base/UnknownMethodException.php
  9. 6
      framework/base/UnknownPropertyException.php
  10. 20
      framework/base/Vector.php
  11. 8
      framework/base/View.php
  12. 24
      framework/db/ActiveRecord.php
  13. 6
      framework/db/ActiveRelation.php
  14. 6
      framework/db/DataReader.php
  15. 6
      framework/db/Schema.php
  16. 6
      framework/db/TableSchema.php
  17. 8
      framework/util/ArrayHelper.php
  18. 6
      tests/unit/framework/base/ComponentTest.php
  19. 4
      tests/unit/framework/base/DictionaryTest.php
  20. 4
      tests/unit/framework/base/ObjectTest.php
  21. 10
      tests/unit/framework/base/VectorTest.php

6
framework/base/Application.php

@ -9,7 +9,7 @@
namespace yii\base; namespace yii\base;
use yii\base\Exception; use yii\base\InvalidCallException;
/** /**
* Application is the base class for all application classes. * Application is the base class for all application classes.
@ -236,13 +236,13 @@ class Application extends Module
/** /**
* Sets the directory that stores runtime files. * Sets the directory that stores runtime files.
* @param string $path the directory that stores runtime files. * @param string $path the directory that stores runtime files.
* @throws BadParamException if the directory does not exist or is not writable * @throws InvalidCallException if the directory does not exist or is not writable
*/ */
public function setRuntimePath($path) public function setRuntimePath($path)
{ {
$p = \Yii::getAlias($path); $p = \Yii::getAlias($path);
if ($p === false || !is_dir($p) || !is_writable($path)) { if ($p === false || !is_dir($p) || !is_writable($path)) {
throw new BadParamException("Application runtime path \"$path\" is invalid. Please make sure it is a directory writable by the Web server process."); throw new InvalidCallException("Application runtime path \"$path\" is invalid. Please make sure it is a directory writable by the Web server process.");
} else { } else {
$this->_runtimePath = $p; $this->_runtimePath = $p;
} }

21
framework/base/BadPropertyException.php

@ -1,21 +0,0 @@
<?php
/**
* BadPropertyException class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\base;
/**
* BadPropertyException represents an exception caused by accessing unknown object properties.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class BadPropertyException extends \Exception
{
}

18
framework/base/Component.php

@ -42,7 +42,7 @@ class Component extends \yii\base\Object
* @param string $name the property name * @param string $name the property name
* @return mixed the property value, event handlers attached to the event, * @return mixed the property value, event handlers attached to the event,
* the behavior, or the value of a behavior's property * the behavior, or the value of a behavior's property
* @throws BadPropertyException if the property is not defined * @throws UnknownPropertyException if the property is not defined
* @see __set * @see __set
*/ */
public function __get($name) public function __get($name)
@ -60,7 +60,7 @@ class Component extends \yii\base\Object
} }
} }
} }
throw new BadPropertyException('Getting unknown property: ' . get_class($this) . '.' . $name); throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '.' . $name);
} }
/** /**
@ -76,7 +76,7 @@ class Component extends \yii\base\Object
* will be implicitly called when executing `$component->property = $value;`. * will be implicitly called when executing `$component->property = $value;`.
* @param string $name the property name or the event name * @param string $name the property name or the event name
* @param mixed $value the property value * @param mixed $value the property value
* @throws BadPropertyException if the property is not defined or read-only. * @throws UnknownPropertyException if the property is not defined or read-only.
* @see __get * @see __get
*/ */
public function __set($name, $value) public function __set($name, $value)
@ -106,9 +106,9 @@ class Component extends \yii\base\Object
} }
} }
if (method_exists($this, 'get' . $name)) { if (method_exists($this, 'get' . $name)) {
throw new BadPropertyException('Setting read-only property: ' . get_class($this) . '.' . $name); throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '.' . $name);
} else { } else {
throw new BadPropertyException('Setting unknown property: ' . get_class($this) . '.' . $name); throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '.' . $name);
} }
} }
@ -151,7 +151,7 @@ class Component extends \yii\base\Object
* Do not call this method directly as it is a PHP magic method that * Do not call this method directly as it is a PHP magic method that
* will be implicitly called when executing `unset($component->property)`. * will be implicitly called when executing `unset($component->property)`.
* @param string $name the property name * @param string $name the property name
* @throws BadPropertyException if the property is read only. * @throws UnknownPropertyException if the property is read only.
*/ */
public function __unset($name) public function __unset($name)
{ {
@ -170,7 +170,7 @@ class Component extends \yii\base\Object
} }
} }
if (method_exists($this, 'get' . $name)) { if (method_exists($this, 'get' . $name)) {
throw new BadPropertyException('Unsetting read-only property: ' . get_class($this) . '.' . $name); throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '.' . $name);
} }
} }
@ -186,7 +186,7 @@ class Component extends \yii\base\Object
* @param string $name the method name * @param string $name the method name
* @param array $params method parameters * @param array $params method parameters
* @return mixed the method return value * @return mixed the method return value
* @throws BadMethodException when calling unknown method * @throws UnknownMethodException when calling unknown method
*/ */
public function __call($name, $params) public function __call($name, $params)
{ {
@ -205,7 +205,7 @@ class Component extends \yii\base\Object
} }
} }
throw new BadMethodException('Calling unknown method: ' . get_class($this) . "::$name()"); throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
} }
/** /**

8
framework/base/Dictionary.php

@ -184,7 +184,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co
* Copies iterable data into the dictionary. * Copies iterable data into the dictionary.
* Note, existing data in the dictionary will be cleared first. * Note, existing data in the dictionary will be cleared first.
* @param mixed $data the data to be copied from, must be an array or an object implementing `Traversable` * @param mixed $data the data to be copied from, must be an array or an object implementing `Traversable`
* @throws BadParamException if data is neither an array nor an iterator. * @throws InvalidCallException if data is neither an array nor an iterator.
*/ */
public function copyFrom($data) public function copyFrom($data)
{ {
@ -199,7 +199,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co
$this->add($key, $value); $this->add($key, $value);
} }
} else { } else {
throw new BadParamException('Data must be either an array or an object implementing Traversable.'); throw new InvalidCallException('Data must be either an array or an object implementing Traversable.');
} }
} }
@ -216,7 +216,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co
* *
* @param array|\Traversable $data the data to be merged with. It must be an array or object implementing Traversable * @param array|\Traversable $data the data to be merged with. It must be an array or object implementing Traversable
* @param boolean $recursive whether the merging should be recursive. * @param boolean $recursive whether the merging should be recursive.
* @throws BadParamException if data is neither an array nor an object implementing `Traversable`. * @throws InvalidCallException if data is neither an array nor an object implementing `Traversable`.
*/ */
public function mergeWith($data, $recursive = true) public function mergeWith($data, $recursive = true)
{ {
@ -240,7 +240,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co
} }
} }
} else { } else {
throw new BadParamException('The data to be merged with must be an array or an object implementing Traversable.'); throw new InvalidCallException('The data to be merged with must be an array or an object implementing Traversable.');
} }
} }

6
framework/base/BadCallException.php → framework/base/InvalidCallException.php

@ -1,6 +1,6 @@
<?php <?php
/** /**
* BadCallException class file. * InvalidCallException class file.
* *
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC * @copyright Copyright &copy; 2008 Yii Software LLC
@ -10,12 +10,12 @@
namespace yii\base; namespace yii\base;
/** /**
* BadCallException represents an exception caused by calling a method in a wrong way. * InvalidCallException represents an exception caused by calling a method in a wrong way.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class BadCallException extends \Exception class InvalidCallException extends \Exception
{ {
} }

6
framework/base/BadConfigException.php → framework/base/InvalidConfigException.php

@ -1,6 +1,6 @@
<?php <?php
/** /**
* BadConfigException class file. * InvalidConfigException class file.
* *
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC * @copyright Copyright &copy; 2008 Yii Software LLC
@ -10,12 +10,12 @@
namespace yii\base; namespace yii\base;
/** /**
* BadConfigException represents an exception caused by incorrect object configuration. * InvalidConfigException represents an exception caused by incorrect object configuration.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class BadConfigException extends \Exception class InvalidConfigException extends \Exception
{ {
} }

18
framework/base/Object.php

@ -58,7 +58,7 @@ class Object
* @param string $name the property name * @param string $name the property name
* @return mixed the property value, event handlers attached to the event, * @return mixed the property value, event handlers attached to the event,
* the named behavior, or the value of a behavior's property * the named behavior, or the value of a behavior's property
* @throws BadPropertyException if the property is not defined * @throws UnknownPropertyException if the property is not defined
* @see __set * @see __set
*/ */
public function __get($name) public function __get($name)
@ -67,7 +67,7 @@ class Object
if (method_exists($this, $getter)) { if (method_exists($this, $getter)) {
return $this->$getter(); return $this->$getter();
} else { } else {
throw new BadPropertyException('Getting unknown property: ' . get_class($this) . '.' . $name); throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '.' . $name);
} }
} }
@ -78,7 +78,7 @@ class Object
* will be implicitly called when executing `$object->property = $value;`. * will be implicitly called when executing `$object->property = $value;`.
* @param string $name the property name or the event name * @param string $name the property name or the event name
* @param mixed $value the property value * @param mixed $value the property value
* @throws BadPropertyException if the property is not defined or read-only. * @throws UnknownPropertyException if the property is not defined or read-only.
* @see __get * @see __get
*/ */
public function __set($name, $value) public function __set($name, $value)
@ -87,9 +87,9 @@ class Object
if (method_exists($this, $setter)) { if (method_exists($this, $setter)) {
$this->$setter($value); $this->$setter($value);
} elseif (method_exists($this, 'get' . $name)) { } elseif (method_exists($this, 'get' . $name)) {
throw new BadPropertyException('Setting read-only property: ' . get_class($this) . '.' . $name); throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '.' . $name);
} else { } else {
throw new BadPropertyException('Setting unknown property: ' . get_class($this) . '.' . $name); throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '.' . $name);
} }
} }
@ -122,7 +122,7 @@ class Object
* Note that if the property is not defined, this method will do nothing. * Note that if the property is not defined, this method will do nothing.
* If the property is read-only, it will throw an exception. * If the property is read-only, it will throw an exception.
* @param string $name the property name * @param string $name the property name
* @throws BadPropertyException if the property is read only. * @throws UnknownPropertyException if the property is read only.
*/ */
public function __unset($name) public function __unset($name)
{ {
@ -130,7 +130,7 @@ class Object
if (method_exists($this, $setter)) { if (method_exists($this, $setter)) {
$this->$setter(null); $this->$setter(null);
} elseif (method_exists($this, 'get' . $name)) { } elseif (method_exists($this, 'get' . $name)) {
throw new BadPropertyException('Unsetting read-only property: ' . get_class($this) . '.' . $name); throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '.' . $name);
} }
} }
@ -143,7 +143,7 @@ class Object
* will be implicitly called when an unknown method is being invoked. * will be implicitly called when an unknown method is being invoked.
* @param string $name the method name * @param string $name the method name
* @param array $params method parameters * @param array $params method parameters
* @throws BadMethodException when calling unknown method * @throws UnknownMethodException when calling unknown method
* @return mixed the method return value * @return mixed the method return value
*/ */
public function __call($name, $params) public function __call($name, $params)
@ -155,7 +155,7 @@ class Object
return call_user_func_array($func, $params); return call_user_func_array($func, $params);
} }
} }
throw new BadMethodException('Unknown method: ' . get_class($this) . "::$name()"); throw new UnknownMethodException('Unknown method: ' . get_class($this) . "::$name()");
} }
/** /**

6
framework/base/BadMethodException.php → framework/base/UnknownMethodException.php

@ -1,6 +1,6 @@
<?php <?php
/** /**
* BadMethodException class file. * UnknownMethodException class file.
* *
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC * @copyright Copyright &copy; 2008 Yii Software LLC
@ -10,12 +10,12 @@
namespace yii\base; namespace yii\base;
/** /**
* BadMethodException represents an exception caused by accessing unknown object methods. * UnknownMethodException represents an exception caused by accessing unknown object methods.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class BadMethodException extends \Exception class UnknownMethodException extends \Exception
{ {
} }

6
framework/base/BadParamException.php → framework/base/UnknownPropertyException.php

@ -1,6 +1,6 @@
<?php <?php
/** /**
* BadParamException class file. * UnknownPropertyException class file.
* *
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC * @copyright Copyright &copy; 2008 Yii Software LLC
@ -10,12 +10,12 @@
namespace yii\base; namespace yii\base;
/** /**
* BadParamException represents an exception caused by incorrect method parameters. * UnknownPropertyException represents an exception caused by accessing unknown object properties.
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class BadParamException extends \Exception class UnknownPropertyException extends \Exception
{ {
} }

20
framework/base/Vector.php

@ -101,7 +101,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
* Returns the item at the specified index. * Returns the item at the specified index.
* @param integer $index the index of the item * @param integer $index the index of the item
* @return mixed the item at the index * @return mixed the item at the index
* @throws BadParamException if the index is out of range * @throws InvalidCallException if the index is out of range
*/ */
public function itemAt($index) public function itemAt($index)
{ {
@ -110,7 +110,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
} elseif ($index >= 0 && $index < $this->_c) { // in case the value is null } elseif ($index >= 0 && $index < $this->_c) { // in case the value is null
return $this->_d[$index]; return $this->_d[$index];
} else { } else {
throw new BadParamException('Index out of range: ' . $index); throw new InvalidCallException('Index out of range: ' . $index);
} }
} }
@ -132,7 +132,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
* one step towards the end. * one step towards the end.
* @param integer $index the specified position. * @param integer $index the specified position.
* @param mixed $item new item to be inserted into the vector * @param mixed $item new item to be inserted into the vector
* @throws BadParamException if the index specified is out of range, or the vector is read-only. * @throws InvalidCallException if the index specified is out of range, or the vector is read-only.
*/ */
public function insertAt($index, $item) public function insertAt($index, $item)
{ {
@ -142,7 +142,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
array_splice($this->_d, $index, 0, array($item)); array_splice($this->_d, $index, 0, array($item));
$this->_c++; $this->_c++;
} else { } else {
throw new BadParamException('Index out of range: ' . $index); throw new InvalidCallException('Index out of range: ' . $index);
} }
} }
@ -169,7 +169,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
* Removes an item at the specified position. * Removes an item at the specified position.
* @param integer $index the index of the item to be removed. * @param integer $index the index of the item to be removed.
* @return mixed the removed item. * @return mixed the removed item.
* @throws BadParamException if the index is out of range, or the vector is read only. * @throws InvalidCallException if the index is out of range, or the vector is read only.
*/ */
public function removeAt($index) public function removeAt($index)
{ {
@ -183,7 +183,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
return $item; return $item;
} }
} else { } else {
throw new BadParamException('Index out of range: ' . $index); throw new InvalidCallException('Index out of range: ' . $index);
} }
} }
@ -242,7 +242,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
* Copies iterable data into the vector. * Copies iterable data into the vector.
* Note, existing data in the vector will be cleared first. * Note, existing data in the vector will be cleared first.
* @param mixed $data the data to be copied from, must be an array or an object implementing `Traversable` * @param mixed $data the data to be copied from, must be an array or an object implementing `Traversable`
* @throws BadParamException if data is neither an array nor an object implementing `Traversable`. * @throws InvalidCallException if data is neither an array nor an object implementing `Traversable`.
*/ */
public function copyFrom($data) public function copyFrom($data)
{ {
@ -257,7 +257,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
$this->add($item); $this->add($item);
} }
} else { } else {
throw new BadParamException('Data must be either an array or an object implementing Traversable.'); throw new InvalidCallException('Data must be either an array or an object implementing Traversable.');
} }
} }
@ -265,7 +265,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
* Merges iterable data into the vector. * Merges iterable data into the vector.
* New items will be appended to the end of the existing items. * New items will be appended to the end of the existing items.
* @param array|\Traversable $data the data to be merged with. It must be an array or object implementing Traversable * @param array|\Traversable $data the data to be merged with. It must be an array or object implementing Traversable
* @throws BadParamException if data is neither an array nor an object implementing `Traversable`. * @throws InvalidCallException if data is neither an array nor an object implementing `Traversable`.
*/ */
public function mergeWith($data) public function mergeWith($data)
{ {
@ -277,7 +277,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
$this->add($item); $this->add($item);
} }
} else { } else {
throw new BadParamException('The data to be merged with must be an array or an object implementing Traversable.'); throw new InvalidCallException('The data to be merged with must be an array or an object implementing Traversable.');
} }
} }

8
framework/base/View.php

@ -105,7 +105,7 @@ class View extends Component
* @param array $params the parameters that should be made available in the view. The PHP function `extract()` * @param array $params the parameters that should be made available in the view. The PHP function `extract()`
* will be called on this variable to extract the variables from this parameter. * will be called on this variable to extract the variables from this parameter.
* @return string the rendering result * @return string the rendering result
* @throws BadParamException if the view file cannot be found * @throws InvalidCallException if the view file cannot be found
*/ */
public function renderPartial($view, $params = array()) public function renderPartial($view, $params = array())
{ {
@ -113,7 +113,7 @@ class View extends Component
if ($file !== false) { if ($file !== false) {
return $this->renderFile($file, $params); return $this->renderFile($file, $params);
} else { } else {
throw new BadParamException("Unable to find the view file for view '$view'."); throw new InvalidCallException("Unable to find the view file for view '$view'.");
} }
} }
@ -416,7 +416,7 @@ class View extends Component
* The themed layout file will be returned if theme is enabled and the theme contains such a layout file. * The themed layout file will be returned if theme is enabled and the theme contains such a layout file.
* *
* @return string|boolean the layout file path, or false if the context does not need layout. * @return string|boolean the layout file path, or false if the context does not need layout.
* @throws BadParamException if the layout file cannot be found * @throws InvalidCallException if the layout file cannot be found
*/ */
public function findLayoutFile() public function findLayoutFile()
{ {
@ -454,7 +454,7 @@ class View extends Component
} }
} }
if ($file === false || !is_file($file)) { if ($file === false || !is_file($file)) {
throw new BadParamException("Unable to find the layout file for layout '{$module->layout}' (specified by " . get_class($module) . ")"); throw new InvalidCallException("Unable to find the layout file for layout '{$module->layout}' (specified by " . get_class($module) . ")");
} elseif ($this->localizeView) { } elseif ($this->localizeView) {
return FileHelper::localize($file, $this->language, $this->sourceLanguage); return FileHelper::localize($file, $this->language, $this->sourceLanguage);
} else { } else {

24
framework/db/ActiveRecord.php

@ -12,8 +12,8 @@ namespace yii\db;
use yii\base\Model; use yii\base\Model;
use yii\base\ModelEvent; use yii\base\ModelEvent;
use yii\base\BadMethodException; use yii\base\UnknownMethodException;
use yii\base\BadParamException; use yii\base\InvalidCallException;
use yii\db\Connection; use yii\db\Connection;
use yii\db\TableSchema; use yii\db\TableSchema;
use yii\db\Expression; use yii\db\Expression;
@ -991,7 +991,7 @@ class ActiveRecord extends Model
* It can be declared in either the Active Record class itself or one of its behaviors. * It can be declared in either the Active Record class itself or one of its behaviors.
* @param string $name the relation name * @param string $name the relation name
* @return ActiveRelation the relation object * @return ActiveRelation the relation object
* @throws BadParamException if the named relation does not exist. * @throws InvalidCallException if the named relation does not exist.
*/ */
public function getRelation($name) public function getRelation($name)
{ {
@ -1001,9 +1001,9 @@ class ActiveRecord extends Model
if ($relation instanceof ActiveRelation) { if ($relation instanceof ActiveRelation) {
return $relation; return $relation;
} }
} catch (BadMethodException $e) { } catch (UnknownMethodException $e) {
} }
throw new BadParamException(get_class($this) . ' has no relation named "' . $name . '".'); throw new InvalidCallException(get_class($this) . ' has no relation named "' . $name . '".');
} }
/** /**
@ -1023,7 +1023,7 @@ class ActiveRecord extends Model
* @param array $extraColumns additional column values to be saved into the pivot table. * @param array $extraColumns additional column values to be saved into the pivot table.
* This parameter is only meaningful for a relationship involving a pivot table * This parameter is only meaningful for a relationship involving a pivot table
* (i.e., a relation set with `[[ActiveRelation::via()]]` or `[[ActiveRelation::viaTable()]]`.) * (i.e., a relation set with `[[ActiveRelation::via()]]` or `[[ActiveRelation::viaTable()]]`.)
* @throws BadParamException if the method is unable to link two models. * @throws InvalidCallException if the method is unable to link two models.
*/ */
public function link($name, $model, $extraColumns = array()) public function link($name, $model, $extraColumns = array())
{ {
@ -1059,7 +1059,7 @@ class ActiveRecord extends Model
$p2 = $this->isPrimaryKey(array_values($relation->link)); $p2 = $this->isPrimaryKey(array_values($relation->link));
if ($p1 && $p2) { if ($p1 && $p2) {
if ($this->getIsNewRecord() && $model->getIsNewRecord()) { if ($this->getIsNewRecord() && $model->getIsNewRecord()) {
throw new BadParamException('Unable to link models: both models are newly created.'); throw new InvalidCallException('Unable to link models: both models are newly created.');
} elseif ($this->getIsNewRecord()) { } elseif ($this->getIsNewRecord()) {
$this->bindModels(array_flip($relation->link), $this, $model); $this->bindModels(array_flip($relation->link), $this, $model);
} else { } else {
@ -1070,7 +1070,7 @@ class ActiveRecord extends Model
} elseif ($p2) { } elseif ($p2) {
$this->bindModels($relation->link, $model, $this); $this->bindModels($relation->link, $model, $this);
} else { } else {
throw new BadParamException('Unable to link models: the link does not involve any primary key.'); throw new InvalidCallException('Unable to link models: the link does not involve any primary key.');
} }
} }
@ -1098,7 +1098,7 @@ class ActiveRecord extends Model
* @param boolean $delete whether to delete the model that contains the foreign key. * @param boolean $delete whether to delete the model that contains the foreign key.
* If false, the model's foreign key will be set null and saved. * If false, the model's foreign key will be set null and saved.
* If true, the model containing the foreign key will be deleted. * If true, the model containing the foreign key will be deleted.
* @throws BadParamException if the models cannot be unlinked * @throws InvalidCallException if the models cannot be unlinked
*/ */
public function unlink($name, $model, $delete = false) public function unlink($name, $model, $delete = false)
{ {
@ -1147,7 +1147,7 @@ class ActiveRecord extends Model
} }
$delete ? $this->delete() : $this->save(false); $delete ? $this->delete() : $this->save(false);
} else { } else {
throw new BadParamException('Unable to unlink models: the link does not involve any primary key.'); throw new InvalidCallException('Unable to unlink models: the link does not involve any primary key.');
} }
} }
@ -1186,14 +1186,14 @@ class ActiveRecord extends Model
* @param array $link * @param array $link
* @param ActiveRecord $foreignModel * @param ActiveRecord $foreignModel
* @param ActiveRecord $primaryModel * @param ActiveRecord $primaryModel
* @throws BadParamException * @throws InvalidCallException
*/ */
private function bindModels($link, $foreignModel, $primaryModel) private function bindModels($link, $foreignModel, $primaryModel)
{ {
foreach ($link as $fk => $pk) { foreach ($link as $fk => $pk) {
$value = $primaryModel->$pk; $value = $primaryModel->$pk;
if ($value === null) { if ($value === null) {
throw new BadParamException('Unable to link models: the primary key of ' . get_class($primaryModel) . ' is null.'); throw new InvalidCallException('Unable to link models: the primary key of ' . get_class($primaryModel) . ' is null.');
} }
$foreignModel->$fk = $value; $foreignModel->$fk = $value;
} }

6
framework/db/ActiveRelation.php

@ -12,7 +12,7 @@ namespace yii\db;
use yii\db\Connection; use yii\db\Connection;
use yii\db\Command; use yii\db\Command;
use yii\base\BadParamException; use yii\base\InvalidConfigException;
/** /**
* ActiveRelation represents a relation between two Active Record classes. * ActiveRelation represents a relation between two Active Record classes.
@ -137,12 +137,12 @@ class ActiveRelation extends ActiveQuery
* @param string $name the relation name * @param string $name the relation name
* @param array $primaryModels primary models * @param array $primaryModels primary models
* @return array the related models * @return array the related models
* @throws BadParamException * @throws InvalidConfigException
*/ */
public function findWith($name, &$primaryModels) public function findWith($name, &$primaryModels)
{ {
if (!is_array($this->link)) { if (!is_array($this->link)) {
throw new BadParamException('Invalid link: it must be an array of key-value pairs.'); throw new InvalidConfigException('Invalid link: it must be an array of key-value pairs.');
} }
if ($this->via instanceof self) { if ($this->via instanceof self) {

6
framework/db/DataReader.php

@ -9,7 +9,7 @@
namespace yii\db; namespace yii\db;
use yii\base\BadCallException; use yii\base\InvalidCallException;
/** /**
* DataReader represents a forward-only stream of rows from a query result set. * DataReader represents a forward-only stream of rows from a query result set.
@ -212,7 +212,7 @@ class DataReader extends \yii\base\Object implements \Iterator, \Countable
/** /**
* Resets the iterator to the initial state. * Resets the iterator to the initial state.
* This method is required by the interface Iterator. * This method is required by the interface Iterator.
* @throws BadCallException if this method is invoked twice * @throws InvalidCallException if this method is invoked twice
*/ */
public function rewind() public function rewind()
{ {
@ -220,7 +220,7 @@ class DataReader extends \yii\base\Object implements \Iterator, \Countable
$this->_row = $this->_statement->fetch(); $this->_row = $this->_statement->fetch();
$this->_index = 0; $this->_index = 0;
} else { } else {
throw new BadCallException('DataReader cannot rewind. It is a forward-only reader.'); throw new InvalidCallException('DataReader cannot rewind. It is a forward-only reader.');
} }
} }

6
framework/db/Schema.php

@ -10,7 +10,7 @@
namespace yii\db; namespace yii\db;
use yii\base\NotSupportedException; use yii\base\NotSupportedException;
use yii\base\BadCallException; use yii\base\InvalidCallException;
/** /**
* Schema is the base class for concrete DBMS-specific schema classes. * Schema is the base class for concrete DBMS-specific schema classes.
@ -205,7 +205,7 @@ abstract class Schema extends \yii\base\Object
* Returns the ID of the last inserted row or sequence value. * Returns the ID of the last inserted row or sequence value.
* @param string $sequenceName name of the sequence object (required by some DBMS) * @param string $sequenceName name of the sequence object (required by some DBMS)
* @return string the row ID of the last row inserted, or the last value retrieved from the sequence object * @return string the row ID of the last row inserted, or the last value retrieved from the sequence object
* @throws BadCallException if the DB connection is not active * @throws InvalidCallException if the DB connection is not active
* @see http://www.php.net/manual/en/function.PDO-lastInsertId.php * @see http://www.php.net/manual/en/function.PDO-lastInsertId.php
*/ */
public function getLastInsertID($sequenceName = '') public function getLastInsertID($sequenceName = '')
@ -213,7 +213,7 @@ abstract class Schema extends \yii\base\Object
if ($this->connection->isActive) { if ($this->connection->isActive) {
return $this->connection->pdo->lastInsertId($sequenceName); return $this->connection->pdo->lastInsertId($sequenceName);
} else { } else {
throw new BadCallException('DB Connection is not active.'); throw new InvalidCallException('DB Connection is not active.');
} }
} }

6
framework/db/TableSchema.php

@ -9,7 +9,7 @@
namespace yii\db; namespace yii\db;
use yii\base\BadParamException; use yii\base\InvalidCallException;
/** /**
* TableSchema represents the metadata of a database table. * TableSchema represents the metadata of a database table.
@ -87,7 +87,7 @@ class TableSchema extends \yii\base\Object
/** /**
* Manually specifies the primary key for this table. * Manually specifies the primary key for this table.
* @param string|array $keys the primary key (can be composite) * @param string|array $keys the primary key (can be composite)
* @throws BadParamException if the specified key cannot be found in the table. * @throws InvalidCallException if the specified key cannot be found in the table.
*/ */
public function fixPrimaryKey($keys) public function fixPrimaryKey($keys)
{ {
@ -102,7 +102,7 @@ class TableSchema extends \yii\base\Object
if (isset($this->columns[$key])) { if (isset($this->columns[$key])) {
$this->columns[$key]->isPrimaryKey = true; $this->columns[$key]->isPrimaryKey = true;
} else { } else {
throw new BadParamException("Primary key '$key' cannot be found in table '{$this->name}'."); throw new InvalidCallException("Primary key '$key' cannot be found in table '{$this->name}'.");
} }
} }
} }

8
framework/util/ArrayHelper.php

@ -9,6 +9,8 @@
namespace yii\util; namespace yii\util;
use yii\base\InvalidCallException;
/** /**
* ArrayHelper provides additional array functionality you can use in your * ArrayHelper provides additional array functionality you can use in your
* application. * application.
@ -240,7 +242,7 @@ class ArrayHelper
* value is for sorting strings in case-insensitive manner. Please refer to * value is for sorting strings in case-insensitive manner. Please refer to
* See [PHP manual](http://php.net/manual/en/function.sort.php) for more details. * See [PHP manual](http://php.net/manual/en/function.sort.php) for more details.
* When sorting by multiple keys with different sort flags, use an array of sort flags. * When sorting by multiple keys with different sort flags, use an array of sort flags.
* @throws \yii\base\BadParamException if the $ascending or $sortFlag parameters do not have * @throws InvalidCallException if the $ascending or $sortFlag parameters do not have
* correct number of elements as that of $key. * correct number of elements as that of $key.
*/ */
public static function multisort(&$array, $key, $ascending = true, $sortFlag = SORT_REGULAR) public static function multisort(&$array, $key, $ascending = true, $sortFlag = SORT_REGULAR)
@ -253,12 +255,12 @@ class ArrayHelper
if (is_scalar($ascending)) { if (is_scalar($ascending)) {
$ascending = array_fill(0, $n, $ascending); $ascending = array_fill(0, $n, $ascending);
} elseif (count($ascending) !== $n) { } elseif (count($ascending) !== $n) {
throw new \yii\base\BadParamException('The length of $ascending parameter must be the same as that of $keys.'); throw new InvalidCallException('The length of $ascending parameter must be the same as that of $keys.');
} }
if (is_scalar($sortFlag)) { if (is_scalar($sortFlag)) {
$sortFlag = array_fill(0, $n, $sortFlag); $sortFlag = array_fill(0, $n, $sortFlag);
} elseif (count($sortFlag) !== $n) { } elseif (count($sortFlag) !== $n) {
throw new \yii\base\BadParamException('The length of $ascending parameter must be the same as that of $keys.'); throw new InvalidCallException('The length of $ascending parameter must be the same as that of $keys.');
} }
$args = array(); $args = array();
foreach ($keys as $i => $key) { foreach ($keys as $i => $key) {

6
tests/unit/framework/base/ComponentTest.php

@ -64,7 +64,7 @@ class ComponentTest extends \yiiunit\TestCase
public function testGetProperty() public function testGetProperty()
{ {
$this->assertTrue('default' === $this->component->Text); $this->assertTrue('default' === $this->component->Text);
$this->setExpectedException('yii\base\BadPropertyException'); $this->setExpectedException('yii\base\UnknownPropertyException');
$value2 = $this->component->Caption; $value2 = $this->component->Caption;
} }
@ -73,7 +73,7 @@ class ComponentTest extends \yiiunit\TestCase
$value = 'new value'; $value = 'new value';
$this->component->Text = $value; $this->component->Text = $value;
$this->assertEquals($value, $this->component->Text); $this->assertEquals($value, $this->component->Text);
$this->setExpectedException('yii\base\BadPropertyException'); $this->setExpectedException('yii\base\UnknownPropertyException');
$this->component->NewMember = $value; $this->component->NewMember = $value;
} }
@ -182,7 +182,7 @@ class ComponentTest extends \yiiunit\TestCase
$this->assertSame($behavior, $component->detachBehavior('a')); $this->assertSame($behavior, $component->detachBehavior('a'));
$this->assertFalse($component->hasProperty('p')); $this->assertFalse($component->hasProperty('p'));
$this->setExpectedException('yii\base\BadMethodException'); $this->setExpectedException('yii\base\UnknownMethodException');
$component->test(); $component->test();
$p = 'as b'; $p = 'as b';

4
tests/unit/framework/base/DictionaryTest.php

@ -95,7 +95,7 @@ class DictionaryTest extends \yiiunit\TestCase
$this->assertEquals($this->item3, $this->dictionary['key3']); $this->assertEquals($this->item3, $this->dictionary['key3']);
$this->assertEquals($this->item1, $this->dictionary['key4']); $this->assertEquals($this->item1, $this->dictionary['key4']);
$this->setExpectedException('yii\base\BadParamException'); $this->setExpectedException('yii\base\InvalidCallException');
$this->dictionary->copyFrom($this); $this->dictionary->copyFrom($this);
} }
@ -114,7 +114,7 @@ class DictionaryTest extends \yiiunit\TestCase
$this->assertEquals(3,$this->dictionary->getCount()); $this->assertEquals(3,$this->dictionary->getCount());
$this->assertEquals($this->item1,$this->dictionary['key2']); $this->assertEquals($this->item1,$this->dictionary['key2']);
$this->assertEquals($this->item3,$this->dictionary['key3']); $this->assertEquals($this->item3,$this->dictionary['key3']);
$this->setExpectedException('yii\base\BadParamException'); $this->setExpectedException('yii\base\InvalidCallException');
$this->dictionary->mergeWith($this,false); $this->dictionary->mergeWith($this,false);
} }

4
tests/unit/framework/base/ObjectTest.php

@ -56,7 +56,7 @@ class ObjectTest extends \yiiunit\TestCase
public function testGetProperty() public function testGetProperty()
{ {
$this->assertTrue('default' === $this->object->Text); $this->assertTrue('default' === $this->object->Text);
$this->setExpectedException('yii\base\BadPropertyException'); $this->setExpectedException('yii\base\UnknownPropertyException');
$value2 = $this->object->Caption; $value2 = $this->object->Caption;
} }
@ -65,7 +65,7 @@ class ObjectTest extends \yiiunit\TestCase
$value = 'new value'; $value = 'new value';
$this->object->Text = $value; $this->object->Text = $value;
$this->assertEquals($value, $this->object->Text); $this->assertEquals($value, $this->object->Text);
$this->setExpectedException('yii\base\BadPropertyException'); $this->setExpectedException('yii\base\UnknownPropertyException');
$this->object->NewMember = $value; $this->object->NewMember = $value;
} }

10
tests/unit/framework/base/VectorTest.php

@ -65,7 +65,7 @@ class VectorTest extends \yiiunit\TestCase
$this->assertEquals(2,$this->vector->indexOf($this->item2)); $this->assertEquals(2,$this->vector->indexOf($this->item2));
$this->assertEquals(0,$this->vector->indexOf($this->item3)); $this->assertEquals(0,$this->vector->indexOf($this->item3));
$this->assertEquals(1,$this->vector->indexOf($this->item1)); $this->assertEquals(1,$this->vector->indexOf($this->item1));
$this->setExpectedException('yii\base\BadParamException'); $this->setExpectedException('yii\base\InvalidCallException');
$this->vector->insertAt(4,$this->item3); $this->vector->insertAt(4,$this->item3);
} }
@ -87,7 +87,7 @@ class VectorTest extends \yiiunit\TestCase
$this->assertEquals(-1,$this->vector->indexOf($this->item2)); $this->assertEquals(-1,$this->vector->indexOf($this->item2));
$this->assertEquals(1,$this->vector->indexOf($this->item3)); $this->assertEquals(1,$this->vector->indexOf($this->item3));
$this->assertEquals(0,$this->vector->indexOf($this->item1)); $this->assertEquals(0,$this->vector->indexOf($this->item1));
$this->setExpectedException('yii\base\BadParamException'); $this->setExpectedException('yii\base\InvalidCallException');
$this->vector->removeAt(2); $this->vector->removeAt(2);
} }
@ -118,7 +118,7 @@ class VectorTest extends \yiiunit\TestCase
$array=array($this->item3,$this->item1); $array=array($this->item3,$this->item1);
$this->vector->copyFrom($array); $this->vector->copyFrom($array);
$this->assertTrue(count($array)==2 && $this->vector[0]===$this->item3 && $this->vector[1]===$this->item1); $this->assertTrue(count($array)==2 && $this->vector[0]===$this->item3 && $this->vector[1]===$this->item1);
$this->setExpectedException('yii\base\BadParamException'); $this->setExpectedException('yii\base\InvalidCallException');
$this->vector->copyFrom($this); $this->vector->copyFrom($this);
} }
@ -127,7 +127,7 @@ class VectorTest extends \yiiunit\TestCase
$array=array($this->item3,$this->item1); $array=array($this->item3,$this->item1);
$this->vector->mergeWith($array); $this->vector->mergeWith($array);
$this->assertTrue($this->vector->getCount()==4 && $this->vector[0]===$this->item1 && $this->vector[3]===$this->item1); $this->assertTrue($this->vector->getCount()==4 && $this->vector[0]===$this->item1 && $this->vector[3]===$this->item1);
$this->setExpectedException('yii\base\BadParamException'); $this->setExpectedException('yii\base\InvalidCallException');
$this->vector->mergeWith($this); $this->vector->mergeWith($this);
} }
@ -141,7 +141,7 @@ class VectorTest extends \yiiunit\TestCase
{ {
$this->assertTrue($this->vector[0]===$this->item1); $this->assertTrue($this->vector[0]===$this->item1);
$this->assertTrue($this->vector[1]===$this->item2); $this->assertTrue($this->vector[1]===$this->item2);
$this->setExpectedException('yii\base\BadParamException'); $this->setExpectedException('yii\base\InvalidCallException');
$a=$this->vector[2]; $a=$this->vector[2];
} }

Loading…
Cancel
Save