Skip to content

Commit 1b6c8ff

Browse files
committed
Added classes to manage the options used in the composer config command
1 parent 312d50e commit 1b6c8ff

File tree

6 files changed

+78
-6
lines changed

6 files changed

+78
-6
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/Arg.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ public function __construct(
1414

1515
public function __toString(): string
1616
{
17-
if ($this->defaultValue !== null) {
17+
if (null !== $this->defaultValue) {
1818
return sprintf('ARG %s=%s', $this->name, $this->defaultValue);
1919
}
20+
2021
return sprintf('ARG %s', $this->name);
2122
}
2223
}

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/ComposerConfigGlobal.php renamed to src/PHP/ComposerGlobalConfig.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55
namespace Kiboko\Component\Dockerfile\PHP;
66

77
use Kiboko\Component\Dockerfile\Dockerfile;
8+
use Kiboko\Component\Dockerfile\Variable;
89

9-
final readonly class ComposerConfigGlobal implements Dockerfile\LayerInterface, \Stringable
10+
final readonly class ComposerGlobalConfig implements Dockerfile\LayerInterface, \Stringable
1011
{
1112
public function __construct(
12-
private string $host,
13-
private string $tokenArgument,
13+
private string $key,
14+
private string|Variable $value,
1415
) {
1516
}
1617

1718
public function __toString(): string
1819
{
1920
return (string) new Dockerfile\Run(<<<"RUN"
20-
composer config --global {$this->host} \${{$this->tokenArgument}}
21-
RUN,
21+
composer config --global {$this->key} {$this->value}
22+
RUN
2223
);
2324
}
2425
}
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)