kodhe / framework
Kodhe Framework Core - Container, Config, Foundation, Exceptions & Support
Requires
- php: >=8.1
- kodhe/cache: ^1.0 || ^2.0
- kodhe/session: ^1.0 || ^2.0
- kodhe/validation: ^1.0 || ^2.0
- paragonie/random_compat: ^9.99
Requires (Dev)
- phpunit/phpunit: ^9.0
Suggests
- kodhe/agent: Resolved by the container service `agent` (Kodhe\Framework\Agent\UserAgent)
- kodhe/auth: Session-based authentication guard with remember-me (Kodhe\Framework\Auth\Auth)
- kodhe/cart: Resolved by the container service `cart` (Kodhe\Framework\Cart\Cart)
- kodhe/driver: Resolved by the container service `driver` (Kodhe\Framework\Driver\Driver)
- kodhe/pagination: Resolved by the container service `pagination` (Kodhe\Framework\Pagination\Pagination)
- kodhe/test: Resolved by the container service `unit_test` (Kodhe\Framework\Test\UnitTest)
- kodhe/view: REQUIRED for templating / app('view') / ViewFactory (resolved at runtime)
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-09-29 21:52:21 UTC
README
Core Framework Components - Container, Config, Foundation, Exceptions & Support
๐ Deskripsi
Kodhe Framework adalah package inti yang menyediakan fondasi utama untuk aplikasi berbasis Kodhe. Package ini mencakup Dependency Injection Container, sistem konfigurasi, application bootstrap, exception handling, controller base classes, dan berbagai helper functions.
Package ini dirancang untuk bekerja seamlessly dengan package Kodhe lainnya seperti kodhe/http, kodhe/view, kodhe/database, dan lain-lain.
โจ Fitur Utama
๐ง Dependency Injection Container
- Service registration dan resolution
- Singleton pattern support
- Automatic dependency resolution
- Closure-based bindings
- Namespace-aware service naming
โ๏ธ Configuration System
- Multi-format config loading (PHP arrays, legacy CI3 format)
- Module-aware configuration
- Config caching support
- ArrayAccess interface for easy access
- Runtime config manipulation
๐ Application Foundation
- Modern application entry point
- Kernel bootstrapping
- Service provider registration
- Auto-loading integration
- Request/Response lifecycle management
๐ฏ Service Management
- Service Locator pattern
- Service Manager for core components
- Service Provider abstraction
- Lazy loading support
- Module service registration
๐ฎ Controller System
- Base Controller class
- Error handling controllers (404, exceptions)
- Integration with HTTP layer
- View rendering helpers
๐ ๏ธ Exception Handling
- Hierarchical exception classes
- Auth exceptions
- Database exceptions
- HTTP exceptions
- Middleware exceptions
- Routing exceptions
- Service exceptions
๐ Support Utilities
- Autoloader (PSR-4 compatible)
- Helper functions (global helpers)
- Module system
- Facade pattern support
- Legacy CodeIgniter 3 compatibility layer
- File/Namespace helper loaders
๐ฆ Instalasi
Requirements
- PHP >= 8.1
- Composer
- kodhe/http package (required)
Install via Composer
composer require kodhe/framework
Package akan otomatis menginstall dependencies:
paragonie/random_compat^9.99kodhe/http*
Optional Packages (Suggested)
# Session handling composer require kodhe/session # Caching composer require kodhe/cache # Database & ORM composer require kodhe/database # Templating / Views (REQUIRED for app('view')) composer require kodhe/view # Form validation composer require kodhe/validation # User agent library composer require kodhe/agent
๐๏ธ Struktur Package
framework/
โโโ Resources/
โ โโโ fonts/ # Font files untuk typography
โ โโโ language/ # Translation files
โโโ src/
โ โโโ Config/
โ โ โโโ Loaders/
โ โ โ โโโ ArrayLoader.php # Load config dari array
โ โ โ โโโ PhpLoader.php # Load config dari file PHP
โ โ โ โโโ FileLoader.php # Load config dari file
โ โ โ โโโ LegacyLoader.php # CI3 compatibility loader
โ โ โโโ Config.php # Main config class
โ โ โโโ ConfigInterface.php # Config contract
โ โ โโโ Setup.php # Setup configuration
โ โ
โ โโโ Container/
โ โ โโโ Binding/
โ โ โ โโโ BindingInterface.php
โ โ โ โโโ ConcreteBinding.php
โ โ โโโ Container.php # DI Container implementation
โ โ
โ โโโ Controllers/
โ โ โโโ Error/
โ โ โ โโโ FileNotFound.php # 404 handler
โ โ โ โโโ CPException.php # Control panel exception
โ โ โโโ BaseController.php # Base controller class
โ โ
โ โโโ Exceptions/
โ โ โโโ Auth/ # Authentication exceptions
โ โ โโโ Database/ # Database exceptions
โ โ โโโ Http/ # HTTP exceptions
โ โ โโโ Middleware/ # Middleware exceptions
โ โ โโโ Routing/ # Routing exceptions
โ โ โโโ Service/ # Service exceptions
โ โ
โ โโโ Foundation/
โ โ โโโ Application.php # Main application class
โ โ โโโ Service/
โ โ โโโ ServiceManager.php # Core service manager
โ โ โโโ ServiceLocator.php # Service locator pattern
โ โ โโโ ServiceProvider.php # Service provider abstract
โ โ โโโ ServiceHelper.php # Service helper utilities
โ โ
โ โโโ Support/
โ โโโ Facades/ # Facade classes
โ โโโ Helpers/ # Helper functions
โ โโโ Loaders/
โ โ โโโ FileHelperLoader.php
โ โ โโโ NamespaceHelperLoader.php
โ โ โโโ HelperLoaderFacade.php
โ โ โโโ HelperLoaderInterface.php
โ โโโ Legacy/ # CodeIgniter 3 compatibility
โ โ โโโ compat/
โ โ โ โโโ hash.php
โ โ โ โโโ password.php
โ โ โ โโโ standard.php
โ โ โโโ Security.php
โ โ โโโ Exceptions.php
โ โ โโโ Log.php
โ โ โโโ LegacyOutput.php
โ โ โโโ Benchmark.php
โ โ โโโ URI.php
โ โ โโโ Input.php
โ โ โโโ common.php
โ โโโ Autoloader.php # PSR-4 Autoloader
โ โโโ Modules.php # Module system
โ โโโ Helpers.php # Global helper functions
โ
โโโ composer.json
โโโ LICENSE
โโโ README.md
๐ Penggunaan
1. Application Bootstrap
<?php require_once 'vendor/autoload.php'; use Kodhe\Framework\Foundation\Application; use Kodhe\Framework\Container\Container; // Create container (optional - will create default if not provided) $container = new Container(); // Create application instance $app = Application::create($container); // Bootstrap the application $app->bootstrap(); // Run the application $app->run();
2. Dependency Injection Container
<?php use Kodhe\Framework\Container\Container; $container = new Container(); // Register a service $container->bind('database', function($app) { return new Database\Connection([ 'host' => 'localhost', 'user' => 'root', 'password' => 'secret' ]); }); // Register a singleton $container->singleton('cache', function($app) { return new Cache\Manager(); }); // Resolve a service $db = $container->resolve('database'); $cache = $container->resolve('cache'); // Check if service exists if ($container->has('database')) { echo "Database service is registered"; } // Get all bindings $bindings = $container->getBindings(); $singletons = $container->getSingletonBindings();
3. Configuration Loading
<?php use Kodhe\Framework\Config\Config; $config = new Config(); // Load a config file $config->load('database'); // Access config values $dbHost = $config->item('database.default.hostname'); $dbUser = $config->item('database.default.username'); // Set config at runtime $config->set_item('app_name', 'My Application'); $config->set_item('debug_mode', true); // Check if config exists if ($config->has('app_name')) { echo $config->item('app_name'); } // Array access echo $config['app_name']; $config['debug_mode'] = false;
4. Service Providers
<?php use Kodhe\Framework\Foundation\Service\ServiceProvider; use Kodhe\Framework\Container\Container; class DatabaseServiceProvider extends ServiceProvider { public function register() { $this->container->singleton('db', function($app) { $config = $app->resolve('config'); return new Database\Connection($config->item('database')); }); } public function boot() { // Called after all services are registered $db = $this->container->resolve('db'); $db->connect(); } } // Register in Application $app->registerProvider(DatabaseServiceProvider::class);
5. Base Controller
<?php namespace App\Controllers; use Kodhe\Framework\Http\Controllers\BaseController; class UserController extends BaseController { protected $middleware = ['auth']; public function index() { $users = $this->resolve('userModel')->getAll(); return $this->response->view('users.index', [ 'users' => $users ]); } public function show($id) { $user = $this->resolve('userModel')->find($id); if (!$user) { return $this->response->notFound(); } return $this->response->view('users.show', [ 'user' => $user ]); } }
6. Exception Handling
<?php use Kodhe\Framework\Exceptions\Http\HttpException; use Kodhe\Framework\Exceptions\Auth\AuthenticationException; use Kodhe\Framework\Exceptions\Database\QueryException; try { // Some operation throw new HttpException(404, 'Resource not found'); } catch (AuthenticationException $e) { // Handle auth exception return redirect()->to('login'); } catch (HttpException $e) { // Handle HTTP exception return response()->json([ 'error' => $e->getMessage() ], $e->getStatusCode()); } catch (QueryException $e) { // Handle database exception log_error($e->getMessage()); return response()->json(['error' => 'Database error'], 500); }
7. Helper Functions
<?php // Load a class instance $db = load_class('Database', 'libraries'); // Get application instance $app = kodhe(); // Access services via app() helper $config = app('config'); $request = app('request'); $response = app('response'); $view = app('view'); // Check if running in CLI if (is_cli()) { echo "Running from command line"; } // Get config item $baseUrl = config_item('base_url'); // Log message log_message('info', 'User logged in'); // Show error show_error('Something went wrong', 500); show_404('Page not found');
8. Module System
<?php use Kodhe\Framework\Support\Modules; // Find module file list($path, $file) = Modules::find('config', 'blog', 'config/'); // Load module file $data = Modules::load_file('routes', 'blog', 'config'); // Get module path $modulePath = Modules::locate('blog');
๐ Class Reference
Core Classes
| Class | Namespace | Description |
|---|---|---|
Container |
Kodhe\Framework\Container |
Dependency Injection Container |
Application |
Kodhe\Framework\Foundation |
Main application entry point |
Config |
Kodhe\Framework\Config |
Configuration manager |
ServiceManager |
Kodhe\Framework\Foundation\Service |
Core service manager |
ServiceLocator |
Kodhe\Framework\Foundation\Service |
Service locator registry |
ServiceProvider |
Kodhe\Framework\Foundation\Service |
Service provider abstract |
Autoloader |
Kodhe\Framework\Support |
PSR-4 autoloader |
Modules |
Kodhe\Framework\Support |
Module system |
Config Loaders
| Class | Description |
|---|---|
ArrayLoader |
Load configuration from PHP arrays |
PhpLoader |
Load configuration from PHP files |
FileLoader |
Load configuration from files |
LegacyLoader |
CodeIgniter 3 compatibility loader |
Exception Classes
| Namespace | Purpose |
|---|---|
Auth |
Authentication & authorization exceptions |
Database |
Database query and connection exceptions |
Http |
HTTP status code exceptions |
Middleware |
Middleware pipeline exceptions |
Routing |
Route matching and generation exceptions |
Service |
Service resolution exceptions |
Controllers
| Class | Description |
|---|---|
BaseController |
Base controller with common functionality |
FileNotFound |
404 error handler controller |
CPException |
Control panel exception handler |
โ๏ธ Konfigurasi
Config Paths
Secara default, framework mencari file konfigurasi di:
APPPATH . 'config/'
Anda dapat menambahkan path tambahan:
$config->_config_paths[] = '/path/to/custom/config';
Service Registration
Daftarkan service providers di aplikasi Anda:
$app->registerProvider(App\Providers\AppServiceProvider::class); $app->registerProvider(App\Providers\RouteServiceProvider::class); $app->registerProvider(App\Providers\DatabaseServiceProvider::class);
Container Configuration
$container = new Container(); // Enable/disable duplicate registration exceptions $container->setThrowOnDuplicate(false); // Check current setting $throwOnDuplicate = $container->getThrowOnDuplicate();
๐งช Testing
# Install dependencies composer install # Run all tests vendor/bin/phpunit # Run specific test file vendor/bin/phpunit tests/ContainerTest.php vendor/bin/phpunit tests/ApplicationTest.php vendor/bin/phpunit tests/ConfigTest.php vendor/bin/phpunit tests/AutoloaderTest.php # Run with coverage vendor/bin/phpunit --coverage-html coverage/ # Run with verbose output vendor/bin/phpunit -v
Test Coverage
Package ini mencakup unit tests untuk:
- ContainerTest - Dependency Injection Container (register, make, singleton, bindings)
- ApplicationTest - Application bootstrap dan lifecycle
- ConfigTest - Configuration loading dan manipulation
- AutoloaderTest - PSR-4 autoloading functionality
๐ Migrasi dari Versi Sebelumnya
Changes in 1.1.1
- โ
Extracted CodeIgniter 3 Legacy Loader (
LegacyLoader) ke separate package:kodhe/legacy-loader - โ
FileLoadermasih extendsLegacyLoaderuntuk full CI3 compatibility - โ
Framework sekarang requires
kodhe/legacy-loadersecara otomatis
Jika Anda upgrade dari versi sebelumnya:
composer update kodhe/framework
Legacy loader akan terinstall otomatis.
๐ค Kontribusi
Kami menyambut kontribusi! Silakan:
- Fork repository
- Buat feature branch (
git checkout -b feature/amazing-feature) - Commit perubahan (
git commit -m 'Add amazing feature') - Push ke branch (
git push origin feature/amazing-feature) - Buka Pull Request
๐ License
Kodhe Framework dilisensikan di bawah MIT License.
๐ Support
Untuk pertanyaan, issue, atau request fitur:
- ๐ง Email: support@kodhe.com
- ๐ฌ GitHub Issues: https://github.com/kodhe/kodhe/issues
- ๐ Dokumentasi: https://kodhe.com/docs
๐ Credits
Dibuat dan maintained oleh Karya Kode Team.
Special thanks to:
- CodeIgniter 3 team untuk inspiration legacy compatibility
- Semua contributor Kodhe Framework
Happy Coding! ๐
Made with โค๏ธ by Karya Kode