blumilksoftware / blt

Behat+Laravel toolbox. Still in progress.
https://packagist.org/packages/blumilksoftware/blt
3 stars 0 forks source link

Make static helpers replaceable #66

Closed krzysztofrewak closed 17 hours ago

krzysztofrewak commented 1 week ago

I would like to provide a way to replace these static helpers that started to showing up in this package.

For example UserHelper:getBy("email", "example@example.com) is reaching to other class and doing some magic. What if someone would like to replace it with simple

    public static function getBy(string $field, string $value): ?object
    {
        return \MyApplication\Eloquent\User::query()->where($field, $value)->first();
    }

or maybe something more complex?

We could create a small service container for contexts and connect it to configuratinon file. So, for example, instead of using UserHelper:getBy("email", "example@example.com), we could use ContextHelper::get(UserHelper::class)->getBy("email", "example@example.com) or even ContextHelper::get("user")->getBy("email", "example@example.com)

And then, config file could have an array of options than could be changed by end user:

"helpers" => [
    "user" => \Blumilk\BLT\Helpers\UserHelper::class,
    // (...)
],

Service provider should be empty-config-proof.