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
Requires
- php: >=5.6
Requires (Dev)
- phpunit/phpunit: ^9.6
README
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->dbquery builderPdoAdapterβ Uses native PDO
- Contract:
ApproverInterfaceensures 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:
- Fork the repository
- Create your feature branch (
git checkout -b feature/your-feature) - Commit changes and push
- 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