Skip to content

Commit 4521fa0

Browse files
authored
Merge pull request #9 from php-etl/feature/new-commands
Added commands for docker and composer
2 parents 703bb1d + 47e3ddf commit 4521fa0

7 files changed

+120
-2
lines changed

src/Argument.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Dockerfile;
6+
7+
final readonly class Argument implements Variable
8+
{
9+
public function __construct(
10+
public string $name,
11+
) {
12+
}
13+
14+
public function __toString()
15+
{
16+
return "\${{$this->name}}";
17+
}
18+
}

src/Dockerfile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ final class Dockerfile implements \IteratorAggregate, \Countable, FileInterface,
1212
/** @var iterable|Dockerfile\LayerInterface[] */
1313
private iterable $layers;
1414

15-
public function __construct(null|Dockerfile\LayerInterface ...$layers)
15+
public function __construct(null|LayerInterface ...$layers)
1616
{
1717
$this->layers = $layers;
1818
}
1919

20-
public function push(Dockerfile\LayerInterface ...$layers): void
20+
public function push(LayerInterface ...$layers): void
2121
{
2222
array_push($this->layers, ...$layers);
2323
}

src/Dockerfile/Arg.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Dockerfile\Dockerfile;
6+
7+
final readonly class Arg implements LayerInterface, \Stringable
8+
{
9+
public function __construct(
10+
private string $name,
11+
private ?string $defaultValue = null,
12+
) {
13+
}
14+
15+
public function __toString(): string
16+
{
17+
if (null !== $this->defaultValue) {
18+
return sprintf('ARG %s=%s', $this->name, $this->defaultValue);
19+
}
20+
21+
return sprintf('ARG %s', $this->name);
22+
}
23+
}

src/EnvironmentVariable.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Dockerfile;
6+
7+
final readonly class EnvironmentVariable implements Variable
8+
{
9+
public function __construct(
10+
public string $name,
11+
) {
12+
}
13+
14+
public function __toString()
15+
{
16+
return "\${{$this->name}}";
17+
}
18+
}

src/PHP/ComposerGlobalConfig.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Dockerfile\PHP;
6+
7+
use Kiboko\Component\Dockerfile\Dockerfile;
8+
use Kiboko\Component\Dockerfile\Variable;
9+
10+
final readonly class ComposerGlobalConfig implements Dockerfile\LayerInterface, \Stringable
11+
{
12+
public function __construct(
13+
private string $key,
14+
private string|Variable $value,
15+
) {
16+
}
17+
18+
public function __toString(): string
19+
{
20+
return (string) new Dockerfile\Run(<<<"RUN"
21+
composer config --global {$this->key} {$this->value}
22+
RUN
23+
);
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Dockerfile\PHP;
6+
7+
use Kiboko\Component\Dockerfile\Dockerfile;
8+
use Kiboko\Component\Dockerfile\Variable;
9+
10+
final readonly class ComposerGlobalGithubAuthentication implements Dockerfile\LayerInterface, \Stringable
11+
{
12+
public function __construct(
13+
private Variable $tokenArgument,
14+
private string $host = 'github.com',
15+
) {
16+
}
17+
18+
public function __toString(): string
19+
{
20+
return (string) new Dockerfile\Run(<<<"RUN"
21+
composer config --global github-oauth.{$this->host} {$this->tokenArgument}
22+
RUN,
23+
);
24+
}
25+
}

src/Variable.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Dockerfile;
6+
7+
interface Variable extends \Stringable
8+
{
9+
}

0 commit comments

Comments
 (0)