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-10-28 11:03:46 UTC
README
Core Framework Components - Container, Config, Foundation, Exceptions & Support
๐ Description
Kodhe Framework is the core package that provides the main foundation for Kodhe-based applications. It includes a Dependency Injection Container, a configuration system, application bootstrap, exception handling, controller base classes, and various helper functions.
It is designed to work seamlessly with other Kodhe packages such as kodhe/http, kodhe/view, kodhe/database, and more.
โจ Key Features
๐ง Dependency Injection Container
- Service registration and 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
๐ฆ Installation
Requirements
- PHP >= 8.1
- Composer
- kodhe/http package (required)
Install via Composer
composer require kodhe/framework
The package automatically installs these 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
๐๏ธ Package Structure
framework/
โโโ Resources/
โ โโโ fonts/ # Font files for typography
โ โโโ language/ # Translation files
โโโ src/
โ โโโ Config/
โ โ โโโ Loaders/
โ โ โ โโโ ArrayLoader.php # Loads config from an array
โ โ โ โโโ PhpLoader.php # Loads config from PHP files
โ โ โ โโโ FileLoader.php # Loads config from files
โ โ โ โโโ 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
๐ Usage
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 |
โ๏ธ Configuration
Config Paths
By default, the framework looks for configuration files in:
APPPATH . 'config/'
You can add additional paths:
$config->_config_paths[] = '/path/to/custom/config';
Service Registration
Register service providers in your application:
$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();
Legacy Hooks & PSR-14 Bridge
The CI3-style hook system (config/hooks.php, container service hooks) is
still supported. To migrate gradually, the framework ships a two-way adapter
in src/Support/Legacy/Bridge/ that works with any PSR-14 dispatcher
(kodhe/events, Symfony, League, โฆ) โ it does not live in the events package,
so events stay a general-purpose subsystem:
use Kodhe\Framework\Support\Legacy\Bridge\HookBridge; // hooks -> events: every call_hook('pre_system') also emits "hook.pre_system" $hooks = new HookBridge($legacyHooks, $psr14Dispatcher); $app->instance('hooks', $hooks); // events -> hooks: forward new PSR-14 events back into existing hook definitions $psr14Dispatcher->on('hook.*', $hooks->asListener());
๐งช 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
This package includes unit tests for:
- ContainerTest - Dependency Injection Container (register, make, singleton, bindings)
- ApplicationTest - Application bootstrap and lifecycle
- ConfigTest - Configuration loading and manipulation
- AutoloaderTest - PSR-4 autoloading functionality
๐ Migration from Previous Versions
Changes in 1.1.1
- โ
Extracted the CodeIgniter 3 legacy loader (
LegacyLoader) into a separate package:kodhe/legacy-loader - โ
FileLoaderstill extendsLegacyLoaderfor full CI3 compatibility - โ
The framework now requires
kodhe/legacy-loaderautomatically
If you are upgrading from a previous version:
composer update kodhe/framework
The legacy loader will be installed automatically.
๐ค Contributing
Contributions are welcome! Please:
- Fork repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
Kodhe Framework is licensed under the MIT License.
๐ Support
For questions, issues, or feature requests:
- ๐ง Email: support@kodhe.com
- ๐ฌ GitHub Issues: https://github.com/kodhe/kodhe/issues
- ๐ Documentation: https://kodhe.com/docs
๐ Credits
Created and maintained by the Karya Kode Team.
Special thanks to:
- The CodeIgniter 3 team for the legacy-compatibility inspiration
- All Kodhe Framework contributors
Happy Coding! ๐
Made with โค๏ธ by Karya Kode