Skip to content

Commit a70b648

Browse files
committed
Allow calling custom processors directly on EnvConfigurator
Add magic __call method to EnvConfigurator to allow calling custom processors as methods instead of using the custom method.
1 parent 741e728 commit a70b648

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Loader/Configurator/EnvConfigurator.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ public function __toString()
3131
return '%env('.implode(':', $this->stack).')%';
3232
}
3333

34+
/**
35+
* @return $this
36+
*/
37+
public function __call(string $name, array $arguments): self
38+
{
39+
$processor = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1_\2', $name));
40+
41+
$this->custom($processor, ...$arguments);
42+
43+
return $this;
44+
}
45+
3446
/**
3547
* @return $this
3648
*/

Tests/Loader/Configurator/EnvConfiguratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ public function provide()
3131
yield ['%env(string:FOO)%', (new EnvConfigurator('FOO'))->string()];
3232
yield ['%env(key:path:url:FOO)%', (new EnvConfigurator('FOO'))->url()->key('path')];
3333
yield ['%env(default:fallback:bar:arg1:FOO)%', (new EnvConfigurator('FOO'))->custom('bar', 'arg1')->default('fallback')];
34+
yield ['%env(my_processor:my_argument:FOO)%', (new EnvConfigurator('FOO'))->myProcessor('my_argument')];
3435
}
3536
}

0 commit comments

Comments
 (0)