Skip to content

Commit 8570f36

Browse files
committed
Refactor packet layers from database into code
1 parent 2f959a9 commit 8570f36

15 files changed

+140
-350
lines changed

src/controllers/Packet/Index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace BNETDocs\Controllers\Packet;
44

55
use \BNETDocs\Libraries\Packet;
6-
use \BNETDocs\Libraries\PacketApplicationLayer as PktAppLayer;
6+
use \BNETDocs\Libraries\Packet\Application as ApplicationLayer;
77
use \BNETDocs\Models\Packet\Index as PacketIndexModel;
88
use \BNETDocs\Views\Packet\IndexHtml as PacketIndexHtmlView;
99
use \BNETDocs\Views\Packet\IndexJSON as PacketIndexJSONView;
@@ -62,7 +62,7 @@ public function &run( Router &$router, View &$view, array &$args ) {
6262
$order = null;
6363
}
6464

65-
$model->application_layers = PktAppLayer::getAllPacketApplicationLayers();
65+
$model->application_layers = ApplicationLayer::getAllAsObjects();
6666

6767
if ( empty( $model->pktapplayer )) {
6868
foreach ( $model->application_layers as $layer ) {

src/controllers/Packet/View.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
use \BNETDocs\Libraries\Packet;
88
use \BNETDocs\Libraries\Product;
99
use \BNETDocs\Models\Packet\View as PacketViewModel;
10+
1011
use \CarlBennett\MVC\Libraries\Common;
1112
use \CarlBennett\MVC\Libraries\Controller;
1213
use \CarlBennett\MVC\Libraries\Router;
1314
use \CarlBennett\MVC\Libraries\View as ViewLib;
15+
1416
use \DateTime;
1517
use \DateTimeZone;
1618

src/libraries/Exceptions/CommentNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class CommentNotFoundException extends BNETDocsException {
1010

1111
public function __construct($query, Exception &$prev_ex = null) {
12-
parent::__construct("Comment not found", 21, $prev_ex);
12+
parent::__construct("Comment not found", 18, $prev_ex);
1313
Logger::logMetric("query", $query);
1414
}
1515

src/libraries/Exceptions/EventNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class EventNotFoundException extends BNETDocsException {
1010

1111
public function __construct($id, Exception &$prev_ex = null) {
12-
parent::__construct('Event not found', 22, $prev_ex);
12+
parent::__construct('Event not found', 19, $prev_ex);
1313
Logger::logMetric('event_id', $id);
1414
}
1515

src/libraries/Exceptions/PacketApplicationLayerNotFoundException.php

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

src/libraries/Exceptions/PacketDirectionInvalidException.php

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

src/libraries/Exceptions/PacketTransportLayerNotFoundException.php

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

src/libraries/Exceptions/ProductNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class ProductNotFoundException extends BNETDocsException {
1010

1111
public function __construct($query, Exception &$prev_ex = null) {
12-
parent::__construct("Product not found", 20, $prev_ex);
12+
parent::__construct("Product not found", 17, $prev_ex);
1313
Logger::logMetric("query", $query);
1414
}
1515

src/libraries/Exceptions/Reference.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ All of the following errors are subclassed from the `BNETDocsException` class.
2121
| 14 | `PacketNotFoundException` | Packet not found |
2222
| 15 | `DocumentNotFoundException` | Document not found |
2323
| 16 | `RecaptchaException` | `$message` |
24-
| 17 | `PacketApplicationLayerNotFoundException` | Packet application layer not found |
25-
| 18 | `PacketTransportLayerNotFoundException` | Packet transport layer not found |
26-
| 19 | `PacketDirectionInvalidException` | Packet direction is invalid |
27-
| 20 | `ProductNotFoundException` | Product not found |
28-
| 21 | `CommentNotFoundException` | Comment not found |
29-
| 22 | `EventNotFoundException` | Event not found |
24+
| 17 | `ProductNotFoundException` | Product not found |
25+
| 18 | `CommentNotFoundException` | Comment not found |
26+
| 19 | `EventNotFoundException` | Event not found |

src/libraries/Packet.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace BNETDocs\Libraries;
44

5-
use \BNETDocs\Libraries\Exceptions\PacketDirectionInvalidException;
65
use \BNETDocs\Libraries\Exceptions\PacketNotFoundException;
76
use \BNETDocs\Libraries\Exceptions\QueryException;
8-
use \BNETDocs\Libraries\PacketApplicationLayer;
9-
use \BNETDocs\Libraries\PacketTransportLayer;
7+
use \BNETDocs\Libraries\Packet\Application as ApplicationLayer;
8+
use \BNETDocs\Libraries\Packet\Transport as TransportLayer;
109
use \BNETDocs\Libraries\User;
1110

1211
use \CarlBennett\MVC\Libraries\Common;
@@ -20,6 +19,7 @@
2019
use \PDO;
2120
use \PDOException;
2221
use \StdClass;
22+
use \UnexpectedValueException;
2323

2424
class Packet implements JsonSerializable {
2525

@@ -332,7 +332,7 @@ public function getOptionsBitmask() {
332332
}
333333

334334
public function getPacketApplicationLayer() {
335-
return new PacketApplicationLayer( $this->packet_application_layer );
335+
return new ApplicationLayer( $this->packet_application_layer );
336336
}
337337

338338
public function getPacketApplicationLayerId() {
@@ -349,7 +349,9 @@ public function getPacketDirectionLabel() {
349349
case self::DIRECTION_SERVER_CLIENT: return 'Server to Client';
350350
case self::DIRECTION_PEER_TO_PEER: return 'Peer to Peer';
351351
default:
352-
throw new PacketDirectionInvalidException( $this->packet_direction_id );
352+
throw new UnexpectedValueException(sprintf(
353+
'packet direction: %d is invalid', $this->packet_direction_id
354+
));
353355
}
354356
}
355357

@@ -359,7 +361,9 @@ public function getPacketDirectionTag() {
359361
case self::DIRECTION_SERVER_CLIENT: return 'S>C';
360362
case self::DIRECTION_PEER_TO_PEER: return 'P2P';
361363
default:
362-
throw new PacketDirectionInvalidException( $this->packet_direction_id );
364+
throw new UnexpectedValueException(sprintf(
365+
'packet direction: %d is invalid', $this->packet_direction_id
366+
));
363367
}
364368
}
365369

@@ -393,7 +397,7 @@ public function getPacketRemarks( $prepare ) {
393397
}
394398

395399
public function getPacketTransportLayer() {
396-
return new PacketTransportLayer( $this->packet_transport_layer_id );
400+
return new TransportLayer( $this->packet_transport_layer_id );
397401
}
398402

399403
public function getPacketTransportLayerId() {

0 commit comments

Comments
 (0)