juaniquillo / base-backend-component
Framework-agnostic base state for backend components: attributes, contents, settings, themes, paths and array serialization. You choose how your components render.
Package info
github.com/juaniquillo/base-backend-component
pkg:composer/juaniquillo/base-backend-component
Requires
- php: ^8.3
- psr/simple-cache: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.89
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12
- rector/rector: ^2.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Framework-agnostic base state for backend components: attributes, contents, settings, themes, paths and array serialization. You choose how your components render (templates, plain strings, JSON, or anything else), and implement that part in your own package.
Install
composer require juaniquillo/base-backend-component
Requires PHP ^8.3.
Use
use Juaniquillo\BaseBackendComponent\BaseBackendComponent; use Juaniquillo\BaseBackendComponent\Themes\GenericThemeManager; $component = new BaseBackendComponent( 'button', new GenericThemeManager(__DIR__.'/themes'), ); $component ->setAttribute('id', 'save') ->setContent('Save') ->setTheme('action', 'success') ->setSetting('transition', 'fade'); $array = $component->toArray();
Restore later with:
use Juaniquillo\BaseBackendComponent\Deserializers\ComponentDeserializer; $restored = ComponentDeserializer::fromArray($array);
Theme files are plain PHP files returning arrays (default extension .php,
configurable through setThemeExtension()):
// themes/action.php return [ 'default' => 'bg-blue-700 hover:bg-blue-800', 'success' => 'bg-green-700 hover:bg-green-800', ];
Non-goals
This package never renders. There is no toHtml(), no renderable interface,
no template engine and no framework integration. Rendering, render caching
and framework wiring belong to the package that consumes this state. The
only cache primitives here are framework-free: the Cache contract,
DefaultCache, and the PSR-16 FileCache.
Building on it
Every concrete class in this package is final and is meant as a blueprint.
Do not extend them. Compose the traits under Concerns\ into your own
classes and implement only the contracts you need.
See docs/implementing-a-package.md for the full guide: contract and trait reference, worked examples for components, attribute bags, contents, themes, serialization, render caching, pitfalls and a test checklist.
Develop
composer install
composer test
composer run coverage:check
composer analyse
composer run format:check
composer run rector:check
composer qa
The suite must keep 100% statement coverage. composer qa:ci runs the same
checks plus the coverage gate, which is what CI executes.
License
MIT. See LICENSE.md.