{"id":37236280,"url":"https://github.com/x3p0-dev/x3p0-framework","last_synced_at":"2026-01-16T04:51:53.617Z","repository":{"id":324757481,"uuid":"1098370533","full_name":"x3p0-dev/x3p0-framework","owner":"x3p0-dev","description":"🧰 A lightweight, modern dependency injection framework for WordPress plugins and themes.","archived":false,"fork":false,"pushed_at":"2025-11-23T06:40:36.000Z","size":42,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-14T14:50:08.965Z","etag":null,"topics":["wordpress","wordpress-development"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/x3p0-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-17T15:49:32.000Z","updated_at":"2026-01-08T10:22:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/x3p0-dev/x3p0-framework","commit_stats":null,"previous_names":["x3p0-dev/x3p0-framework"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/x3p0-dev/x3p0-framework","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x3p0-dev%2Fx3p0-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x3p0-dev%2Fx3p0-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x3p0-dev%2Fx3p0-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x3p0-dev%2Fx3p0-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/x3p0-dev","download_url":"https://codeload.github.com/x3p0-dev/x3p0-framework/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x3p0-dev%2Fx3p0-framework/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28442367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T00:55:22.719Z","status":"online","status_checked_at":"2026-01-15T02:00:08.019Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wordpress","wordpress-development"],"created_at":"2026-01-15T04:12:51.966Z","updated_at":"2026-01-15T04:12:52.593Z","avatar_url":"https://github.com/x3p0-dev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# X3P0: Framework\n\n![Nova, a blue alien, as a construction worker wearing a toolbelt and holding a wrench in a city construction zone.](https://repository-images.githubusercontent.com/1098370533/fc172954-cd4e-4669-be63-ef92774fcbbf)\n\nA lightweight, modern dependency injection framework for WordPress plugins and themes. Built with PHP 8.1+, it provides a robust DI container and abstract application layer to help you write cleaner, more maintainable WordPress code.\n\n[![License](https://img.shields.io/badge/license-GPL--2.0--or--later-blue.svg)](LICENSE.md)\n[![PHP Version](https://img.shields.io/badge/php-%3E%3D8.1-8892BF.svg)](https://php.net)\n\n## Features\n\n- **Modern Dependency Injection Container**: Manage your application's dependencies with ease\n- **Service Providers**: Organize your code with a clean, modular architecture\n- **Singleton and Transient Services**: Full control over service lifetimes\n- **WordPress-Optimized**: Built specifically for WordPress hooks and architecture\n- **Bootable Services**: Optional boot process for service initialization\n- **Lightweight**: Minimal overhead with maximum flexibility\n- **Type-Safe**: Full PHP 8.1+ type declarations for better IDE support\n\n## Requirements\n\n- PHP 8.1 or higher\n- WordPress (recommended latest version)\n- Composer\n\n## Installation\n\nInstall via Composer:\n\n```bash\ncomposer require x3p0-dev/x3p0-framework\n```\n\n**Important:** If you're releasing this as part of a theme or plugin bundle, please vendor prefix your installation to avoid conflicts with other plugins/themes.\n\n## Quick Start\n\n### 1. Create Your Services\n\nFirst, define the services your application needs:\n\n```php\n\u003c?php\nnamespace Your\\Project;\n\nclass ServiceA implements ServiceAInterface\n{\n\tpublic function doSomething(): void\n\t{\n\t\t// Your implementation\n\t}\n}\n\nclass ServiceB\n{\n\tpublic function __construct(\n\t\tprivate ServiceAInterface $serviceA\n\t) {}\n\n\tpublic function boot(): void\n\t{\n\t\t// Bootstrap code\n\t}\n}\n```\n\n### 2. Registers Services via a Service Provider\n\nExtend the `ServiceProvider` base class to register your services:\n\n```php\n\u003c?php\nnamespace Your\\Project;\n\nuse X3P0\\Framework\\Contracts\\Bootable;\nuse X3P0\\Framework\\Core\\ServiceProvider;\n\nfinal class YourServiceProvider extends ServiceProvider implements Bootable\n{\n\tpublic function register(): void\n\t{\n\t\t// Register an abstract/interface with a concrete implementation.\n\t\t// `transient()` creates a new instance each time.\n\t\t$this-\u003econtainer-\u003etransient(\n\t\t\tServiceAInterface::class,\n\t\t\tServiceA::class\n\t\t);\n\n\t\t// Register a concrete implementation.\n\t\t// `singleton()` creates a single instance and reuses it.\n\t\t$this-\u003econtainer-\u003esingleton(ServiceB::class);\n\t}\n\n\t// Implementing `Bootable` is optional but useful for bootstrapping.\n\tpublic function boot(): void\n\t{\n\t\t$this-\u003econtainer-\u003eget(ServiceB::class)-\u003eboot();\n\t}\n}\n```\n\n### 3. Create Your Application\n\nExtend the `Application` base class to define your plugin/theme configuration:\n\n```php\n\u003c?php\nnamespace Your\\Project;\n\nuse X3P0\\Framework\\Core\\Application;\n\nfinal class Plugin extends Application\n{\n\t/**\n\t * Defines the plugin's namespace, used as a hook prefix.\n\t */\n\tprotected const NAMESPACE = 'your/plugin';\n\n\t/**\n\t * Defines the plugin's service providers.\n\t */\n\tprotected const PROVIDERS = [\n\t\tYourServiceProvider::class\n\t];\n}\n```\n\n### 4. Bootstrap Your Application\n\nCreate a helper function to access your application instance:\n\n```php\n\u003c?php\nnamespace Your\\Project;\n\nuse X3P0\\Framework\\Container\\ServiceContainer;\nuse X3P0\\Framework\\Core\\Application;\n\nfunction plugin(): Application\n{\n\tstatic $plugin;\n\n\tif (! $plugin instanceof Plugin) {\n\t\t$plugin = new Plugin(new ServiceContainer());\n\t}\n\n\treturn $plugin;\n}\n```\n\n### 5. Initialize in Your Main Plugin File\n\n```php\n\u003c?php\n/**\n * Plugin Name: Your Plugin\n * Plugin URI:  https://example.com\n * Description: Your plugin description\n * Version:\t1.0.0\n * Author:\tYour Name\n */\n\nnamespace Your\\Project;\n\n// Autoload dependencies.\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n// Initialize the plugin.\nadd_action('plugins_loaded', plugin(...), 9999);\n\n// Boot registered services.\nadd_action('plugins_loaded', fn() =\u003e plugin()-\u003eboot(), PHP_INT_MAX);\n```\n\n## Core Concepts\n\n### Service Container\n\nThe service container manages the creation and lifecycle of your application's objects. It supports three binding types:\n\n#### Singleton\n\nCreates a single instance that's reused throughout the application:\n\n```php\n$this-\u003econtainer-\u003esingleton(MyServiceInterface::class, MyService::class);\n```\n\n#### Transient\n\nCreates a new instance each time it's requested:\n\n```php\n$this-\u003econtainer-\u003etransient(MyServiceInterface::class, MyService::class);\n```\n\n#### Instance\n\nRegisters an existing instance with the container, which is reused throughout the application:\n\n```php\n$this-\u003econtainer-\u003einstance('my-custom-instance', new MyCustomInstance());\n```\n\n### Service Providers\n\nService providers are the central place to configure your container bindings. They have two main methods:\n\n- `register()`: Register bindings in the container\n- `boot()`: Execute bootstrapping code (optional, requires implementing `Bootable`)\n\n### The Application Class\n\nThe application class serves as the central hub of your plugin/theme:\n\n- Manages service providers\n- Provides a hook namespace for WordPress integration\n- Orchestrates the boot process\n\n## Advanced Usage\n\n### Accessing Services\n\nRetrieve services from the container:\n\n```php\n$service = plugin()-\u003econtainer()-\u003eget(ServiceA::class);\n```\n\nOr from within a service provider:\n\n```php\n$service = $this-\u003econtainer-\u003eget(ServiceA::class);\n```\n\n### Multiple Service Providers\n\nRegister multiple service providers in your application:\n\n```php\nfinal class App extends Application\n{\n\tprotected const NAMESPACE = 'your/plugin';\n\n\tprotected const PROVIDERS = [\n\t\tCoreServiceProvider::class,\n\t\tAdminServiceProvider::class,\n\t\tFrontendServiceProvider::class,\n\t];\n}\n```\n\n### Constructor Injection\n\nThe container automatically resolves dependencies:\n\n```php\nclass MyService\n{\n\tpublic function __construct(\n\t\tprivate DependencyA $dependencyA,\n\t\tprivate DependencyB $dependencyB\n\t) {}\n}\n\n// The container will automatically inject DependencyA and DependencyB.\n$this-\u003econtainer-\u003esingleton(MyService::class);\n```\n\n## Best Practices\n\n### 1. Keep Service Providers Focused\n\nEach service provider should handle a specific domain or feature:\n\n```php\n// Good\nclass AdminServiceProvider extends ServiceProvider { /* ... */ }\nclass ApiServiceProvider extends ServiceProvider { /* ... */ }\n\n// Avoid\nclass EverythingProvider extends ServiceProvider { /* ... */ }\n```\n\n### 2. Use Interfaces for Flexibility\n\nBind interfaces to implementations for easier testing and flexibility:\n\n```php\n$this-\u003econtainer-\u003esingleton(\n\tCacheInterface::class,\n\tTransientCache::class\n);\n```\n\n### 3. Leverage the Boot Method\n\nUse the service provider's `boot()` method for operations that require all services to be registered:\n\n```php\npublic function boot(): void\n{\n\t// Runs a service's `init()` method.\n\t$this-\u003econtainer-\u003eget(MyService::class)-\u003einit();\n}\n```\n\n### 4. Vendor Prefix When Necessary\n\nIf you're distributing your plugin/theme, consider using a tool like [PHP-Scoper](https://github.com/humbug/php-scoper) to avoid conflicts.\n\n## License\n\nX3P0 Framework is licensed under the [GPL-2.0-or-later](LICENSE.md) license.\n\n## Credits\n\nCreated and maintained by [Justin Tadlock](https://github.com/justintadlock) under the [X3P0](https://github.com/x3p0-dev) umbrella.\n\n## Support\n\n- [GitHub Issues](https://github.com/x3p0-dev/x3p0-framework/issues)\n- [Packagist](https://packagist.org/packages/x3p0-dev/x3p0-framework)\n\n---\n\n**Note:** This framework is designed for modern PHP development. If you need to support older PHP versions, please consider using a different solution or forking this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx3p0-dev%2Fx3p0-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fx3p0-dev%2Fx3p0-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx3p0-dev%2Fx3p0-framework/lists"}