From 9d22dbc673f10ad9a215d53e18aef111a23ec74e Mon Sep 17 00:00:00 2001 From: edalzell Date: Tue, 1 Apr 2025 17:42:36 -0700 Subject: [PATCH 1/2] make method public --- src/Writers/FunctionWriter.php | 2 +- tests/LaravelFunctionCallTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Writers/FunctionWriter.php b/src/Writers/FunctionWriter.php index 93f5a37..ee1e669 100644 --- a/src/Writers/FunctionWriter.php +++ b/src/Writers/FunctionWriter.php @@ -28,7 +28,7 @@ class FunctionWriter const FUNC_LARAVEL_ENV = 'env'; - protected function makeSimpleFunctionCall(string $name, string|array $args): FuncCall + public function makeSimpleFunctionCall(string $name, string|array $args): FuncCall { return new FuncCall( $this->convertToName($name), diff --git a/tests/LaravelFunctionCallTest.php b/tests/LaravelFunctionCallTest.php index ceccb60..ef78d26 100644 --- a/tests/LaravelFunctionCallTest.php +++ b/tests/LaravelFunctionCallTest.php @@ -46,6 +46,22 @@ public function testExistingEnvCallsCanBeReplaced() ); } + public function testCustomCallsCanBeWritten() + { + $f = new FunctionWriter(); + + $this->assertChangeEquals( + __DIR__.'/configs/empty.php', + __DIR__.'/expected/newenv.php', + [ + 'thing' => $f->makeSimpleFunctionCall('env', ['APP_NAME', 'Laravel']), + 'thing2' => $f->makeSimpleFunctionCall('env', 'Something'), + ] + ); + } + + + public function testWritingNewClosuresOrArrowFunctions() { $f = new FunctionWriter(); From fbe6704fdb12296eba0415c7a168a3159351bc83 Mon Sep 17 00:00:00 2001 From: edalzell Date: Tue, 1 Apr 2025 17:49:55 -0700 Subject: [PATCH 2/2] docs --- README.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f41dec0..3f5428c 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ use Stillat\Proteus\Support\Facades\ConfigWriter; $document = ConfigWriter::edit('app') ->set([ 'locale' => 'fr', - 'timezone' => 'Europe/Paris' + 'timezone' => 'Europe/Paris' ])->preview(); ``` @@ -176,7 +176,7 @@ use Stillat\Proteus\Support\Facades\ConfigWriter; ConfigWriter::edit('app') ->set([ 'locale' => 'fr', - 'timezone' => 'Europe/Paris' + 'timezone' => 'Europe/Paris' ])->save(); ``` @@ -237,7 +237,7 @@ use Stillat\Proteus\Support\Facades\ConfigWriter; ConfigWriter::edit('app') ->set([ 'locale' => 'fr', - 'timezone' => 'Europe/Paris' + 'timezone' => 'Europe/Paris' ])->merge('providers', [ SomeProvider::class, SomeOtherProvider::class @@ -295,6 +295,19 @@ ConfigWriter::write('custom.path', ConfigWriter::f()->publicPath('relative')); ConfigWriter::write('custom.path', ConfigWriter::f()->resourcePath('relative')); ``` +You may also call other **globally registered** functions: + +```php +makeSimpleFunctionCall('my_custom_function', [$one, $two])); +``` + ## Advanced Usage Given the following input configuration file: @@ -323,7 +336,7 @@ $updater->update([ 'hello', 'world' ] - ] + ] ] ] ]);