Files
kiri-databases/Traits/HasBase.php
T

80 lines
1.4 KiB
PHP
Raw Normal View History

2022-01-09 03:49:51 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/4 0004
* Time: 15:47
*/
declare(strict_types=1);
namespace Database\Traits;
use Database\ModelInterface;
use Database\Collection;
use Database\Relation;
2023-04-01 17:11:47 +08:00
use Kiri;
2022-01-09 03:49:51 +08:00
/**
* Class HasBase
* @package Database
*
* @include Query
2023-04-01 17:11:47 +08:00
*
* @method first($name)
* @method all($name)
* @method count($name)
2022-01-09 03:49:51 +08:00
*/
abstract class HasBase implements \Database\Traits\Relation
{
2023-04-20 23:16:36 +08:00
2023-12-12 15:35:35 +08:00
/** @var ModelInterface|Collection */
protected mixed $data = null;
/**
* @var ModelInterface
*/
protected mixed $model;
protected mixed $value = 0;
/**
* HasBase constructor.
* @param string $name
*/
public function __construct(public string $name)
{
}
/**
* @param $name
* @param $arguments
* @return static
* @throws
*/
public function __call($name, $arguments)
{
if ($name !== 'get') {
$relation = Kiri::getDi()->get(Relation::class);
$relation->getQuery($this->name)->$name(...$arguments);
return $this;
} else {
return $this->get();
}
}
/**
* @param $name
* @return mixed
*/
public function __get($name): mixed
{
if ($this->data === null) {
$this->data = $this->get();
}
return $this->data;
}
2022-01-09 03:49:51 +08:00
}