Skip to content

Commit

Permalink
added __debugInfo magic method, do not use field default values in row
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed May 10, 2016
1 parent 18bc1ef commit 5213700
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,30 @@ public function __construct(Table $table)
{
parent::__construct($table);

$defaults = [];

foreach ($table->getScheme()['fields'] as $name => $field) {
$defaults[$name] = $field['default'];
$this->values[$name] = null;
}

$this->init($defaults);
}

/**
* Clear the current cache.
* Debug info.
*
* @return array
*/
public function clearCache()
public function __debugInfo()
{
$this->relations = [];
return [
'table' => $this->getTable()->name,
'values' => $this->values,
];
}

/**
* Initialize the row with the data from database.
*
* @param array $values
* @param array $relations
* Clear the current cache.
*/
public function init(array $values, array $relations = [])
public function clearCache()
{
$this->values = $values;
$this->relations = $relations;
$this->changed = false;
$this->relations = [];
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/RowCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ class RowCollection extends AbstractRow implements ArrayAccess, Iterator, Counta
private $rows = [];
private $loadedRelations = [];

/**
* Debug info.
*
* @return array
*/
public function __debugInfo()
{
return [
'table' => $this->getTable()->name,
'rows' => $this->rows,
];
}

/**
* Magic method to get properties from all rows.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ final public function __construct(SimpleCrud $db, $name)
$this->init();
}

/**
* Debug info.
*
* @return array
*/
public function __debugInfo()
{
return [
'name' => $this->name,
'fields' => $this->fields,
];
}

/**
* Callback used to init the table.
*/
Expand Down

0 comments on commit 5213700

Please sign in to comment.