Skip to content

Commit

Permalink
Merge pull request #1627 from theoboldalex/enable-event-file-for-bref…
Browse files Browse the repository at this point in the history
…-local

Enable file path to data on bref-local with CDK
  • Loading branch information
mnapoli authored Aug 31, 2023
2 parents a653ef1 + 9b7211c commit 6c9bbec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/function/local-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ Hello world
# With JSON event data
$ vendor/bin/bref-local my-function.php '{"name": "Jane"}'
Hello Jane
# With a path to a file containing a JSON event.
$ cat event.json
{
"name": "Alex"
}
$ vendor/bin/bref-local --path event.json my-function.php
Hello Alex
```
If you want to run your function in Docker:
Expand Down
10 changes: 10 additions & 0 deletions src/bref-local
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ if (file_exists(__DIR__ . '/../vendor/autoload.php')) {

$handler = $argv[1] ?? '';
$data = $argv[2] ?? null;
$opts = getopt('', ['path:']);

if (isset($opts['path'])) {
if (! file_exists($opts['path'])) {
throw new Exception('The file ' . $opts['path'] . ' could not be found.');
}

$handler = $argv[array_key_last($argv)];
$data = file_get_contents($opts['path']);
}

try {
$handler = Bref::getContainer()->get($handler);
Expand Down

0 comments on commit 6c9bbec

Please sign in to comment.