shahajahan/approval-flow

A dynamic, framework-agnostic approval access control system for any PHP framework (Laravel, CodeIgniter, CakePHP, Symfony, or plain PHP). Define and manage multi-level approval roles, with forward/backward flow and permission checks.

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/shahajahan/approval-flow

1.0.0 2025-10-13 08:15 UTC

This package is auto-updated.

Last update: 2025-12-13 12:06:06 UTC


README

Packagist Version License PHP Version Build Status

A dynamic approval access control system for any PHP framework (Laravel, CodeIgniter, CakePHP, Symfony, or plain PHP). Define and manage multi-level approval roles, with forward/backward flow and permission checks β€” all framework-agnostic.

πŸš€ Features

βœ… Framework-agnostic core βœ… Works with Laravel, CodeIgniter, Symfony, CakePHP, or raw PHP βœ… Dynamic approval hierarchy (forward/backward flow) βœ… Dynamic approval (forward/backward flow) with multiple approval flow on same project βœ… Simple adapter pattern for DB access (PDO, Query Builder, or ORM) βœ… PSR-4 and PSR-12 compliant βœ… Extensible and testable

🧩 Installation

Via Composer

composer require shahajahan/approval-flow

If you’re developing locally, clone the repo and link:

git clone https://github.com/shahajahancse/approval-flow.git
cd approval-flow
composer install

πŸ—ƒοΈ Database Schema

The recommended database schema is defined in database/schema.sql. You can use this file to set up your tables. A migration file for Laravel is also available at database/migrations/2025_10_13_000000_create_approval_tables.php.

βš™οΈ Usage Examples

πŸ”Ή Laravel

use ApprovalFlow\Services\ApprovalFlow;
use ApprovalFlow\Adapters\LaravelAdapter;

$flow = new ApprovalFlow(new LaravelAdapter());

$nextRole = $flow->nextRole(2);
$prevRole = $flow->previousRole(2);
$canApprove = $flow->canApprove(auth()->id(), $documentId);

πŸ”Ή CodeIgniter (v3 or v4)

$flow = new \ApprovalFlow\Services\ApprovalFlow(
    new \ApprovalFlow\Adapters\CodeIgniterAdapter($this)
);

$next = $flow->nextRole($currentRoleId);
$canApprove = $flow->canApprove($user_id, $doc_id);

πŸ”Ή Symfony

use ApprovalFlow\Services\ApprovalFlow;
use ApprovalFlow\Adapters\SymfonyAdapter;
use Doctrine\ORM\EntityManagerInterface;

// Assuming you have injected the EntityManager
$adapter = new SymfonyAdapter($entityManager);
$flow = new ApprovalFlow($adapter);

$nextRole = $flow->nextRole(1);

πŸ”Ή CakePHP

use ApprovalFlow\Services\ApprovalFlow;
use ApprovalFlow\Adapters\CakePHPAdapter;
use Cake\ORM\TableRegistry;

// Get the default ORM table
$usersTable = TableRegistry::getTableLocator()->get('Users');
$adapter = new CakePHPAdapter($usersTable);
$flow = new ApprovalFlow($adapter);

$nextRole = $flow->nextRole(1);

πŸ”Ή Plain PHP (PDO)

use ApprovalFlow\Services\ApprovalFlow;
use ApprovalFlow\Adapters\PdoAdapter;

$pdo = new PDO("mysql:host=localhost;dbname=test", "root", "");
$adapter = new PdoAdapter($pdo);
$flow = new ApprovalFlow($adapter);

if ($flow->canApprove(1, 100)) {
    echo "User can approve document!";
}

🧠 Architecture

  • Core Logic: ApprovalFlow (framework-independent)
  • Adapters:
    • LaravelAdapter β€” Uses Laravel’s Query Builder (DB Facade)
    • CodeIgniterAdapter β€” Uses CI’s $this->db query builder
    • PdoAdapter β€” Uses native PDO
  • Contract: ApproverInterface ensures consistency across adapters

🧰 Helper Functions

approval_log("Approval started...");
// Output: [ApprovalFlow] 2025-10-13 11:00:00 - Approval started...

πŸ§ͺ Running Tests

./vendor/bin/phpunit --bootstrap vendor/autoload.php tests

Sample test (tests/ApprovalFlowTest.php) is already included.

🧱 Folder Structure

approval-flow/
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Contracts/ApproverInterface.php
β”‚   β”œβ”€β”€ Services/ApprovalFlow.php
β”‚   β”œβ”€β”€ Adapters/
β”‚   β”‚   β”œβ”€β”€ LaravelAdapter.php
β”‚   β”‚   β”œβ”€β”€ CodeIgniterAdapter.php
β”‚   β”‚   └── PdoAdapter.php
β”‚   └── Helpers/helper.php
β”‚
β”œβ”€β”€ tests/
β”‚   └── ApprovalFlowTest.php
└── composer.json

πŸͺͺ License

This package is open-sourced software licensed under the MIT license.

πŸ‘¨β€πŸ’» Author

Md Shahajahan Ali πŸ“§ msacse1@gmail.com 🌐 GitHub: @shahajahan

🌟 Contributing

Pull requests are welcome! To contribute:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/your-feature)
  3. Commit changes and push
  4. Submit a Pull Request 🎯

πŸ’‘ Future Enhancements

  • Approval workflow templates (Leave, Expense, Purchase)
  • Event hooks (onApprove, onReject)
  • JSON-based flow configuration
  • Role-based escalation and notifications