Welcome to JiFramework, a lightweight and efficient PHP framework designed to simplify web application development. JiFramework emphasizes ease of use and flexibility, allowing you to build robust applications without unnecessary complexity or overhead.
Whether you're a seasoned developer or just starting out, JiFramework provides the tools you need to create powerful web applications quickly and efficiently.
Why JiFramework
Simplicity and Ease of Use
- Minimal Setup: Start developing immediately by including the autoloader—no complicated configurations required.
- No Template Engine Required: Use plain PHP for your views, giving you complete control over your application's presentation layer.
Flexibility and Modularity
- Component-Based Architecture: Include only the components you need, keeping your application lean and efficient.
- Easy Integration: JiFramework can be integrated into existing projects or used as the foundation for new ones.
Powerful Features
- Database Query Builder: Simplify database interactions with an intuitive and secure query builder.
- Robust Error Handling: Comprehensive error and exception handling mechanisms to ensure your application runs smoothly.
- Security Measures: Built-in features like CSRF protection, encryption, and rate limiting to enhance your application's security.
Performance
- Lightweight: Designed with performance in mind, JiFramework ensures your applications are fast and responsive.
- Efficient Codebase: Optimized components reduce resource consumption and improve execution times.
Setting up JiFramework is straightforward. Follow the steps below to install the framework and get started with your application.
Prerequisites
- PHP 7.4 or higher
- Composer installed globally on your system
Steps:
1. Create a New Project Directory (If Needed)
If you're starting a new project:
mkdir my_project
cd my_project
2. Initialize Composer
Run the following command to initialize Composer in your project directory:
composer init
Follow the prompts to generate a composer.json
file for your project.
3. Require JiFramework via Composer
Add JiFramework to your project by running:
composer require jiframework/jiframework
This command will install JiFramework and its dependencies into the vendor
directory.
4. Include the Autoloader in Your Project
In your application's entry point (e.g., index.php
), include Composer's autoloader:
require __DIR__ . '/vendor/autoload.php';
This line ensures that all JiFramework classes and any other dependencies are properly loaded.
Or download the zip file and extract the files and include the autoloader.
JiFramework is designed to work out of the box with minimal configuration. However, you can customize various settings to tailor the framework to your application's needs.
Basic Usage
After including the autoloader, you can start using JiFramework's components immediately. There are two primary ways to instantiate and use the framework's classes.
Option 1: Using the App Container
The App
class serves as a central container that initializes and manages the framework's components.
use JIFramework\Core\App\App;
$app = new App();
// Access the Query Builder for database operations
$db = $app->db;
// Access other components as needed
$logger = $app->logger;
$session = $app->sessionManager;
This approach centralizes component management, making it easier to handle dependencies and maintain your application.
Option 2: Instantiating Components Directly
If you prefer more granular control, you can instantiate individual components directly.
use JIFramework\Core\Database\QueryBuilder;
$db = new QueryBuilder();
// Perform database operations
$results = $db->table('users')->where('status', 'active')->get();
This method allows you to include only the components you need, potentially reducing overhead.
Configuration Options
JiFramework provides a Config
class where you can set various configuration options. Customize these settings to match your application's requirements.
1. Database Configuration
Configure your database connection settings in the Config
class.
namespace JIFramework\Config;
class Config {
const DB_HOST = 'localhost';
const DB_NAME = 'your_database_name';
const DB_USER = 'your_database_user';
const DB_PASS = 'your_database_password';
const DB_CHARSET = 'utf8mb4';
const DB_DRIVER = 'mysql'; // Supported drivers: mysql, pgsql, sqlite
}
2. Application Mode
Set the application mode to control error reporting and debugging information.
class Config {
const APP_MODE = 'development'; // Options: 'development' or 'production'
}
- Development: Displays detailed error messages and stack traces.
- Production: Suppresses detailed errors and logs them instead.
3. Logging Configuration
Configure logging preferences to keep track of application events and errors.
class Config {
const LOG_ENABLED = true;
const LOG_LEVEL = 'DEBUG'; // Options: 'DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'CRITICAL', 'ALERT', 'EMERGENCY'
const LOG_FILE_PATH = __DIR__ . '/../logs/';
const LOG_FILE_NAME = 'app.log';
const LOG_MAX_FILE_SIZE = 10485760; // Maximum log file size in bytes (e.g., 10 MB)
const LOG_MAX_FILES = 5; // Maximum number of log files to retain
}
4. Session Management
Customize session handling to enhance security and performance.
class Config {
const SESSION_LIFETIME = 3600; // Session lifetime in seconds
const SESSION_COOKIE_SECURE = true; // Use secure cookies (requires HTTPS)
const SESSION_COOKIE_HTTPONLY = true; // Make cookies inaccessible to JavaScript
const SESSION_COOKIE_SAMESITE = 'Lax'; // Options: 'Lax', 'Strict', 'None'
}
5. Security Settings
Configure security-related options such as CSRF protection and rate limiting.
class Config {
const CSRF_TOKEN_KEY = '_csrf_token';
const CSRF_TOKEN_EXPIRY = 3600; // Token expiry time in seconds
const RATE_LIMIT_ENABLED = true;
const RATE_LIMIT_REQUESTS = 100; // Maximum requests allowed
const RATE_LIMIT_TIME_WINDOW = 3600; // Time window in seconds
}
6. Error Handling
Define how your application responds to errors and exceptions.
class Config {
const ERROR_HANDLER_ENABLED = true;
const DISPLAY_ERRORS = false; // Set to true to display errors (not recommended in production)
}
Advanced Configuration
JiFramework allows further customization through its various components.
Error Handling and Logging
Customize the error handler and logger to integrate with third-party services or to modify how errors are captured and recorded.
Database Connections
Support for multiple database connections can be configured if your application interacts with more than one database.
Internationalization
If your application supports multiple languages, configure the LanguageManager
to manage translations and locale settings.
Additional Components
Explore and configure other components as needed:
- Cache Management
- Utility Helpers
- Networking Tools
- Security Enhancements
Next Steps
With JiFramework installed and configured, you're ready to start building your application. Refer to the detailed documentation for each component to learn more about their functionalities and how to leverage them effectively.