diff --git a/Annotation/Get.php b/Annotation/Get.php index 1004b76..d7fcb0f 100644 --- a/Annotation/Get.php +++ b/Annotation/Get.php @@ -12,6 +12,7 @@ use Kiri\Annotation\AbstractAttribute; /** * Class Get * @package Annotation\Model + * @deprecated */ #[Attribute(Attribute::TARGET_METHOD)] class Get extends AbstractAttribute { @@ -33,8 +34,8 @@ use Kiri\Annotation\AbstractAttribute; */ public function execute(mixed $class, mixed $method = null): bool { - $keys = \Kiri::getDi()->get(Getter::class); - $keys->write($this->name, $class, $method); +// $keys = \Kiri::getDi()->get(Getter::class); +// $keys->write($this->name, $class, $method); return true; } diff --git a/Annotation/Set.php b/Annotation/Set.php index f39876d..e6e55fc 100644 --- a/Annotation/Set.php +++ b/Annotation/Set.php @@ -7,6 +7,10 @@ namespace Database\Annotation; use Database\Base\Setter; use Kiri\Annotation\AbstractAttribute; + +/** + * @deprecated + */ #[\Attribute(\Attribute::TARGET_METHOD)] class Set extends AbstractAttribute { @@ -27,8 +31,8 @@ use Kiri\Annotation\AbstractAttribute; */ public function execute(mixed $class, mixed $method = null): bool { - $keys = \Kiri::getDi()->get(Setter::class); - $keys->write($this->name, $class, $method); +// $keys = \Kiri::getDi()->get(Setter::class); +// $keys->write($this->name, $class, $method); return true; } diff --git a/Base/Model.php b/Base/Model.php index 61657ff..b7f9f67 100644 --- a/Base/Model.php +++ b/Base/Model.php @@ -75,6 +75,12 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T protected bool $isNewExample = TRUE; + /** + * @var array + */ + protected array $overwriteFields = []; + + /** * @var array */ diff --git a/Model.php b/Model.php index b127231..3ba92e1 100644 --- a/Model.php +++ b/Model.php @@ -265,9 +265,9 @@ class Model extends Base\Model public function toArray(): array { $data = $this->_attributes; - $keys = Kiri::getDi()->get(Getter::class)->getAll(static::class); - foreach ($keys as $key => $datum) { - $data[$key] = $this->{$datum}($data[$key]); + foreach ($this->overwriteFields as $key => $datum) { + $method = 'get' . ucfirst($key) . 'Attribute'; + $data[$key] = $this->{$method}($datum); } return $this->withRelates($data); } @@ -284,8 +284,8 @@ class Model extends Base\Model } return $relates; } - - + + /** * @param ModelInterface|string $modelName * @param $foreignKey @@ -293,13 +293,14 @@ class Model extends Base\Model * @return string * @throws Exception */ - private function _hasBase(ModelInterface|string $modelName, $foreignKey, $localKey):string { + private function _hasBase(ModelInterface|string $modelName, $foreignKey, $localKey): string + { if (($value = $this->{$localKey}) === null) { throw new Exception("Need join table primary key."); } - + $relation = $this->getRelation(); - + $primaryKey = $modelName . $foreignKey . $value; if (!$relation->hasIdentification($primaryKey)) { $relation->bindIdentification($primaryKey, $modelName::query()->where([$foreignKey => $value]));