PHPackages                             kwidoo/lifecycle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kwidoo/lifecycle

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kwidoo/lifecycle
================

Lifecycle for my Laravel apps

1.1.0(1y ago)01MITPHPPHP ^8.2CI failing

Since Apr 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/kwidoo/lifecycle)[ Packagist](https://packagist.org/packages/kwidoo/lifecycle)[ Docs](https://github.com/kwidoo/lifecycle)[ RSS](/packages/kwidoo-lifecycle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (9)Versions (4)Used By (0)

Lifecycle
=========

[](#lifecycle)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cdc60adf6848370277ec8373b5a048883bcd006f8ca2f405cd110f807fb2c990/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b7769646f6f2f6c6966656379636c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kwidoo/lifecycle)[![Tests](https://github.com/kwidoo/lifecycle/actions/workflows/tests.yml/badge.svg)](https://github.com/kwidoo/lifecycle/actions/workflows/tests.yml)[![Code Style](https://github.com/kwidoo/lifecycle/actions/workflows/code-style.yml/badge.svg)](https://github.com/kwidoo/lifecycle/actions/workflows/code-style.yml)[![Total Downloads](https://camo.githubusercontent.com/2274b4822fbc321d6d65641b47bdd0375138eeed3fdafd112a5d97445f347162/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b7769646f6f2f6c6966656379636c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kwidoo/lifecycle)

A Laravel package that provides a flexible lifecycle management system for your application operations. This package helps you implement consistent patterns for handling events, transactions, logging, authorization, caching, and rate limiting across your Laravel application.

Features
--------

[](#features)

- 🛡️ **Authorization Management**: Control access with configurable authorization strategies
- 🔄 **Transaction Management**: Wrap operations in database transactions
- 📊 **Logging**: Automatically log actions, results, and errors
- 📡 **Event Dispatching**: Dispatch events before and after operations
- 💾 **Caching**: Cache operation results for improved performance
- 🚦 **Rate Limiting**: Protect against abuse with configurable rate limiting
- 🔁 **Retry Handling**: Automatically retry failed operations with backoff
- 🧩 **Strategy Pattern**: Choose which features to enable for each operation
- 🔌 **Extensible**: Create custom strategies for your specific requirements

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require kwidoo/lifecycle
```

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="Kwidoo\\Lifecycle\\LifecycleServiceProvider"
```

This will create a `config/lifecycle.php` file where you can configure default behaviors.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Kwidoo\Lifecycle\Data\LifecycleContextData;
use Kwidoo\Lifecycle\Data\LifecycleOptionsData;
use Kwidoo\Lifecycle\Contracts\Lifecycle;

class YourService
{
    public function __construct(protected Lifecycle $lifecycle) {}

    public function performAction($context)
    {
        $contextData = new LifecycleContextData(
            action: 'create',
            resource: 'users',
            context: $context
        );

        return $this->lifecycle->run($contextData, function ($contextData) {
            // Your business logic here
            $result = $this->createUser($contextData->context);

            return $result;
        }, new LifecycleOptionsData());
    }
}
```

### Customizing Strategy Options

[](#customizing-strategy-options)

You can use the fluent interface to customize which strategies are enabled:

```
// Configure strategies with fluent interface
$result = $this->lifecycle->run(
    $contextData,
    function ($contextData) {
        // Business logic
        return $result;
    },
    (new LifecycleOptionsData())
        ->withoutTrx()       // Disable transactions
        ->withEvents()       // Enable events
        ->withoutLogging()   // Disable logging
        ->withCache()        // Enable caching
        ->withRetry()        // Enable retry on failure
);
```

### Lifecycle Data

[](#lifecycle-data)

The package now uses separate data objects for input and output:

```
// Input context data - immutable
$contextData = new LifecycleContextData(
    action: 'update',      // The action being performed (create, update, delete, etc.)
    resource: 'products',  // The resource being operated on
    context: $product,     // The contextual data for the operation
);

// Execute with lifecycle
$resultData = $this->lifecycle->run($contextData, function($contextData) {
    // Business logic - process the context
    $result = processData($contextData->context);

    // Return the result
    return $result;
});
```

### Events

[](#events)

Events are dispatched with the following naming pattern:

- Before operation: `before.{resource}.{action}`
- After operation: `after.{resource}.{action}`
- On error: `error.{resource}.{action}`

Advanced Usage
--------------

[](#advanced-usage)

### Custom Authorizers

[](#custom-authorizers)

You can create custom authorizers for specific resources:

```
namespace App\Authorizers;

use Kwidoo\Lifecycle\Authorizers\DefaultAuthorizer;

class ProductAuthorizer extends DefaultAuthorizer
{
    public function authorize(string $action, $context): bool
    {
        // Custom authorization logic for products
        if ($action === 'delete' && !$this->userCanDeleteProduct($context)) {
            return false;
        }

        return true;
    }

    protected function userCanDeleteProduct($product): bool
    {
        return auth()->user()->hasPermission('delete-products');
    }
}
```

### Custom Strategy Implementations

[](#custom-strategy-implementations)

You can create custom strategies by implementing the respective interfaces:

```
namespace App\Strategies\Logging;

use Kwidoo\Lifecycle\Contracts\Strategies\LogStrategy;
use Kwidoo\Lifecycle\Data\LifecycleContextData;

class EnhancedLogStrategy implements LogStrategy
{
    public function execute(LifecycleContextData $data, callable $callback): mixed
    {
        // Custom pre-execution logging
        $this->logWithMetadata($data, 'before');

        // Execute the callback
        $result = $callback();

        // Custom post-execution logging
        $this->logWithMetadata($data, 'after', $result);

        return $result;
    }

    public function logPhase(LifecycleContextData $data, string $phase, string $level = 'info'): void
    {
        // Your custom logging implementation
    }

    protected function logWithMetadata(LifecycleContextData $data, string $phase, $result = null): void
    {
        // Enhanced logging with additional metadata
    }
}
```

### Using Caching

[](#using-caching)

Enable caching for frequently-used operations:

```
$result = $this->lifecycle->run(
    $contextData,
    function ($contextData) {
        // Expensive operation that will be cached
        return $this->repository->fetchExpensiveData($contextData->context);
    },
    (new LifecycleOptionsData())
        ->withCache()  // Results will be cached
);
```

### Rate Limiting

[](#rate-limiting)

Protect your application from abuse:

```
$result = $this->lifecycle->run(
    $contextData,
    function ($contextData) {
        // Operation that needs rate limiting
        return $this->processSensitiveOperation($contextData->context);
    },
    (new LifecycleOptionsData())
        ->withRateLimit()  // Apply rate limiting
);
```

Testing
-------

[](#testing)

```
composer test
```

The package includes comprehensive test coverage for all components including:

- Unit tests for all service components
- Strategy implementation tests
- Feature/integration tests demonstrating real-world use cases

Tests are automatically run via GitHub Actions when code is pushed to the repository.

Upgrading
---------

[](#upgrading)

If you're upgrading from a previous version, please see the [Upgrade Guide](docs/upgrade-guide.md) for detailed instructions.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Oleg Pashkovsky](https://github.com/kwidoo)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance48

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

3

Last Release

383d ago

Major Versions

0.9.0 → 1.0.02025-04-24

PHP version history (2 changes)0.9.0PHP ^8.0

1.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/40e08f40bb6cff697b1703ccab1a57f3bd327faedf429df8e588d325a76de9f8?d=identicon)[samsite](/maintainers/samsite)

---

Top Contributors

[![kwidoo](https://avatars.githubusercontent.com/u/14920653?v=4)](https://github.com/kwidoo "kwidoo (26 commits)")

---

Tags

lifecyclekwidoo

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/kwidoo-lifecycle/health.svg)

```
[![Health](https://phpackages.com/badges/kwidoo-lifecycle/health.svg)](https://phpackages.com/packages/kwidoo-lifecycle)
```

###  Alternatives

[illuminate/pipeline

The Illuminate Pipeline package.

9346.6M213](/packages/illuminate-pipeline)[mrmarchone/laravel-auto-crud

Laravel Auto CRUD helps you streamline development and save time.

28711.8k2](/packages/mrmarchone-laravel-auto-crud)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
