Skip to content

Commit 08c6fe3

Browse files
Merge pull request #35 from edalzell/feature/public-function-calls
Make `makeSimpleFunctionCall` public
2 parents 70192b4 + fbe6704 commit 08c6fe3

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ use Stillat\Proteus\Support\Facades\ConfigWriter;
162162
$document = ConfigWriter::edit('app')
163163
->set([
164164
'locale' => 'fr',
165-
'timezone' => 'Europe/Paris'
165+
'timezone' => 'Europe/Paris'
166166
])->preview();
167167
```
168168

@@ -176,7 +176,7 @@ use Stillat\Proteus\Support\Facades\ConfigWriter;
176176
ConfigWriter::edit('app')
177177
->set([
178178
'locale' => 'fr',
179-
'timezone' => 'Europe/Paris'
179+
'timezone' => 'Europe/Paris'
180180
])->save();
181181
```
182182

@@ -237,7 +237,7 @@ use Stillat\Proteus\Support\Facades\ConfigWriter;
237237
ConfigWriter::edit('app')
238238
->set([
239239
'locale' => 'fr',
240-
'timezone' => 'Europe/Paris'
240+
'timezone' => 'Europe/Paris'
241241
])->merge('providers', [
242242
SomeProvider::class,
243243
SomeOtherProvider::class
@@ -295,6 +295,19 @@ ConfigWriter::write('custom.path', ConfigWriter::f()->publicPath('relative'));
295295
ConfigWriter::write('custom.path', ConfigWriter::f()->resourcePath('relative'));
296296
```
297297

298+
You may also call other **globally registered** functions:
299+
300+
```php
301+
<?php
302+
use Stillat\Proteus\Support\Facades\ConfigWriter;
303+
304+
function my_custom_function($paramOne, $paramTwo) {
305+
...
306+
}
307+
308+
ConfigWriter::write('custom.path', ConfigWriter::f()->makeSimpleFunctionCall('my_custom_function', [$one, $two]));
309+
```
310+
298311
## Advanced Usage
299312

300313
Given the following input configuration file:
@@ -323,7 +336,7 @@ $updater->update([
323336
'hello',
324337
'world'
325338
]
326-
]
339+
]
327340
]
328341
]
329342
]);

src/Writers/FunctionWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class FunctionWriter
2828

2929
const FUNC_LARAVEL_ENV = 'env';
3030

31-
protected function makeSimpleFunctionCall(string $name, string|array $args): FuncCall
31+
public function makeSimpleFunctionCall(string $name, string|array $args): FuncCall
3232
{
3333
return new FuncCall(
3434
$this->convertToName($name),

tests/LaravelFunctionCallTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ public function testExistingEnvCallsCanBeReplaced()
4646
);
4747
}
4848

49+
public function testCustomCallsCanBeWritten()
50+
{
51+
$f = new FunctionWriter();
52+
53+
$this->assertChangeEquals(
54+
__DIR__.'/configs/empty.php',
55+
__DIR__.'/expected/newenv.php',
56+
[
57+
'thing' => $f->makeSimpleFunctionCall('env', ['APP_NAME', 'Laravel']),
58+
'thing2' => $f->makeSimpleFunctionCall('env', 'Something'),
59+
]
60+
);
61+
}
62+
63+
64+
4965
public function testWritingNewClosuresOrArrowFunctions()
5066
{
5167
$f = new FunctionWriter();

0 commit comments

Comments
 (0)