-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; | ||
|
||
use Yiisoft\ActiveRecord\ActiveRecord; | ||
|
||
/** | ||
* Class CustomerClosureField. | ||
* | ||
* @property int $id | ||
* @property string $name | ||
* @property string $email | ||
* @property string $address | ||
* @property int $status | ||
* @property string $sex | ||
*/ | ||
final class CustomerExtraAttributes extends ActiveRecord | ||
{ | ||
private array $extraAttributes = [ | ||
'sex' => 'm', | ||
]; | ||
|
||
public function getTableName(): string | ||
{ | ||
return 'customer'; | ||
} | ||
|
||
public function getAttribute(string $name): mixed | ||
{ | ||
if (array_key_exists($name, $this->extraAttributes)) { | ||
return $this->extraAttributes[$name]; | ||
} | ||
|
||
return parent::getAttribute($name); | ||
} | ||
|
||
public function getAttributes(array $names = null, array $except = []): array | ||
{ | ||
return array_merge(parent::getAttributes($names, $except), $this->extraAttributes); | ||
} | ||
|
||
public function hasAttribute($name): bool | ||
{ | ||
return array_key_exists($name, $this->extraAttributes) || parent::hasAttribute($name); | ||
} | ||
} |