Download the PHP package damarbob/starcore without Composer
On this page you can find all versions of the php package damarbob/starcore. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download damarbob/starcore
More information about damarbob/starcore
Files in damarbob/starcore
Package starcore
Short Description The HMVC and Hook Orchestration Kernel for CodeIgniter 4
License MIT
Informations about the package starcore
StarCore
The HMVC and Hook Orchestration Kernel for CodeIgniter 4
StarCore is a lightweight, powerful library designed to bring Hierarchical Model-View-Controller (HMVC) architecture and a robust Hook Orchestration system to CodeIgniter 4 applications. It enables modular application development and provides a flexible event-driven architecture.
Features
- HMVC Architecture: Organize your application into reusable modules with their own routes, controllers, models, and views.
- Hook Orchestration: A powerful event system supporting Actions, Filters, and Triggers with priority management.
- Module Autoloading: Automatically discovers and loads modules from
modules/directory. - Zero Configuration: Works out of the box with sensible defaults, but fully configurable.
Installation
Install via Composer:
Configuration
Active Modules
By default, StarCore looks for modules in the modules/ directory. You can configure active modules in Config/Star.php (publish this file to your application's app/Config directory if needed, or modify it in place for the library).
Alternatively, you can set this in your .env file:
Development Modules
Development modules are located in the modules/.star-dev/ directory. These modules are either experimental or intended for development tools and features, and should not be enabled in production.
You can configure active development modules in Config/Star.php:
Alternatively, you can set this in your .env file:
Note: Development modules are automatically disabled when
safeModeis enabled.
Safe Mode
Safe mode disables all modules, useful for debugging or maintenance.
Usage
Hooks
StarCore provides a global helper function hook() and a service HyperHooks to manage events.
Registering a Hook
You can register hooks in your module's init.php or any other loaded file.
Triggering a Hook
Using the hook() Helper
The hook() helper is used to retrieve hook configurations or values from Hooks/ files in your modules.
Creating a Hook
To create a hook that can be retrieved via the hook() helper, create a file in your module's Hooks/ directory (e.g., modules/Blog/Hooks/Frontend.php). This file should return an associative array of Star\HyperHook objects.
You can then access these hooks using hook('Frontend.header') or hook('Frontend.footer').
Dynamic Hook Names
You can use placeholders in your hook values to make them dynamic. Placeholders are defined using curly braces, e.g., {name}.
1. Create a hook with a placeholder:
2. Retrieve the hook with parameters:
Pass an associative array as the second argument to the hook() helper to replace the placeholders.
Module Structure
A typical module structure looks like this:
Development Module Structure
A typical development module structure looks like this:
Module Autoloading
StarCore automatically discovers and loads modules located in the modules/ directory (and modules/.star-dev/ for development modules). This process happens immediately when the library is loaded (before the pre_system event) to ensure namespaces and event listeners are available during the application bootstrapping.
- Namespace Registration: The autoloader automatically registers the module's namespace based on its directory name. For example, a module in
modules/Blogwill have theBlognamespace registered. - Initialization: If an
init.phpfile exists in the module's root, it is executed. This is the ideal place to register hooks or perform other setup tasks.
Composer Compatibility
StarCore is designed to work seamlessly with Composer.
- Library Support: You can use any StarCore-supported module as a Composer package. Simply require it in your project's
composer.jsonand use it as usual. StarCore prioritizes Composer packages over its own modules. - Local Modules: Unlike Composer’s autoloader, StarCore’s autoloader automatically registers namespaces for modules in the
modules/directory. This means you don’t need to runcomposer dump-autoloadevery time you create a new module or class, helping speed up your development workflow.
Choose the option that best fits your needs.
License
This project is licensed under the MIT License.