phil / spaces
Let groups, organizations and courses each turn modules on and off: one registry of what modules bring, with settings, tabs and roles per space.
Requires
- php: >=8.5
- ext-mbstring: *
- psr/event-dispatcher: ^1.0
Requires (Dev)
- phpunit/phpunit: ^13.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-03 01:32:58 UTC
README
Groups, organizations and courses each choose their modules — forum, polls, courses, files — from one registry of what each module brings: enabled space by space, with its settings, its tab in the order the space likes and its permissions given to the roles of the space.
phil/spaces is the registry an application shares between every kind of space it has. A module is declared once, by the bundle that provides it: its name and label, the kinds of space it applies to, the modules it needs, the permissions it defines with the roles that hold them by default, its settings with their types and bounds, and its tab, placed before or after other modules — never by a number. The registry checks them as a whole when the application starts: each name once, each dependency installed and applying wherever its dependent applies, no cycle of dependencies, and an order of the tabs that honours every before and after.
A space — a group, an organization, a course, any place named by a kind and an identifier — then enables the modules it wants. Enabling checks the kind and the dependencies; disabling a module another active module needs is refused; a module disabled loses its tab and its permissions and keeps its settings and its content for the day it comes back. The space sets the settings, puts its favourite tabs first and chooses which of its roles hold each permission. Each change is saved under the version read, so that two administrators never overwrite each other, and dispatched as a PSR-14 event that carries identifiers only.
A page reads a view of the space once — its active modules, its tabs in order, the settings with their defaults and who holds each permission — and every question after that is a lookup.
It is a plain PHP library on psr/event-dispatcher. What a space chose lives in a store behind an interface, in memory
for tests and scripts, and a codec writes it as one versioned, strictly read JSON document for a store that keeps it
in a single column. The library holds no state between calls and runs in a worker. Who is an organizer or a member of
a space, the pages and the database tables belong to the application or to a bundle.
Status
| Part | State |
|---|---|
| Module definitions — kinds, dependencies, permissions with default roles, typed settings, tabs — built or read from configuration | Implemented and tested |
| The registry, checked as a whole, with the default order of the tabs from before and after | Implemented and tested |
| Enabling, disabling, settings, order of the tabs and roles of each permission, per space, under a version, with events | Implemented and tested |
| The view of a space: active modules, tabs, settings with defaults, permissions | Implemented and tested |
| The in-memory store and the JSON codec, with two fuzz targets and a benchmark | Implemented and tested |
| A Symfony bundle: modules declared by tagged services, a Doctrine store, the administration page of a space | Not written |
Documentation
| Document | What it covers |
|---|---|
| Installation | Requirements, installing, building the service. |
| Modules | Declaring a module, its permissions, settings and tab, the configuration format, the registry checks. |
| Spaces | Enabling and disabling, settings, tabs, roles, the view, versions and events, storing a space. |
| Extension points | The ports, events and arguments an application chooses or replaces. |
| Testing | The package's tests, fuzz targets and benchmark, and how to test code that reads spaces. |
| Reference | Every public type, with its role. |
Quick start
composer require phil/spaces
use Phil\Spaces\InMemorySpaceStore; use Phil\Spaces\ModuleDefinition; use Phil\Spaces\ModuleRegistry; use Phil\Spaces\Permission; use Phil\Spaces\SettingDefinition; use Phil\Spaces\SpaceRef; use Phil\Spaces\Spaces; use Phil\Spaces\Tab; $spaces = new Spaces(new ModuleRegistry([ new ModuleDefinition('members', 'Members', tab: new Tab('space_members', 'Members')), new ModuleDefinition( 'forum', 'Forum', kinds: ['group'], requires: ['members'], permissions: [new Permission('forum.post', ['member', 'organizer'])], settings: [SettingDefinition::boolean('slow_mode', false)], tab: new Tab('space_forum', 'Forum', before: ['members']), ), ]), new InMemorySpaceStore()); $club = new SpaceRef('group', 'chess-club'); $spaces->enable($club, 'members'); $spaces->enable($club, 'forum', ['slow_mode' => true]); $view = $spaces->view($club); $view->tabs(); // forum, then members $view->allows(['member'], 'forum.post'); // true $view->setting('forum', 'slow_mode'); // true
Requirements
PHP 8.5 or later with ext-mbstring.
Contributing
Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.
License
MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See LICENSE.