Skip to content

Commit 6116aad

Browse files
committed
Move Servers class to Server/Index
1 parent f30fb6d commit 6116aad

File tree

9 files changed

+69
-69
lines changed

9 files changed

+69
-69
lines changed

src/Controllers/Servers.php renamed to src/Controllers/Server/Index.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?php
22

3-
namespace BNETDocs\Controllers;
3+
namespace BNETDocs\Controllers\Server;
44

55
use \BNETDocs\Libraries\Server\Server as ServerLib;
66

7-
class Servers extends Base
7+
class Index extends \BNETDocs\Controllers\Base
88
{
99
/**
1010
* Constructs a Controller, typically to initialize properties.
1111
*/
1212
public function __construct()
1313
{
14-
$this->model = new \BNETDocs\Models\Servers();
14+
$this->model = new \BNETDocs\Models\Server\Index();
1515
}
1616

1717
/**
@@ -24,7 +24,7 @@ public function invoke(?array $args): bool
2424
{
2525
$q = \BNETDocs\Libraries\Core\Router::query();
2626

27-
$this->model->server_types = array();
27+
$this->model->server_types = [];
2828
$this->model->servers = ServerLib::getAllServers();
2929
$this->model->status_bitmasks = [
3030
[

src/Models/Server/Index.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace BNETDocs\Models\Server;
4+
5+
class Index extends \BNETDocs\Models\ActiveUser
6+
{
7+
public ?array $server_types = null;
8+
public ?array $servers = null;
9+
public ?array $status_bitmasks = null;
10+
}

src/Models/Servers.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Templates/Servers.phtml renamed to src/Templates/Server/Index.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
2-
namespace BNETDocs\Templates;
2+
namespace BNETDocs\Templates\Server;
33
use \BNETDocs\Libraries\User\User;
44
use \CarlBennett\MVC\Libraries\Common;
55
use \CarlBennett\MVC\Libraries\Pair;

src/Views/Server/IndexHtml.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace BNETDocs\Views\Server;
4+
5+
class IndexHtml extends \BNETDocs\Views\Base\Html
6+
{
7+
public static function invoke(\BNETDocs\Interfaces\Model $model): void
8+
{
9+
if (!$model instanceof \BNETDocs\Models\Server\Index)
10+
{
11+
throw new \BNETDocs\Exceptions\InvalidModelException($model);
12+
}
13+
14+
(new \BNETDocs\Libraries\Core\Template($model, 'Server/Index'))->invoke();
15+
$model->_responseHeaders['Content-Type'] = self::mimeType();
16+
}
17+
}

src/Views/Server/IndexJson.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace BNETDocs\Views\Server;
4+
5+
class IndexJson extends \BNETDocs\Views\Base\Json
6+
{
7+
public static function invoke(\BNETDocs\Interfaces\Model $model): void
8+
{
9+
if (!$model instanceof \BNETDocs\Models\Server\Index)
10+
{
11+
throw new \BNETDocs\Exceptions\InvalidModelException($model);
12+
}
13+
14+
$content = [];
15+
16+
foreach ($model->server_types as $server_type)
17+
{
18+
$content['server_types'][] = [
19+
'id' => (int) $server_type->getId(),
20+
'label' => $server_type->getLabel()
21+
];
22+
}
23+
24+
foreach ($model->servers as $server)
25+
{
26+
$content['servers'][] = $server;
27+
}
28+
29+
$content['status_bitmasks'] = $model->status_bitmasks;
30+
31+
echo json_encode($content, self::jsonFlags());
32+
$model->_responseHeaders['Content-Type'] = self::mimeType();
33+
}
34+
}

src/Views/ServersHtml.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Views/ServersJson.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/main.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ function main(): void
107107
['#^/server/delete/?$#', 'Server\\Delete', ['Server\\DeleteHtml']],
108108
['#^/server/edit/?$#', 'Server\\Edit', ['Server\\EditHtml']],
109109
['#^/server/updatejob\.json$#', 'Server\\UpdateJob', ['Server\\UpdateJobJson']],
110-
['#^/servers\.html?$#', 'Servers', ['ServersHtml']],
111-
['#^/servers\.json$#', 'Servers', ['ServersJson']],
112-
['#^/servers/?$#', 'Servers', ['ServersHtml', 'ServersJson']],
110+
['#^/servers\.html?$#', 'Server\\Index', ['Server\\IndexHtml']],
111+
['#^/servers\.json$#', 'Server\\Index', ['Server\\IndexJson']],
112+
['#^/servers/?$#', 'Server\\Index', ['Server\\IndexHtml', 'Server\\IndexJson']],
113113
['#^/status\.json$#', 'Core\\Status', ['Core\\StatusJson']],
114114
['#^/status\.txt$#', 'Core\\Status', ['Core\\StatusPlain']],
115115
['#^/status/?$#', 'Core\\Status', ['Core\\StatusJson', 'Core\\StatusPlain']],

0 commit comments

Comments
 (0)