Skip to content

Added commands for docker and composer #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 15, 2024
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}}";
}
}
4 changes: 2 additions & 2 deletions src/Dockerfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ final class Dockerfile implements \IteratorAggregate, \Countable, FileInterface,
/** @var iterable|Dockerfile\LayerInterface[] */
private iterable $layers;

public function __construct(null|Dockerfile\LayerInterface ...$layers)
public function __construct(null|LayerInterface ...$layers)
{
$this->layers = $layers;
}

public function push(Dockerfile\LayerInterface ...$layers): void
public function push(LayerInterface ...$layers): void
{
array_push($this->layers, ...$layers);
}
Expand Down
23 changes: 23 additions & 0 deletions src/Dockerfile/Arg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Dockerfile\Dockerfile;

final readonly class Arg implements LayerInterface, \Stringable
{
public function __construct(
private string $name,
private ?string $defaultValue = null,
) {
}

public function __toString(): string
{
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}}";
}
}
25 changes: 25 additions & 0 deletions src/PHP/ComposerGlobalConfig.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 ComposerGlobalConfig implements Dockerfile\LayerInterface, \Stringable
{
public function __construct(
private string $key,
private string|Variable $value,
) {
}

public function __toString(): string
{
return (string) new Dockerfile\Run(<<<"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
{
}