qqq
This commit is contained in:
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Database\Base;
|
||||
|
||||
|
||||
use Database\ActiveQuery;
|
||||
use Database\ModelInterface;
|
||||
use Exception;
|
||||
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Base;
|
||||
|
||||
use Database\ModelInterface;
|
||||
|
||||
class Getter
|
||||
{
|
||||
|
||||
private array $getter = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $className
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function write(string $name, string $className, string $method): void
|
||||
{
|
||||
if (!isset($this->getter[$className])) {
|
||||
$this->getter[$className] = [];
|
||||
}
|
||||
$this->getter[$className][$name] = $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @return array
|
||||
*/
|
||||
public function getAll(string $className): array
|
||||
{
|
||||
return $this->getter[$className] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $className, string $name): bool
|
||||
{
|
||||
return isset($this->getter[$className]) && isset($this->getter[$className][$name]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ModelInterface $class
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
public function override(ModelInterface $class, string $key, mixed $value): mixed
|
||||
{
|
||||
$method = $this->getter[$class::class][$key] ?? null;
|
||||
if ($method !== null) {
|
||||
return $class->{$method}($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string $name
|
||||
* @return string|null
|
||||
*/
|
||||
public function get(string $className, string $name): ?string
|
||||
{
|
||||
if (!$this->has($className,$name)) {
|
||||
return null;
|
||||
}
|
||||
return $this->getter[$className][$name];
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -536,7 +536,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
||||
}
|
||||
$validate = $this->resolve($rule);
|
||||
if (!$validate->validation()) {
|
||||
return \Kiri::getLogger()->addError($validate->getError(), 'mysql');
|
||||
return \Kiri::getLogger()->failure($validate->getError(), 'mysql');
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Base;
|
||||
|
||||
use Database\ModelInterface;
|
||||
|
||||
class Setter
|
||||
{
|
||||
|
||||
private array $setter = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $className
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function write(string $name, string $className, string $method): void
|
||||
{
|
||||
if (!isset($this->setter[$className])) {
|
||||
$this->setter[$className] = [];
|
||||
}
|
||||
$this->setter[$className][$name] = $method;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $className, string $name): bool
|
||||
{
|
||||
return isset($this->setter[$className]) && isset($this->setter[$className][$name]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @return array|null
|
||||
*/
|
||||
public function getAll(string $className): ?array
|
||||
{
|
||||
return $this->setter[$className] ?? null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ModelInterface $class
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
public function override(ModelInterface $class, string $key, mixed $value): mixed
|
||||
{
|
||||
$method = $this->setter[$class::class][$key] ?? null;
|
||||
if ($method !== null) {
|
||||
return $class->{$method}($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string $name
|
||||
* @return string|null
|
||||
*/
|
||||
public function get(string $className, string $name): ?string
|
||||
{
|
||||
if (!$this->has($className, $name)) {
|
||||
return null;
|
||||
}
|
||||
return $this->setter[$className][$name];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user