Skip to content
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

Enable file path to data on bref-local with CDK #1627

Merged
merged 6 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'])) {
theoboldalex marked this conversation as resolved.
Show resolved Hide resolved
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
Loading