Download the PHP package tiao2/php-tools without Composer
On this page you can find all versions of the php package tiao2/php-tools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tiao2/php-tools
More information about tiao2/php-tools
Files in tiao2/php-tools
Package php-tools
Short Description Modular PHP website building toolkit with SSO, community, API gateway and unified exception handling
License Apache-2.0
Informations about the package php-tools
PHP Tools - Modular Website Building Toolkit
A modular PHP library for building websites with SSO authentication, community features, API gateway and unified exception handling.
Features
- SSO Module: Token + AuthCode dual-factor session management with IP binding, support for MySQL/Redis storage.
- Community Module: User management, ACL permission control, post management, file upload, internal notifications, cache driver, logging, and CAPTCHA generation.
- API Gateway: Lightweight router, global middleware support (auth, rate limiting, versioning), unified JSON response and exception handling.
- Unified Exception Handling: Automatic detection of API/Web requests, returns structured JSON or debug HTML.
- Out of the box: PSR-4 autoloading, centralized configuration, minimal dependencies.
Requirements
- PHP >= 8.0
- Composer
- MySQL 5.7+ (or MariaDB 10.2+)
- Redis (optional, for distributed rate limiting and SSO storage)
Quick Start
1. Create project and install dependencies
Or clone the repository manually and run:
2. Configure environment variables
Copy .env.example to .env and adjust settings according to your environment:
Edit .env to set database connection, SSO expiration times, rate limiting parameters, etc. All modules are enabled by default and can be disabled via *_ENABLED variables.
3. Create database tables
Execute the following SQL to create the required tables (SSO sessions, users, posts, etc.):
4. Implement user authentication interface
The SSO module requires you to provide real user verification logic. Create a class that implements PhpTools\SSO\AuthenticatorInterface, for example:
Then pass an instance of it to SSO::fromEnv() in your entry file index.php.
5. Configure web server
Point your website root to public/ (if you use public/index.php) or directly to the project root's index.php. It is recommended to use public/ as the public directory for better security.
6. Access the application
Visit your domain. If everything is configured correctly, you will see the default API response (or routes you defined).
Directory Structure
Module Overview
SSO (Single Sign-On)
- Login:
$sso->login($username, $password)returns token and authcode. - Verification:
$sso->verify($token, $authcode, $ip)returns user ID. - Storage: Default MySQL, can be switched to Redis via
.env. - IP Binding: IPv4 exact match, IPv6 prefix match (default /64).
Community
All sub-modules extend CommunityBase and use SSO for authentication. Sub-module switches are controlled by COMMUNITY_*_ENABLED.
| Sub-module | Main Features |
|---|---|
| User | User profile query and update |
| Acl | Role-based permission checking |
| Content | Post creation, listing, deletion (with permission checks) |
| File | File upload, download, deletion (with type and size restrictions) |
| Notification | Send, query, mark-as-read for internal notifications |
| Cache | File cache implementation (supports TTL) |
| Log | Simple file logger |
| Captcha | Math or text CAPTCHA generation |
API Gateway
- Router: Supports
GET/POST/PUT/DELETE, path parameters{id}. - Middleware:
AuthMiddleware: ReadsX-API-TokenandX-API-AuthCodefrom headers for authentication.RateLimitMiddleware: Supports in-memory or Redis rate limiting, returns 429 status withRetry-Afterheader.VersionMiddleware: Sets controller namespace prefix based onX-API-Versionheader.
- Exception Handling: Unified capture; API requests return JSON errors, HTML requests show a debug page (in development mode).
Configuration Reference (.env)
| Variable | Description | Default |
|---|---|---|
| APP_DEBUG | Debug mode, shows detailed errors | false |
| SSO_ENABLED | Enable SSO module | true |
| COMMUNITY_ENABLED | Enable Community module | true |
| API_ENABLED | Enable API module | true |
| SSO_TOKEN_EXPIRE | Token expiration (seconds) | 3600 |
| SSO_AUTHCODE_EXPIRE | AuthCode expiration (seconds) | 3600 |
| SSO_IPV6_PREFIX | IPv6 prefix length to compare | 64 |
| DB_HOST / DB_PORT etc. | Database connection parameters | localhost |
| API_RATE_LIMIT_REQUESTS | Max requests per window | 100 |
| API_RATE_LIMIT_WINDOW | Rate limit window (seconds) | 60 |
| API_RATE_LIMIT_DRIVER | Rate limit driver (memory/redis) | memory |
See
.env.examplefor more configuration items
Usage Examples
1. Enable SSO Login
2. Create a Post (Community Content)
3. Register API Routes
Extending
- New storage driver: Implement
StorageInterface, instantiate inSSO::fromEnvas needed. - New rate limiter: Implement
RateLimiterInterface, inject intoRateLimitMiddleware. - New middleware: Implement
MiddlewareInterface, register via$router->addGlobalMiddleware(). - New Community sub-module: Extend
CommunityBase, add dependencies inModuleManager.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contact
For questions or suggestions, please open an issue or pull request.