Browse Source

fixed exception.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
f68bed0ccb
  1. 8
      framework/base/Dictionary.php
  2. 20
      framework/base/Vector.php
  3. 4
      framework/base/View.php
  4. 5
      framework/db/ActiveRecord.php
  5. 6
      framework/db/TableSchema.php
  6. 8
      framework/db/mysql/QueryBuilder.php
  7. 8
      framework/db/sqlite/QueryBuilder.php
  8. 8
      framework/util/ArrayHelper.php
  9. 48
      framework/util/VarDumper.php
  10. 4
      tests/unit/framework/base/DictionaryTest.php
  11. 10
      tests/unit/framework/base/VectorTest.php

8
framework/base/Dictionary.php

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

20
framework/base/Vector.php

@ -101,7 +101,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
* Returns the item at the specified index.
* @param integer $index the index of the item
* @return mixed the item at the index
* @throws InvalidCallException if the index is out of range
* @throws InvalidParamException if the index is out of range
*/
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
return $this->_d[$index];
} else {
throw new InvalidCallException('Index out of range: ' . $index);
throw new InvalidParamException('Index out of range: ' . $index);
}
}
@ -132,7 +132,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
* one step towards the end.
* @param integer $index the specified position.
* @param mixed $item new item to be inserted into the vector
* @throws InvalidCallException if the index specified is out of range, or the vector is read-only.
* @throws InvalidParamException if the index specified is out of range, or the vector is read-only.
*/
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));
$this->_c++;
} else {
throw new InvalidCallException('Index out of range: ' . $index);
throw new InvalidParamException('Index out of range: ' . $index);
}
}
@ -169,7 +169,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
* Removes an item at the specified position.
* @param integer $index the index of the item to be removed.
* @return mixed the removed item.
* @throws InvalidCallException if the index is out of range, or the vector is read only.
* @throws InvalidParamException if the index is out of range, or the vector is read only.
*/
public function removeAt($index)
{
@ -183,7 +183,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
return $item;
}
} else {
throw new InvalidCallException('Index out of range: ' . $index);
throw new InvalidParamException('Index out of range: ' . $index);
}
}
@ -242,7 +242,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
* Copies iterable data into the vector.
* 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`
* @throws InvalidCallException if data is neither an array nor an object implementing `Traversable`.
* @throws InvalidParamException if data is neither an array nor an object implementing `Traversable`.
*/
public function copyFrom($data)
{
@ -257,7 +257,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
$this->add($item);
}
} else {
throw new InvalidCallException('Data must be either an array or an object implementing Traversable.');
throw new InvalidParamException('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.
* 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
* @throws InvalidCallException if data is neither an array nor an object implementing `Traversable`.
* @throws InvalidParamException if data is neither an array nor an object implementing `Traversable`.
*/
public function mergeWith($data)
{
@ -277,7 +277,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
$this->add($item);
}
} else {
throw new InvalidCallException('The data to be merged with must be an array or an object implementing Traversable.');
throw new InvalidParamException('The data to be merged with must be an array or an object implementing Traversable.');
}
}

4
framework/base/View.php

@ -122,7 +122,7 @@ class View extends Component
* @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.
* @return string the rendering result
* @throws InvalidCallException if the view file cannot be found
* @throws InvalidParamException if the view file cannot be found
* @see findViewFile()
*/
public function renderPartial($view, $params = array())
@ -131,7 +131,7 @@ class View extends Component
if ($file !== false) {
return $this->renderFile($file, $params);
} else {
throw new InvalidCallException("Unable to find the view file for view '$view'.");
throw new InvalidParamException("Unable to find the view file for view '$view'.");
}
}

5
framework/db/ActiveRecord.php

@ -11,6 +11,7 @@
namespace yii\db;
use yii\base\Model;
use yii\base\InvalidParamException;
use yii\base\Event;
use yii\base\ModelEvent;
use yii\base\UnknownMethodException;
@ -1045,7 +1046,7 @@ class ActiveRecord extends Model
* It can be declared in either the Active Record class itself or one of its behaviors.
* @param string $name the relation name
* @return ActiveRelation the relation object
* @throws InvalidCallException if the named relation does not exist.
* @throws InvalidParamException if the named relation does not exist.
*/
public function getRelation($name)
{
@ -1057,7 +1058,7 @@ class ActiveRecord extends Model
}
} catch (UnknownMethodException $e) {
}
throw new InvalidCallException(get_class($this) . ' has no relation named "' . $name . '".');
throw new InvalidParamException(get_class($this) . ' has no relation named "' . $name . '".');
}
/**

6
framework/db/TableSchema.php

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

8
framework/db/mysql/QueryBuilder.php

@ -10,7 +10,7 @@
namespace yii\db\mysql;
use yii\db\Exception;
use yii\base\InvalidCallException;
use yii\base\InvalidParamException;
/**
* QueryBuilder is the query builder for MySQL databases.
@ -98,7 +98,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
* @param mixed $value the value for the primary key of the next new row inserted. If this is not set,
* the next new row's primary key will have a value 1.
* @return string the SQL statement for resetting sequence
* @throws InvalidCallException if the table does not exist or there is no sequence associated with the table.
* @throws InvalidParamException if the table does not exist or there is no sequence associated with the table.
*/
public function resetSequence($tableName, $value = null)
{
@ -113,9 +113,9 @@ class QueryBuilder extends \yii\db\QueryBuilder
}
return "ALTER TABLE $tableName AUTO_INCREMENT=$value";
} elseif ($table === null) {
throw new InvalidCallException("Table not found: $tableName");
throw new InvalidParamException("Table not found: $tableName");
} else {
throw new InvalidCallException("There is not sequence associated with table '$tableName'.'");
throw new InvalidParamException("There is not sequence associated with table '$tableName'.'");
}
}

8
framework/db/sqlite/QueryBuilder.php

@ -10,8 +10,8 @@
namespace yii\db\sqlite;
use yii\db\Exception;
use yii\base\InvalidParamException;
use yii\base\NotSupportedException;
use yii\base\InvalidCallException;
/**
* QueryBuilder is the query builder for SQLite databases.
@ -50,7 +50,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
* @param mixed $value the value for the primary key of the next new row inserted. If this is not set,
* the next new row's primary key will have a value 1.
* @return string the SQL statement for resetting sequence
* @throws InvalidCallException if the table does not exist or there is no sequence associated with the table.
* @throws InvalidParamException if the table does not exist or there is no sequence associated with the table.
*/
public function resetSequence($tableName, $value = null)
{
@ -70,9 +70,9 @@ class QueryBuilder extends \yii\db\QueryBuilder
} catch (Exception $e) {
}
} elseif ($table === null) {
throw new InvalidCallException("Table not found: $tableName");
throw new InvalidParamException("Table not found: $tableName");
} else {
throw new InvalidCallException("There is not sequence associated with table '$tableName'.'");
throw new InvalidParamException("There is not sequence associated with table '$tableName'.'");
}
}

8
framework/util/ArrayHelper.php

@ -9,7 +9,7 @@
namespace yii\util;
use yii\base\InvalidCallException;
use yii\base\InvalidParamException;
/**
* ArrayHelper provides additional array functionality you can use in your
@ -242,7 +242,7 @@ class ArrayHelper
* 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.
* When sorting by multiple keys with different sort flags, use an array of sort flags.
* @throws InvalidCallException if the $ascending or $sortFlag parameters do not have
* @throws InvalidParamException if the $ascending or $sortFlag parameters do not have
* correct number of elements as that of $key.
*/
public static function multisort(&$array, $key, $ascending = true, $sortFlag = SORT_REGULAR)
@ -255,12 +255,12 @@ class ArrayHelper
if (is_scalar($ascending)) {
$ascending = array_fill(0, $n, $ascending);
} elseif (count($ascending) !== $n) {
throw new InvalidCallException('The length of $ascending parameter must be the same as that of $keys.');
throw new InvalidParamException('The length of $ascending parameter must be the same as that of $keys.');
}
if (is_scalar($sortFlag)) {
$sortFlag = array_fill(0, $n, $sortFlag);
} elseif (count($sortFlag) !== $n) {
throw new InvalidCallException('The length of $ascending parameter must be the same as that of $keys.');
throw new InvalidParamException('The length of $ascending parameter must be the same as that of $keys.');
}
$args = array();
foreach ($keys as $i => $key) {

48
framework/util/VarDumper.php

@ -17,14 +17,15 @@ namespace yii\util;
* recursive display of some peculiar variables.
*
* VarDumper can be used as follows,
* <pre>
*
* ~~~
* VarDumper::dump($var);
* </pre>
* ~~~
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class VarDumper
class CVarDumper
{
private static $_objects;
private static $_output;
@ -58,8 +59,7 @@ class VarDumper
self::$_objects = array();
self::$_depth = $depth;
self::dumpInternal($var, 0);
if($highlight)
{
if ($highlight) {
$result = highlight_string("<?php\n" . self::$_output, true);
self::$_output = preg_replace('/&lt;\\?php<br \\/>/', '', $result, 1);
}
@ -72,8 +72,7 @@ class VarDumper
*/
private static function dumpInternal($var, $level)
{
switch(gettype($var))
{
switch (gettype($var)) {
case 'boolean':
self::$_output .= $var ? 'true' : 'false';
break;
@ -96,45 +95,38 @@ class VarDumper
self::$_output .= '{unknown}';
break;
case 'array':
if(self::$_depth<=$level)
if (self::$_depth <= $level) {
self::$_output .= 'array(...)';
else if(empty($var))
} elseif (empty($var)) {
self::$_output .= 'array()';
else
{
} else {
$keys = array_keys($var);
$spaces = str_repeat(' ', $level * 4);
self::$_output .= "array\n" . $spaces . '(';
foreach($keys as $key)
{
if(gettype($key)=='integer')
$key2=$key;
else
$key2="'".str_replace("'","\\'",$key)."'";
self::$_output.="\n".$spaces." $key2 => ";
self::$_output.=self::dumpInternal($var[$key],$level+1);
foreach ($keys as $key) {
self::$_output .= "\n" . $spaces . ' ';
self::dumpInternal($key, 0);
self::$_output .= ' => ';
self::dumpInternal($var[$key], $level + 1);
}
self::$_output .= "\n" . $spaces . ')';
}
break;
case 'object':
if(($id=array_search($var,self::$_objects,true))!==false)
if (($id = array_search($var, self::$_objects, true)) !== false) {
self::$_output .= get_class($var) . '#' . ($id + 1) . '(...)';
else if(self::$_depth<=$level)
} elseif (self::$_depth <= $level) {
self::$_output .= get_class($var) . '(...)';
else
{
$id=array_push(self::$_objects,$var);
} else {
$id = self::$_objects[] = $var;
$className = get_class($var);
$members = (array)$var;
$spaces = str_repeat(' ', $level * 4);
self::$_output .= "$className#$id\n" . $spaces . '(';
foreach($members as $key=>$value)
{
foreach ($members as $key => $value) {
$keyDisplay = strtr(trim($key), array("\0" => ':'));
self::$_output .= "\n" . $spaces . " [$keyDisplay] => ";
self::$_output.=self::dumpInternal($value,$level+1);
self::dumpInternal($value, $level + 1);
}
self::$_output .= "\n" . $spaces . ')';
}

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

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

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

@ -75,7 +75,7 @@ class VectorTest extends \yiiunit\TestCase
$this->assertEquals(2,$this->vector->indexOf($this->item2));
$this->assertEquals(0,$this->vector->indexOf($this->item3));
$this->assertEquals(1,$this->vector->indexOf($this->item1));
$this->setExpectedException('yii\base\InvalidCallException');
$this->setExpectedException('yii\base\InvalidParamException');
$this->vector->insertAt(4,$this->item3);
}
@ -97,7 +97,7 @@ class VectorTest extends \yiiunit\TestCase
$this->assertEquals(-1,$this->vector->indexOf($this->item2));
$this->assertEquals(1,$this->vector->indexOf($this->item3));
$this->assertEquals(0,$this->vector->indexOf($this->item1));
$this->setExpectedException('yii\base\InvalidCallException');
$this->setExpectedException('yii\base\InvalidParamException');
$this->vector->removeAt(2);
}
@ -135,7 +135,7 @@ class VectorTest extends \yiiunit\TestCase
$array=array($this->item3,$this->item1);
$this->vector->copyFrom($array);
$this->assertTrue(count($array)==2 && $this->vector[0]===$this->item3 && $this->vector[1]===$this->item1);
$this->setExpectedException('yii\base\InvalidCallException');
$this->setExpectedException('yii\base\InvalidParamException');
$this->vector->copyFrom($this);
}
@ -150,7 +150,7 @@ class VectorTest extends \yiiunit\TestCase
$this->vector->mergeWith($vector);
$this->assertTrue($this->vector->getCount()==5 && $this->vector[0]===$this->item1 && $this->vector[3]===$this->item1 && $this->vector[4]===1);
$this->setExpectedException('yii\base\InvalidCallException');
$this->setExpectedException('yii\base\InvalidParamException');
$this->vector->mergeWith($this);
}
@ -164,7 +164,7 @@ class VectorTest extends \yiiunit\TestCase
{
$this->assertTrue($this->vector[0]===$this->item1);
$this->assertTrue($this->vector[1]===$this->item2);
$this->setExpectedException('yii\base\InvalidCallException');
$this->setExpectedException('yii\base\InvalidParamException');
$a=$this->vector[2];
}

Loading…
Cancel
Save