Skip to content

Commit

Permalink
Add definition
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Yves <[email protected]>
  • Loading branch information
docjyJ committed Jul 14, 2024
1 parent c8e4f70 commit 70224e6
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
7 changes: 7 additions & 0 deletions php/src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Container {
private int $maxShutdownTime;
private ContainerPorts $ports;
private string $internalPorts;
private ContainerCaddyRoutes $caddyRoutes;
private ContainerVolumes $volumes;
private ContainerEnvironmentVariables $containerEnvironmentVariables;
/** @var string[] */
Expand Down Expand Up @@ -46,6 +47,7 @@ public function __construct(
int $maxShutdownTime,
ContainerPorts $ports,
string $internalPorts,
ContainerCaddyRoutes $caddyRoutes,
ContainerVolumes $volumes,
ContainerEnvironmentVariables $containerEnvironmentVariables,
array $dependsOn,
Expand All @@ -71,6 +73,7 @@ public function __construct(
$this->maxShutdownTime = $maxShutdownTime;
$this->ports = $ports;
$this->internalPorts = $internalPorts;
$this->caddyRoutes = $caddyRoutes;
$this->volumes = $volumes;
$this->containerEnvironmentVariables = $containerEnvironmentVariables;
$this->dependsOn = $dependsOn;
Expand Down Expand Up @@ -158,6 +161,10 @@ public function GetInternalPort() : string {
return $this->internalPorts;
}

public function GetCaddyRoutes() : ContainerCaddyRoutes {
return $this->caddyRoutes;
}

public function GetVolumes() : ContainerVolumes {
return $this->volumes;
}
Expand Down
23 changes: 23 additions & 0 deletions php/src/Container/ContainerCaddyRoute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php


namespace AIO\Container;

class ContainerCaddyRoute {
public string $route;
public string $subDomain;
public string $target;
public string $uriStripPrefix;

public function __construct(
string $route,
string $subDomain,
string $target,
string $uriStripPrefix
) {
$this->route = $route;
$this->subDomain = $subDomain;
$this->target = $target;
$this->uriStripPrefix = $uriStripPrefix;
}
}
21 changes: 21 additions & 0 deletions php/src/Container/ContainerCaddyRoutes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php



namespace AIO\Container;

class ContainerCaddyRoutes {
/** @var ContainerCaddyRoute[] */
private array $caddyRoutes = [];

public function AddCaddyRoute(ContainerCaddyRoute $caddyRoute) : void {
$this->caddyRoutes[] = $caddyRoute;
}

/**
* @return ContainerCaddyRoute[]
*/
public function GetCaddyRoutes() : array {
return $this->caddyRoutes;
}
}
21 changes: 19 additions & 2 deletions php/src/ContainerDefinitionFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use AIO\Container\AioVariables;
use AIO\Container\Container;
use AIO\Container\ContainerCaddyRoute;
use AIO\Container\ContainerCaddyRoutes;
use AIO\Container\ContainerEnvironmentVariables;
use AIO\Container\ContainerPort;
use AIO\Container\ContainerPorts;
Expand Down Expand Up @@ -99,7 +101,7 @@ private function GetDefinition(): array

$ports = new ContainerPorts();
if (isset($entry['ports'])) {
foreach ($entry['ports'] as $value) {
foreach ($entry['ports'] as $value) {
$ports->AddPort(
new ContainerPort(
$value['port_number'],
Expand Down Expand Up @@ -156,6 +158,20 @@ private function GetDefinition(): array
}
}

$caddyRoutes = new ContainerCaddyRoutes();
if (isset($entry['caddy_routes'])) {
foreach ($entry['caddy_routes'] as $value) {
$caddyRoutes->AddCaddyRoute(
new ContainerCaddyRoute(
$value['route'],
$value['sub_domain'],
$value['target'],
$value['uri_strip_prefix']
)
);
}
}

$dependsOn = [];
if (isset($entry['depends_on'])) {
$valueDependsOn = $entry['depends_on'];
Expand Down Expand Up @@ -204,7 +220,7 @@ private function GetDefinition(): array
$dependsOn[] = $value;
}
}

$variables = new ContainerEnvironmentVariables();
if (isset($entry['environment'])) {
foreach ($entry['environment'] as $value) {
Expand Down Expand Up @@ -307,6 +323,7 @@ private function GetDefinition(): array
$maxShutdownTime,
$ports,
$internalPort,
$caddyRoutes,
$volumes,
$variables,
$dependsOn,
Expand Down

0 comments on commit 70224e6

Please sign in to comment.