-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathIndex.php
More file actions
62 lines (52 loc) · 2.34 KB
/
Copy pathIndex.php
File metadata and controls
62 lines (52 loc) · 2.34 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace BNETDocs\Controllers\Packet;
class Index extends \BNETDocs\Controllers\Base
{
public function __construct()
{
$this->model = new \BNETDocs\Models\Packet\Index();
}
public function invoke(?array $args): bool
{
if (is_null($args) || count($args) != 1)
throw new \InvalidArgumentException('Arguments must have exactly 1 item');
$q = \BNETDocs\Libraries\Core\Router::query();
$this->model->order = isset($q['order']) ? $q['order'] : 'packet-id-asc';
$pktapplayer = !isset($q['pktapplayer']) ? [] : (is_array($q['pktapplayer']) ? $q['pktapplayer'] : [$q['pktapplayer']]);
$this->model->pktapplayer = array_map('intval', array_filter($pktapplayer, fn($v) => $v !== ''));
switch ($this->model->order)
{
case 'created-datetime-asc': $this->model->order = ['created_datetime','ASC']; break;
case 'created-datetime-desc': $this->model->order = ['created_datetime','DESC']; break;
case 'id-asc': $this->model->order = ['id','ASC']; break;
case 'id-desc': $this->model->order = ['id','DESC']; break;
case 'packet-id-asc': $this->model->order = ['packet_application_layer_id,packet_id','ASC']; break;
case 'packet-id-desc': $this->model->order = ['packet_application_layer_id,packet_id','DESC']; break;
case 'user-id-asc': $this->model->order = ['user_id','ASC']; break;
case 'user-id-desc': $this->model->order = ['user_id','DESC']; break;
default: $this->model->order = null;
}
$this->model->application_layers = \BNETDocs\Libraries\Packet\Application::getAllAsObjects();
if (empty($this->model->pktapplayer))
{
foreach ($this->model->application_layers as $layer)
{
$this->model->pktapplayer[] = $layer->getId();
}
}
$this->model->packets = \BNETDocs\Libraries\Packet\Packet::getAllPackets(
'`packet_application_layer_id` IN (' . implode(',', array_map('intval', $this->model->pktapplayer)) . ')',
$this->model->order
);
$deduplicate = (bool) array_shift($args);
if ($deduplicate)
{
$r = [];
foreach ($this->model->packets as $item) $r[$item->getLabel()] = $item;
$this->model->packets = $r;
}
$this->model->timestamp = new \BNETDocs\Libraries\Core\DateTimeImmutable('now');
$this->model->_responseCode = \BNETDocs\Libraries\Core\HttpCode::HTTP_OK;
return true;
}
}