mardi 26 novembre 2019

PHP/Laravel Check a condition in a function only once

I have written a custom translation function for Laravel, which first checks a configuration variable to see whether to use Laravel's default __() function or my custom trans() function.

Here's my function:

function t($key, $replace = [], $locale = null)
{
    $source = Config::get('translate.source');
    if ($source == 'database') {
        return trans($key, $replace, $locale);
    } else {
        return __($key, $replace, $locale);
    }
}

However, for speed purposes, I don't want the if condition to run reach time I call the t() function, but only on the first call.

Any ideas?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OPVJ1u
via IFTTT

Aucun commentaire:

Enregistrer un commentaire