Download the PHP package codesignificant/api-pro without Composer
On this page you can find all versions of the php package codesignificant/api-pro. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codesignificant/api-pro
More information about codesignificant/api-pro
Files in codesignificant/api-pro
Package api-pro
Short Description API PRO – Lightweight PHP REST API framework
License MIT
Informations about the package api-pro
ApiPro — Lightweight PHP REST API Framework
ApiPro is a high-performance, lightweight, production-ready PHP REST framework built on a secure, service-oriented paradigm. It is engineered with a strict Separation of Concerns architecture, native multi-device stateful sessions via Redis, deterministic page builders, and distributed high-concurrency protection tools.
Key Features
- Clean Layered Architecture: Strictly isolates HTTP parsing and routing gateways (Controllers) from pure, state-free business logic (Services).
- Attribute-Based Declarative Routing: Map endpoints using clean PHP attributes:
#[Controller],#[Get],#[Post]. - Unified JSON Response Envelopes: Consistent API contracts structured cleanly under
'success','message', and'data'keys without top-level property pollution. - Robust Stateful Session Security: Crypto-secure Encrypt-then-MAC tokens with Redis-backed multi-device limiters, automatic hijacking protection, and developer-friendly
curlcompatibility. - Distributed Concurrency Mutex: Native Redis-backed distributed locks to prevent race conditions during write/read operations.
- Deterministic Pagination: Group-safe, JOIN-safe paginator that structures queries with absolute mathematical precision.
Directory Layout
1. Clean Separation of Concerns
To maximize testability and keep code state-free, ApiPro strictly separates request boundaries:
- The Controller parses inputs, manages HTTP headers, verifies permissions using the secure
Session::Get()module, and converts web state into primitives (such as$userId). - The Service acts as a pure machine. It has zero knowledge of HTTP headers, cookies, or the global web environment. It operates purely on arguments passed down by the Controller and returns a standardized
DataResponse.
Implementation Example
Controller Layer (lib/controller/ProductController.php):
Service Layer (lib/service/ProductService.php):
2. Request Handling & Parameter Validation (Deprecated: Node)
ApiPro introduces the object-oriented Request class for extracting and validating input parameters.
Request Injection
Controller methods access the current HTTP request by accepting a $request parameter (which is injected automatically by the router):
Type-Safe Retrieval & Validation Rules
The $request->body, $request->params, and $request->multipart sub-properties (instances of RequestData) provide type-specific methods that cast values and handle validation:
getString(string $key, $default = null): stringgetInt(string $key, $default = null): intgetFloat(string $key, $default = null): floatgetBool(string $key, $default = null): boolgetArray(string $key, $default = null): arraygetObject(string $key, $default = null)getFile(string $key, bool $mandatory = true, array $allowedFormats = [])getFiles(string $key = null, bool $mandatory = true, array $allowedFormats = [])
Mandatory vs Optional Parameters:
- Mandatory: If the second argument (
$default) is omitted (checked via argument count), the parameter is treated as required. If it is missing or fails the type validation, the request automatically halts and returns a standard400 Bad Requestvalidation response (DataFailed) detailing the missing key. - Optional: If a default value is provided, the key is treated as optional, and the default value is returned if the parameter is missing or invalid.
Endpoint Documentation (addComment)
You can document an endpoint inside its controller method using $request->addComment("Read me description"). The static router analysis parses these comments and displays them in the interactive tester UI:
Legacy Node Class (Deprecated)
The static Node class (Node::body(), Node::params(), Node::files()) is deprecated. Existing usages are fully backward compatible but will log and trigger deprecation headers:
3. Standardized JSON Envelope Contract
All success responses returned by the framework are automatically formatted using a unified, clean three-key envelope:
If a request fails, a clean error structure is returned:
4. High-Concurrency Distributed Locks (ProLock)
Protect critical pathways (deducting balances, booking hotel rooms, checking out shopping carts) from double-spend and race conditions with native Redis-backed mutexes:
5. Multi-Device Stateful Session Security
ApiPro provides full session control with customizable maximum device limits:
- Stateful Driver Support: Easily switch session management to Redis by setting
TOKEN_DRIVERto'redis'inconfig.php. - Multi-Device Concurrency Control: Define
TOKEN_MAX_DEVICES(default5) to limit concurrent sessions. - Developer-Friendly API Testing: Dynamic validation allows stateful tokens to be tested seamlessly on
curlor Postman without getting blocked by user-agent fingerprint mismatches when custom device tracking headers are omitted.
6. Config-Driven Automatic Schema Sync & 3-Tier Locks
ApiPro introduces a base Repository (backed by ProRepository) class that automatically synchronizes database table schemas declared inside child constructors, managed globally or protected by a robust 3-tier lock system.
Queue-Based Schema Creation & Dependency Resolution
All table creation and alter/update tasks are collected into a schema creation queue and processed iteratively over up to 3 passes. If a table schema requires another table schema (e.g., foreign key references or dependent table structures), the queue re-attempts execution in subsequent passes. If any schema operation continues to fail after 3 attempts, the framework immediately halts and responds with an HTTP 500 DataFailed response detailing the migration error.
Key Operational Sync Modes (config.php):
define('DB_WRITE', 'update');(Default / Development): Automatically creates missing tables and runs incremental structure alterations on existing tables.define('DB_WRITE', 'create');: Creates tables only if they are missing.define('DB_WRITE', 'force');(or'recreate'): Automatically drops existing tables and recreates them fresh.define('DB_WRITE', false);: Completely suspends all constructor checks and database sync activity (highly recommended for production performance).
Database Query Error Handling (ProSql)
Database connection failures and query execution errors in ProSql return a DataFailed response envelope with an explicit HTTP 500 status code (e.g. new DataFailed("Query failed: ...", 500)).
The 3-Tier Lock Hierarchy:
- Global Lock (Project Scope): Set
define('DB_WRITE', 'lock');inconfig.phpto prevent drops or alterations on any table in the entire codebase. - Repository Lock (Class Scope): Pass
trueor['lock' => true]as the second argument toparent::__construct($tables, true)to lock all tables declared inside that repository class. - Table Lock (Table Scope): Define
'lock' => trueon an individual table configuration array to protect only that table.
If locked at any level, the engine will still auto-create the table if it's missing (to prevent app crashes), but will completely bypass any drops, recreations, or alters if the table already exists.
7. Symmetric Data Encryption Layer
ApiPro features a dedicated symmetric data encryption layer for response payloads. This encrypts the value of the "data" key in all success and failure response envelopes.
- Global Configuration: Set
define("DATA_ENC", "your_secret_key");inconfig.php. IfDATA_ENCis empty or undefined, data encryption is disabled globally. - Custom Key / Bypass Overrides: Both
DataSuccessandDataFailedconstructors accept a fourth optional parameter$encryptionKey(?string $encryptionKey = null):- Null (Default): Uses the global
DATA_ENCkey. If configured, encrypts the data; otherwise, returns data as-is. - Empty String
"": Explicitly disables encryption for this response (even ifDATA_ENCis configured globally). - Non-Empty String: Encrypts the response data using this custom key.
- Null (Default): Uses the global
Code Examples:
8. Running and Setting Up the Project
Local Development Server
To start the built-in PHP development server, run from the project root:
Or you can use the composer script:
The server will be running on http://127.0.0.1:8000.
Setup Checklist
- Initialize Workspace: Run
composer installto download dependencies and trigger post-install mappings. - Environment Configuration: Set credentials and encryption constants in
config.php:SERVER_ENC(Tokens and session keys)DATA_ENC(Symmetric response data keys)- Redis host and port config (
TOKEN_DRIVER => 'redis') - Database sync modes (
DB_WRITE => 'update'for dev,DB_WRITE => falsefor database-less or production mode)
9. ApiPro CLI Tool
The framework includes a CLI companion tool in the project root: api-pro.
Commands
-
Check version:
-
Update Framework: Downloads the latest release ZIP package from the official repository and securely updates the
Core/framework directory, entry points (index.php,.htaccess), and dependencies while completely preserving your custom application code (lib/), configurations (config.php), and non-project folders:(Example:
php api-pro update 2.1.0or simplyphp api-pro updateto fetch the latest release).
Installation Guide
Prerequisites
Make sure your development server meets the following requirements:
- PHP: Version 8.0 or higher.
- Extensions:
pdo_mysql,openssl,redis(or a compatible Redis library), and optionallyzip(for framework updates). - Composer: PHP dependency manager.
- Services: MySQL/MariaDB and Redis.
Option 1: Via Composer (Recommended)
Create a brand new ApiPro project from the official skeleton:
This command downloads the framework skeleton, initializes the correct configurations, performs post-install mappings, and cleans up temporary setup documentation for a production-ready folder structure.
Option 2: Direct Git Clone
Clone the repository manually:
Post-Installation Setup
- Configure Environment: Update
config.phpin the root directory with your MySQL DB, Redis, and MAILER settings. - Set up Web Server routing:
- Apache: The preconfigured
.htaccessfile handles URL rewriting and routes requests toindex.phpout of the box. Ensuremod_rewriteis enabled. - Nginx: Set your server block configuration to rewrite unmatched requests:
- Apache: The preconfigured
Release Notes & Updates
Version 2.4.2 Release Notes
ApiPro v2.4.2 introduces strict typing for multiple and single file uploads, along with inline format validation.
- Strict Multipart Array Typing & Format Validation:
getFile(string $key, bool $mandatory = true, array $allowedFormats = [])now strictly enforces a single file upload, rejecting array uploads.getFiles(string $key = null, bool $mandatory = true, array $allowedFormats = [])strictly enforces multiple files (arrays), and the API Tester UI automatically configures the HTML input to supportmultipleand formats the form data accurately with[]brackets.- Passing an array of extensions to
$allowedFormats(e.g.['jpg', 'png']) will automatically reject any uploads that don't match those extensions with a 400 Bad Request error.
Version 2.4.1 Release Notes
ApiPro v2.4.1 enforces explicit source targeting on all request getters and introduces the query property alias.
- Enforced Explicit Source Targeting:
- Direct getter calls on the
Requestobject (e.g.$request->getString()) now throw anExceptionat runtime with a clear developer message. - All getters must now be called on a specific source:
$request->body->getString(),$request->query->getString(), or$request->multipart->getFile(). - This prevents ambiguity about where a value is sourced and makes controller intent immediately clear.
- Direct getter calls on the
- New
queryProperty Alias:- Added
$request->queryas a semantic alias for$request->params, allowing more expressive and idiomatic code (e.g.$request->query->getInt('page', 1)). - Both
paramsandqueryare fully supported and interchangeable.
- Added
- API Tester UI — Source Badges:
- The interactive tester now renders colored source tags alongside each parameter field.
- 🟡
body— amber badge for body-sourced parameters ($request->body->...) - 🟢
query— green badge for query-string parameters ($request->query->...or$request->params->...) - 🟣
multipart— purple badge for single file upload fields ($request->multipart->getFile()) - 🟣
multipart (array)— purple badge for multiple file upload fields ($request->multipart->getFiles()) - Source badges are derived from static analysis of controller code in
ProTestService.php.
- CLI:
start/serveCommand:- Added
php api-pro startto launch the built-in PHP development server. - Supports
--port=7070,--port 7070,-p 7070, and--host=0.0.0.0options. Defaults to127.0.0.1:7070.
- Added
- CLI:
latestCommand:- Added
php api-pro latest(aliases:--latest,-l) to check the latest available release on GitHub. - Compares it to the locally installed version and prompts for update if a newer version exists.
- Added
- CLI:
changelogCommand:- Added
php api-pro changelog [version](aliases:--changelog,-c) to display release notes in the terminal. - Defaults to the currently installed version if no version argument is given.
- Added
- CLI:
updateEnhancements:php api-pro updatenow also overwritesREADME.mdandAI_INSTRUCTIONS.mdto keep documentation current.- After a successful update, the release notes for the newly installed version are printed automatically.
Version 2.4.0 Release Notes
ApiPro v2.4.0 focuses on improving request input validation, parameter type safety, and inline endpoint documentation.
- Object-Oriented Request & RequestData Classes:
- Replaced the deprecated static
Nodeutility class with a dynamically injectedRequestinstance. - Implemented type-safe helper getters:
getString,getInt,getFloat,getBool,getArray,getObject,getFile, andgetFiles. - Checking for argument count automatically enforces mandatory/optional parameters. Omitting the default value validates input presence and returns a
400 Bad Requeston failure, while including a default value makes it optional.
- Replaced the deprecated static
- Backward Compatibility & Warning Headers:
- Full backward compatibility for controllers using
Node::body(),Node::params(), orNode::files(). - Generates an
X-ApiPro-Warningheader and flags routes in the debugger console if they continue to use the legacyNodeclass.
- Full backward compatibility for controllers using
- Dynamic Endpoint Documentation (
addComment):- Supported adding README documentation to route methods using
$request->addComment("..."). - Statically extracts comments and renders them within a dedicated read-me section in the API Tester UI.
- Supported adding README documentation to route methods using
Version 2.3.0 Release Notes
ApiPro v2.3.0 focuses on modularizing the debugger tools, introducing global utility logging, and stabilizing the CLI update engine.
- Modular Developer Console:
- Relocated the monolithic
logs.htmlandtest.htmlassets into organized subfolders (Core/logs/andCore/tester/) to maintain a clean workspace. - Added an in-place highlight and find navigation system (browser-like
Ctrl+Flayout) with arrow cycle buttons and Enter/Shift+Enter keystroke navigation in the Logger console. - Shortened and styled the timestamp toggle into a compact, space-saving clock icon toggle button.
- Automatically filters long absolute file directories and line number strings from PHP error logs to keep message outputs clean.
- Relocated the monolithic
- Global Helper Logging:
- Introduced the static helper class
Log(e.g.Log::info(),Log::warning(),Log::error()) write-mapped directly to the error stream. - Implemented automatic logging of incoming request methods/paths and corresponding response status codes.
- Introduced the static helper class
- Payload Optimizations:
- Configured
DataResponseto completely omit the"data"field from final JSON responses when its value isnull. - Added text masking styles and autocomplete attributes to password fields to prevent browser autofill suggestions.
- Configured
- Framework CLI Updater Improvements:
- Overhauled
php api-pro updateto clear out outdated files before copying, eliminating old directory junk. - Added a multi-layered downloader that tries
curlfirst before falling back to native stream wrappers. - Uses native PHP
ZipArchiveunpacking with a command-lineunzipfallback.
- Overhauled
How to Update an Installed Instance
To update your existing ApiPro project to this latest release, execute the built-in updater command from your terminal:
The updater will download the specified release, safely perform a fresh overwrite of the framework Core/ directory, and verify your updated setup while keeping your custom lib/ controllers/services and config.php files untouched.
License
This project is open-source software licensed under the MIT License.
All versions of api-pro with dependencies
ext-redis Version *