Skip to content

Commit 63dade3

Browse files
authored
Made the constructor final. Added getInternalRow()
1 parent a94046a commit 63dade3

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

src/Bean.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ abstract class Bean implements \CoolBeans\Contract\Row, \IteratorAggregate
1111
protected \ReflectionClass $reflection;
1212
protected \CoolBeans\Contract\PrimaryKey $primaryKey;
1313

14-
public function __construct(
14+
final public function __construct(
1515
protected \Nette\Database\Table\ActiveRow $row,
16+
private bool $extraColumns = false,
1617
)
1718
{
1819
$this->reflection = new \ReflectionClass(static::class);
1920
$this->primaryKey = \CoolBeans\Contract\PrimaryKey::create($this->row);
2021

21-
if (\CoolBeans\Config::$validateColumns) {
22-
$this->validateMissingColumns();
22+
if (\CoolBeans\Config::$validateColumns && !$this->extraColumns) {
23+
$this->validateMissingProperties();
2324
}
2425

2526
if (\CoolBeans\Config::$validateTableName) {
@@ -112,6 +113,14 @@ public function refresh() : void
112113
$this->initiateProperties();
113114
}
114115

116+
/**
117+
* Returns internal Nette row.
118+
*/
119+
public function getInternalRow() : \Nette\Database\Table\ActiveRow
120+
{
121+
return $this->row;
122+
}
123+
115124
/**
116125
* Selects referenced row from $table where <referencedRowPrimary> = $throughColumn
117126
*/
@@ -134,7 +143,7 @@ protected function related(string $table, ?string $throughColumn = null) : \Nett
134143
* Foo -> foo
135144
* FooBar -> foo_bar
136145
*/
137-
protected function validateTableName() : void
146+
private function validateTableName() : void
138147
{
139148
$tableName = $this->getTableName();
140149
$className = $this->reflection->getShortName();
@@ -152,7 +161,7 @@ protected function validateTableName() : void
152161
/**
153162
* Validates whether every column in database have its column property.
154163
*/
155-
protected function validateMissingColumns() : void
164+
private function validateMissingProperties() : void
156165
{
157166
foreach ($this->row->toArray() as $name => $value) {
158167
if (!$this->offsetExists($name)) {
@@ -164,7 +173,7 @@ protected function validateMissingColumns() : void
164173
/**
165174
* Initiates values into column properties.
166175
*/
167-
protected function initiateProperties() : void
176+
private function initiateProperties() : void
168177
{
169178
foreach ($this->reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
170179
$type = $property->getType();

0 commit comments

Comments
 (0)