Files
kiri-databases/HasCount.php
T

40 lines
761 B
PHP
Raw Normal View History

2022-01-09 03:49:51 +08:00
<?php
declare(strict_types=1);
namespace Database;
use Database\Traits\HasBase;
2022-01-19 14:59:46 +08:00
use Exception;
2022-01-09 03:49:51 +08:00
/**
* Class HasCount
* @package Database
*/
class HasCount extends HasBase
{
/**
* @param $name
* @param $arguments
* @return ActiveQuery
2022-01-19 14:57:14 +08:00
* @throws ActiveQuery|static
2022-01-09 03:49:51 +08:00
*/
2022-01-19 14:57:14 +08:00
public function __call($name, $arguments)
2022-01-09 03:49:51 +08:00
{
2022-01-19 14:59:46 +08:00
if (!method_exists($this, $name)) {
return $this->_relation->getQuery($this->model::className())->$name(...$arguments);
2022-01-09 03:49:51 +08:00
}
2022-01-19 14:59:46 +08:00
return call_user_func([$this, $name], ...$arguments);
2022-01-09 03:49:51 +08:00
}
/**
* @return array|null|ModelInterface
* @throws Exception
*/
public function get(): array|ModelInterface|null
{
return $this->_relation->count($this->model::className(), $this->value);
}
}