Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Add Macroable trait to Sleep class #47099

Merged
merged 4 commits into from
May 16, 2023
Merged

[10.x] Add Macroable trait to Sleep class #47099

merged 4 commits into from
May 16, 2023

Conversation

bradietilley
Copy link
Contributor

From #47092

This PR adds the Macroable trait to the Sleep class. Example:

// AppServiceProvider
Sleep::macro('forConfiguredTime', static function () {
    $milliseconds = DB::table('settings')->where('key', 'sleep_after_action')->first()->value ?? 1000; // let's say 3500 ms

    return Sleep::for($milliseconds)->milliseconds();
} );

// Throughout your application:
Sleep::forConfiguredTime(); // e.g. 3500ms

// Or
Sleep::for(1)->second()->orMyCustomMacroAmountOfTime();

A helpful subfeature for this facility would be the ability to define a replacement duration. Example:

$sleep = Sleep::for(1)->second();

// Replace the duration
$sleep->duration(800)->milliseconds();

// $sleep = 800ms not 1s

@nunomaduro nunomaduro changed the title Add Macroable trait to Sleep class [10.x] Add Macroable trait to Sleep class May 15, 2023
src/Illuminate/Support/Sleep.php Outdated Show resolved Hide resolved
@nunomaduro
Copy link
Member

Ups! You will need to adjust your testItCanReplacePreviouslyDefinedDurations test - one idea is create a macro to override the duration

@nunomaduro nunomaduro marked this pull request as draft May 15, 2023 22:38
@nunomaduro nunomaduro self-assigned this May 15, 2023
Copy link
Member

@nunomaduro nunomaduro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the test suite.

@nunomaduro nunomaduro marked this pull request as ready for review May 15, 2023 23:06
@taylorotwell taylorotwell merged commit f11b39c into laravel:10.x May 16, 2023
@bradietilley bradietilley deleted the sleep-macroable branch May 16, 2023 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants