Skip to content

Commit

Permalink
Merge pull request #9 from php-etl/feature/new-commands
Browse files Browse the repository at this point in the history
Added commands for docker and composer
  • Loading branch information
gplanchat authored Feb 15, 2024
2 parents 703bb1d + 47e3ddf commit 4521fa0
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 2 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}}";
}
}
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;

Check failure on line 17 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Kiboko\Component\Dockerfile\Dockerfile::$layers (iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface>) does not accept array<int|string, Kiboko\Component\Dockerfile\Dockerfile\LayerInterface|null>.

Check failure on line 17 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Kiboko\Component\Dockerfile\Dockerfile::$layers (iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface>) does not accept array<int|string, Kiboko\Component\Dockerfile\Dockerfile\LayerInterface|null>.

Check failure on line 17 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Kiboko\Component\Dockerfile\Dockerfile::$layers (iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface>) does not accept array<int|string, Kiboko\Component\Dockerfile\Dockerfile\LayerInterface|null>.

Check failure on line 17 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Kiboko\Component\Dockerfile\Dockerfile::$layers (iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface>) does not accept array<int|string, Kiboko\Component\Dockerfile\Dockerfile\LayerInterface|null>.
}

public function push(Dockerfile\LayerInterface ...$layers): void
public function push(LayerInterface ...$layers): void
{
array_push($this->layers, ...$layers);

Check failure on line 22 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $array of function array_push expects array, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.

Check failure on line 22 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $array of function array_push expects array, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.

Check failure on line 22 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $array of function array_push expects array, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.

Check failure on line 22 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $array of function array_push expects array, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.
}
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
{
}

0 comments on commit 4521fa0

Please sign in to comment.