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.
This commit is contained in:
parent
8451a9fbef
commit
1d008f76da
@ -31,6 +31,18 @@ class EnvConfigurator
|
|||||||
return '%env('.implode(':', $this->stack).')%';
|
return '%env('.implode(':', $this->stack).')%';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function __call(string $name, array $arguments): self
|
||||||
|
{
|
||||||
|
$processor = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1_\2', $name));
|
||||||
|
|
||||||
|
$this->custom($processor, ...$arguments);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
|
@ -31,5 +31,6 @@ final class EnvConfiguratorTest extends TestCase
|
|||||||
yield ['%env(string:FOO)%', (new EnvConfigurator('FOO'))->string()];
|
yield ['%env(string:FOO)%', (new EnvConfigurator('FOO'))->string()];
|
||||||
yield ['%env(key:path:url:FOO)%', (new EnvConfigurator('FOO'))->url()->key('path')];
|
yield ['%env(key:path:url:FOO)%', (new EnvConfigurator('FOO'))->url()->key('path')];
|
||||||
yield ['%env(default:fallback:bar:arg1:FOO)%', (new EnvConfigurator('FOO'))->custom('bar', 'arg1')->default('fallback')];
|
yield ['%env(default:fallback:bar:arg1:FOO)%', (new EnvConfigurator('FOO'))->custom('bar', 'arg1')->default('fallback')];
|
||||||
|
yield ['%env(my_processor:my_argument:FOO)%', (new EnvConfigurator('FOO'))->myProcessor('my_argument')];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user