forked from kvnZero/hyperf-APIJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeadMethod.php
More file actions
39 lines (31 loc) · 1.11 KB
/
HeadMethod.php
File metadata and controls
39 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\ApiJson\Method;
use App\ApiJson\Parse\Handle;
use App\Event\ApiJson\QueryExecuteAfter;
use App\Event\ApiJson\QueryExecuteBefore;
use Hyperf\Utils\ApplicationContext;
use Psr\EventDispatcher\EventDispatcherInterface;
class HeadMethod extends AbstractMethod
{
protected function validateCondition(): bool
{
return $this->method == 'HEAD';
}
protected function process()
{
$handle = new Handle($this->tableEntity->getConditionEntity(), $this->tableEntity);
$handle->buildQuery();
$event = new QueryExecuteBefore($this->query->toSql(), $this->method);
ApplicationContext::getContainer()->get(EventDispatcherInterface::class)->dispatch($event);
if(is_null($event->result)) {
$count = $this->query->count();
} else {
$count = $event->result;
}
$event = new QueryExecuteAfter($this->query->toSql(), $this->method, $count);
ApplicationContext::getContainer()->get(EventDispatcherInterface::class)->dispatch($event);
return [
'count' => $event->result
];
}
}