Download the PHP package cuongnd88/atom without Composer
On this page you can find all versions of the php package cuongnd88/atom. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cuongnd88/atom
More information about cuongnd88/atom
Files in cuongnd88/atom
Package atom
Short Description Atom Framework
License MIT
Homepage https://github.com/cuongnd88/atom
Informations about the package atom
Atom
A lightweight PHP framework that implements the MVC pattern.
Please read more about the Request Lifecycle.
Table of Contents
- Features
- Installation
- Quick Start
- Directory Structure
- Routing
- Middleware
- Controllers
- Request
- Response
- Database / Query Builder
- Models
- Validation
- Authentication
- Views & Templates
- Storage
- Signed URLs
- File Handling
- Service Container
- Helpers
- Example Project
- License
Features
- MVC architecture with single entry point
- Fluent query builder with MySQL support
- Route-based middleware with priority ordering
- Dependency injection container
- Input validation with 15 built-in rules
- JWT-based and session-based authentication
- View rendering and template composition
- File storage abstraction
- Signed URLs with expiration
- CSV, Image, and Log file handling
Installation
Requirements: PHP >= 7.0
Quick Start
Create your entry point public/index.php:
The Server constructor accepts an array of config file names to load. The env file (e.g., config/env.ini) is loaded to set environment variables.
Application Constants
Define these constants in your bootstrap to configure directory paths:
Directory Structure
Routing
Routes are defined as PHP arrays in routes/web.php and routes/api.php.
Dynamic parameters use {param} syntax and are automatically extracted and injected into the Request object.
Supported HTTP methods: GET, POST, PUT, PATCH, DELETE
API routes are automatically detected when the URI contains api or the Content-Type header is application/json.
Middleware
Configuration
Define middleware in config/middleware.php:
Creating Middleware
Place middleware files in your MIDDLEWARE_PATH directory. Each middleware must implement a handle() method:
Attaching Middleware to Routes
Middlewares are sorted by priority and executed in order before the controller action.
Controllers
Controllers are loaded from the CONTROLLER_PATH directory. Method parameters are automatically resolved via the service container.
Request
The Request class collects parameters from URI, query string, POST data, file uploads, and JSON body automatically.
Response
Database / Query Builder
Database credentials are loaded from environment variables: DB_CONNECTION, DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, DB_PORT.
Basic Queries
Where Conditions
Use the # prefix on a key to reference a raw column name (no quoting):
Joins
Grouping & Ordering
Insert
Update & Delete
Chunking
Process large result sets in chunks:
Transactions
Query Logging
Mass Assignment Protection
Only name and email columns will be inserted; any other keys in the input are ignored.
Models
Create models by extending the abstract Model class:
CRUD Operations
Models inherit all query builder methods:
Validation
Use the Validator trait in your controllers:
Custom Error Messages
Available Rules
| Rule | Description | Example |
|---|---|---|
required |
Must not be empty | 'required' |
string |
Must be a string | 'string' |
integer |
Must be an integer | 'integer' |
email |
Must be a valid email | 'email' |
array |
Must be an array | 'array' |
date |
Must be a valid date | 'date' |
date_format |
Must match date format | 'date_format:Y-m-d' |
image |
Must be an image (jpeg, png, bmp, gif, svg) | 'image' |
between |
Must be between min and max | 'between:1,100' |
min |
Must be >= value | 'min:18' |
max |
Must be <= value | 'max:200' |
in_array |
Must be one of the listed values | 'in_array:a,b,c' |
after |
Date must be after given date | 'after:2024-01-01' |
before |
Date must be before given date | 'before:2025-12-31' |
required_if |
Required if another field is present | 'required_if:role,admin' |
Rules are combined with |: 'required|email|string'
Authentication
Use the Auth trait for session-based and JWT authentication.
Configuration
In config/app.php:
Set APP_KEY and SESSION_LIFETIME (in minutes) in your env.ini.
Usage
API Authentication
When app.auth.response.success is empty, login() returns a JSON response with the JWT token:
The token can be sent in the Authorization header for subsequent requests.
Views & Templates
Simple Views
Views are PHP files located in VIEW_PATH. Use dot notation to reference subdirectories:
Inside view files, the data array is extracted into variables:
Templates
Templates allow composing multiple view files into a layout. Define templates in config/templates.php:
Use the template() helper to render:
Storage
Local Storage
Configure storage drivers in config/app.php:
Signed URLs
Generate URLs with HMAC signatures and optional expiration:
File Handling
CSV
Image
Logging
Service Container
The container automatically resolves type-hinted dependencies in controller methods:
In controller methods, dependencies are auto-injected:
Helpers
| Function | Description |
|---|---|
config('app.key') |
Load config value using dot notation |
route('web.users') |
Load route definition |
env('DB_HOST') |
Get environment variable |
view('users.index', $data) |
Render a view file |
template('layout', 'page', $data) |
Render a template |
url('/path') |
Get full URL |
back() |
Redirect to previous page |
now() |
Current timestamp (Y-m-d H:i:s) |
today() |
Current date (Y-m-d) |
json($data) |
Convert to JSON |
isApi() |
Check if request is API |
storage_path('uploads') |
Get storage directory path |
resources_path('views') |
Get resources directory path |
public_path('images') |
Get public directory path |
assets('/css/app.css') |
Get asset URL |
getHeaders() |
Get all HTTP request headers |
imageLocation($file) |
Extract GPS coordinates from image EXIF |
Example Project
For a full implementation example, see the EzyCrazy project built with Atom.
License
MIT