Skip to content

Commit

Permalink
Allow to set the context in the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Mar 3, 2025
1 parent a8ccd8b commit a6645f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,11 @@ When your cronjobs are defined, you can output the crontab file:
use Setono\CronBuilder\CronBuilder;
use Symfony\Component\Finder\Finder;

echo (new CronBuilder())
->addFiles(
(new Finder())
->files()
->in(__DIR__ . '/etc/cronjobs')
->name('*.php')
)
->addContext('release_path', '/home/johndoe/public_html')
->addContext('env', 'prod')
->addContext('args', ['--verbose'])
->build()
;
echo (new CronBuilder(__DIR__ . '/etc/cronjobs', [
'release_path' => '/home/johndoe/public_html',
'env' => 'prod',
'args' => ['--verbose'],
]))->build();
```

This will output the following:
Expand Down
6 changes: 4 additions & 2 deletions src/CronBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ final class CronBuilder

/**
* @param string|list<string> $directories
* @param array<string, mixed> $context
*/
public function __construct(string|array $directories = [])
public function __construct(string|array $directories = [], array $context = [])
{
$this->twig = new Environment(new ArrayLoader());
$this->context = new Context();

if (is_string($directories)) {
$directories = [$directories];
Expand All @@ -43,6 +43,8 @@ public function __construct(string|array $directories = [])
->name('*.php'),
);
}

$this->context = new Context($context);
}

public function addFile(string|\SplFileInfo $file): self
Expand Down

0 comments on commit a6645f3

Please sign in to comment.