mirror of
https://github.com/dg/dibi.git
synced 2025-08-28 08:19:48 +02:00
DibiRow: shows suggestions for missing columns
This commit is contained in:
@@ -47,6 +47,13 @@ class DibiRow implements ArrayAccess, IteratorAggregate, Countable
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function __get($key)
|
||||||
|
{
|
||||||
|
$hint = DibiHelpers::getSuggestion(array_keys((array) $this), $key);
|
||||||
|
trigger_error("Attempt to read missing column '$key'" . ($hint ? ", did you mean '$hint'?" : '.'), E_USER_NOTICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/********************* interfaces ArrayAccess, Countable & IteratorAggregate ****************d*g**/
|
/********************* interfaces ArrayAccess, Countable & IteratorAggregate ****************d*g**/
|
||||||
|
|
||||||
|
|
||||||
|
@@ -24,16 +24,26 @@ Assert::true(isset($row['title']));
|
|||||||
// missing
|
// missing
|
||||||
Assert::error(function () use ($row) {
|
Assert::error(function () use ($row) {
|
||||||
$x = $row->missing;
|
$x = $row->missing;
|
||||||
}, E_NOTICE, 'Undefined property: DibiRow::$missing');
|
}, E_USER_NOTICE, "Attempt to read missing column 'missing'.");
|
||||||
|
|
||||||
Assert::error(function () use ($row) {
|
Assert::error(function () use ($row) {
|
||||||
$x = $row['missing'];
|
$x = $row['missing'];
|
||||||
}, E_NOTICE, 'Undefined property: DibiRow::$missing');
|
}, E_USER_NOTICE, "Attempt to read missing column 'missing'.");
|
||||||
|
|
||||||
Assert::false(isset($row->missing));
|
Assert::false(isset($row->missing));
|
||||||
Assert::false(isset($row['missing']));
|
Assert::false(isset($row['missing']));
|
||||||
|
|
||||||
|
|
||||||
|
// suggestions
|
||||||
|
Assert::error(function () use ($row) {
|
||||||
|
$x = $row->tilte;
|
||||||
|
}, E_USER_NOTICE, "Attempt to read missing column 'tilte', did you mean 'title'?");
|
||||||
|
|
||||||
|
Assert::error(function () use ($row) {
|
||||||
|
$x = $row['tilte'];
|
||||||
|
}, E_USER_NOTICE, "Attempt to read missing column 'tilte', did you mean 'title'?");
|
||||||
|
|
||||||
|
|
||||||
// to array
|
// to array
|
||||||
Assert::same(['product_id' => 1, 'title' => 'Chair'], iterator_to_array($row));
|
Assert::same(['product_id' => 1, 'title' => 'Chair'], iterator_to_array($row));
|
||||||
Assert::same(['product_id' => 1, 'title' => 'Chair'], $row->toArray());
|
Assert::same(['product_id' => 1, 'title' => 'Chair'], $row->toArray());
|
||||||
|
Reference in New Issue
Block a user