Skip to content

Commit

Permalink
Added classes to manage the options used in the composer config command
Browse files Browse the repository at this point in the history
  • Loading branch information
sebprt committed Feb 1, 2024
1 parent 312d50e commit 1b6c8ff
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 6 deletions.
18 changes: 18 additions & 0 deletions src/Argument.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Dockerfile;

final readonly class Argument implements Variable
{
public function __construct(
public string $name,
) {
}

public function __toString()
{
return "\${{$this->name}}";
}
}
3 changes: 2 additions & 1 deletion src/Dockerfile/Arg.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public function __construct(

public function __toString(): string
{
if ($this->defaultValue !== null) {
if (null !== $this->defaultValue) {
return sprintf('ARG %s=%s', $this->name, $this->defaultValue);
}

return sprintf('ARG %s', $this->name);
}
}
18 changes: 18 additions & 0 deletions src/EnvironmentVariable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Dockerfile;

final readonly class EnvironmentVariable implements Variable
{
public function __construct(
public string $name,
) {
}

public function __toString()
{
return "\${{$this->name}}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
namespace Kiboko\Component\Dockerfile\PHP;

use Kiboko\Component\Dockerfile\Dockerfile;
use Kiboko\Component\Dockerfile\Variable;

final readonly class ComposerConfigGlobal implements Dockerfile\LayerInterface, \Stringable
final readonly class ComposerGlobalConfig implements Dockerfile\LayerInterface, \Stringable
{
public function __construct(
private string $host,
private string $tokenArgument,
private string $key,
private string|Variable $value,
) {
}

public function __toString(): string
{
return (string) new Dockerfile\Run(<<<"RUN"
composer config --global {$this->host} \${{$this->tokenArgument}}
RUN,
composer config --global {$this->key} {$this->value}
RUN
);
}
}
25 changes: 25 additions & 0 deletions src/PHP/ComposerGlobalGithubAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Dockerfile\PHP;

use Kiboko\Component\Dockerfile\Dockerfile;
use Kiboko\Component\Dockerfile\Variable;

final readonly class ComposerGlobalGithubAuthentication implements Dockerfile\LayerInterface, \Stringable
{
public function __construct(
private Variable $tokenArgument,
private string $host = 'github.com',
) {
}

public function __toString(): string
{
return (string) new Dockerfile\Run(<<<"RUN"
composer config --global github-oauth.{$this->host} {$this->tokenArgument}
RUN,
);
}
}
9 changes: 9 additions & 0 deletions src/Variable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Dockerfile;

interface Variable extends \Stringable
{
}

0 comments on commit 1b6c8ff

Please sign in to comment.