2020-08-31 12:38:32 +08:00
|
|
|
<?php
|
2020-10-29 18:17:25 +08:00
|
|
|
declare(strict_types=1);
|
2020-08-31 12:38:32 +08:00
|
|
|
|
|
|
|
|
namespace Database;
|
|
|
|
|
|
|
|
|
|
use Exception;
|
2021-02-25 18:56:37 +08:00
|
|
|
use Database\Traits\HasBase;
|
2020-08-31 12:38:32 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class HasCount
|
|
|
|
|
* @package Database
|
|
|
|
|
*/
|
|
|
|
|
class HasCount extends HasBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $name
|
|
|
|
|
* @param $arguments
|
2021-01-16 16:57:35 +08:00
|
|
|
* @return ActiveQuery
|
2020-08-31 12:38:32 +08:00
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2021-01-16 16:57:35 +08:00
|
|
|
public function __call($name, $arguments): mixed
|
2020-08-31 12:38:32 +08:00
|
|
|
{
|
2021-01-16 16:57:35 +08:00
|
|
|
if (method_exists($this, $name)) {
|
|
|
|
|
return call_user_func([$this, $name], ...$arguments);
|
|
|
|
|
}
|
|
|
|
|
return $this->_relation->getQuery($this->model::className())->$name(...$arguments);
|
2020-08-31 12:38:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array|null|ActiveRecord
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2020-12-17 14:09:14 +08:00
|
|
|
public function get(): array|ActiveRecord|null
|
2020-08-31 12:38:32 +08:00
|
|
|
{
|
|
|
|
|
return $this->_relation->count($this->model::className(), $this->value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|