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

added functionality for callbacks before/after create/delete #80

Closed
wants to merge 4 commits into from
Closed

added functionality for callbacks before/after create/delete #80

wants to merge 4 commits into from

Conversation

silentpatrik
Copy link

@silentpatrik silentpatrik commented Dec 20, 2023

This makes some things when for example setting up new projects or doing heavy backend processing like setting up or compiling or anything not supposed to last after their execution,

Not the best example, but to illiustrate usage:
App/Console/Commands/InstallCommand.php

// file: App/Console/InstallCommand.php

private $commands=[
    'git clone xxx ',
    'wget somebigfile',
    'echo "installing stuff and unpacking somebigfile"'
];
function install()
{
    $temporaryDirectory = (new TemporaryDirectory())
        ->useLifecycleEvents()
        ->afterCreate(function($temporaryDirectory) {
            foreach($this->commands as $cmd) {
            Process::path($temporaryDirectory()->path())->run($cmd);
            }
    })->create();
}

Usage :

   $temporaryDirectory = (new TemporaryDirectory())->useLifecycleEvents()
        ->beforeCreate(function() { /*code to be executed*/ })
        ->afterCreate(function() { /*code to be executed*/ }
        ->beforeDelete(function() { /*code to be executed*/ })
        ->afterDelete(function() { /*code to be executed*/ })

Multiple functions can be chained:

   $temporaryDirectory = (new TemporaryDirectory())->useLifecycleEvents()
        ->beforeCreate(function() { /*code to be executed*/ })
        ->beforeCreate(function() { /*code to be executed*/ })
        ->beforeCreate(function() { /*code to be executed*/ })

or as an array of closures:

   $temporaryDirectory = (new TemporaryDirectory())->useLifecycleEvents()
        ->beforeCreate([
            function() { /*code to be executed*/ },
            function() { /*code to be executed*/ },
            function() { /*code to be executed*/ }
        ])->create();

silentpatrik and others added 4 commits December 20, 2023 17:04
…elete. This makes some things when for example setting up new projects or cloning git repos for install scripts etc. a bit smoother
@silentpatrik silentpatrik marked this pull request as ready for review December 20, 2023 21:04
@freekmurze
Copy link
Member

I'm going to hold off on this to keep the package simple. Feel free to create a fork and apply your changes there.

@freekmurze freekmurze closed this Dec 21, 2023
@silentpatrik silentpatrik deleted the feature/lifecycle-events branch December 21, 2023 10:29
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.

2 participants