PHPackages                             damarbob/starcore - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. damarbob/starcore

ActiveLibrary

damarbob/starcore
=================

The HMVC and Hook Orchestration Kernel for CodeIgniter 4

v0.2.0(4mo ago)11611MITPHPPHP ^8.1

Since Nov 26Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/damarbob/StarCore)[ Packagist](https://packagist.org/packages/damarbob/starcore)[ RSS](/packages/damarbob-starcore/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (7)Used By (1)

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
--------

[](#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
------------

[](#installation)

Install via Composer:

```
composer require damarbob/starcore
```

Configuration
-------------

[](#configuration)

### Active Modules

[](#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).

```
// app/Config/Star.php

protected string $activeModules = 'Blog,Auth,Shop';
```

Alternatively, you can set this in your `.env` file:

```
Star.activeModules = 'Blog,Auth,Shop'
```

### Development Modules

[](#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`:

```
protected string $activeDevModules = 'DebugToolbar,Generator';
```

Alternatively, you can set this in your `.env` file:

```
Star.activeDevModules = 'DebugToolbar,Generator'
```

> **Note:** Development modules are automatically disabled when `safeMode` is enabled.

### Safe Mode

[](#safe-mode)

Safe mode disables all modules, useful for debugging or maintenance.

```
public bool $safeMode = true;
```

Usage
-----

[](#usage)

### Hooks

[](#hooks)

StarCore provides a global helper function `hook()` and a service `HyperHooks` to manage events.

#### Registering a Hook

[](#registering-a-hook)

You can register hooks in your module's `init.php` or any other loaded file.

```
use StarCore\Service\HyperHooks;

// Register an action (side-effect)
HyperHooks::getInstance()->register('user.login', function($user) {
    log_message('info', 'User logged in: ' . $user->id);
});

// Register a filter (modify value)
HyperHooks::getInstance()->register('content.render', function($content) {
    return strtoupper($content);
});
```

#### Triggering a Hook

[](#triggering-a-hook)

```
// Trigger an action
$hooks = service('hooks');
$hooks->action('user.login', [$currentUser]);

// Apply filters
$content = "hello world";
$content = $hooks->filter('content.render', $content); // Returns "HELLO WORLD"
```

#### Using the `hook()` Helper

[](#using-the-hook-helper)

The `hook()` helper is used to retrieve hook configurations or values from `Hooks/` files in your modules.

```
// Returns the value of 'header' from 'Hooks/Frontend.php'
$headerHook = hook('Frontend.header');
```

#### Creating a Hook

[](#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.

```
