{"id":25799322,"url":"https://github.com/derafu/kernel","last_synced_at":"2025-06-22T01:34:08.189Z","repository":{"id":278123607,"uuid":"934596220","full_name":"derafu/kernel","owner":"derafu","description":"Lightweight Kernel Implementation with DI Container","archived":false,"fork":false,"pushed_at":"2025-05-09T18:50:08.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-09T07:57:02.915Z","etag":null,"topics":["dependency-injection","kernel","php"],"latest_commit_sha":null,"homepage":"https://derafu.org/kernel","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/derafu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2025-02-18T05:04:36.000Z","updated_at":"2025-05-09T18:50:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"ae00ef69-a6cc-421c-bbdf-c38765a852a6","html_url":"https://github.com/derafu/kernel","commit_stats":null,"previous_names":["derafu/kernel"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/derafu/kernel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derafu%2Fkernel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derafu%2Fkernel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derafu%2Fkernel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derafu%2Fkernel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/derafu","download_url":"https://codeload.github.com/derafu/kernel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derafu%2Fkernel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261220293,"owners_count":23126726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["dependency-injection","kernel","php"],"created_at":"2025-02-27T15:42:31.953Z","updated_at":"2025-06-22T01:34:03.146Z","avatar_url":"https://github.com/derafu.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Derafu: Kernel - Lightweight Kernel Implementation with Container\n\n[![CI Workflow](https://github.com/derafu/kernel/actions/workflows/ci.yml/badge.svg?branch=main\u0026event=push)](https://github.com/derafu/kernel/actions/workflows/ci.yml?query=branch%3Amain)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nA lightweight kernel implementation with a dependency injection container, inspired by Symfony but with a minimal approach.\n\n## Overview\n\nDerafu Kernel provides a clean, flexible foundation for PHP applications with minimal dependencies. It offers:\n\n- A lightweight kernel implementation with DI container.\n- Environment-aware configuration management.\n- Support for PHP and YAML configuration files.\n- Container caching for improved performance.\n- Built-in support for multiple environments (dev, prod, test, etc.).\n\n## Installation\n\n```bash\ncomposer require derafu/kernel\n```\n\n## Basic Usage\n\n### Create a Kernel\n\nThe simplest way to use the kernel is to create an instance with a specific environment:\n\n```php\nuse Derafu\\Kernel\\MicroKernel;\n\n// Create a kernel with 'dev' environment and debug mode enabled.\n$kernel = new MicroKernel('dev', true);\n\n// Boot the kernel to initialize the container.\n$kernel-\u003eboot();\n```\n\n### Custom Kernel Implementation\n\nYou can extend the `MicroKernel` class to customize its behavior:\n\n```php\nuse Derafu\\Kernel\\MicroKernel;\nuse Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ContainerConfigurator;\n\nclass AppKernel extends MicroKernel\n{\n    // Override the default configuration files.\n    protected const CONFIG_FILES = [\n        'services.php' =\u003e 'php',\n        'routes.php' =\u003e 'routes',\n        'parameters.yaml' =\u003e 'yaml',\n    ];\n\n    // Add additional container configuration.\n    protected function configure(ContainerConfigurator $configurator): void\n    {\n        $services = $configurator-\u003eservices();\n\n        // Register application services.\n        $services-\u003eset('app.service', MyService::class)\n            -\u003epublic()\n            -\u003eargs(['param1', 'param2']);\n    }\n}\n```\n\n### Environment Configuration\n\nThe kernel uses an environment object to determine settings and directories:\n\n```php\nuse Derafu\\Kernel\\Environment;\n\n// Create an environment with custom settings.\n$environment = new Environment(\n    'prod',                 // Environment name.\n    false,                  // Debug mode.\n    ['custom' =\u003e 'value']   // Context variables.\n);\n\n// Create a kernel with the custom environment.\n$kernel = new MicroKernel($environment);\n```\n\n## Configuration\n\n### Directory Structure\n\nThe kernel expects a `config` directory for configurations. Any other structure is free.\n\n### Service Configuration\n\nDefine services in `config/services.php`:\n\n```php\nuse Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ContainerConfigurator;\n\nreturn static function (ContainerConfigurator $configurator) {\n    $services = $configurator-\u003eservices();\n\n    // Auto-configure and autowire services by default.\n    $services-\u003edefaults()\n        -\u003eautowire()\n        -\u003eautoconfigure();\n\n    // Register a single service.\n    $services-\u003eset('app.service', AppService::class)\n        -\u003epublic();\n\n    // Register multiple services from namespace.\n    $services-\u003eload('App\\\\Service\\\\', '../src/Service/*')\n        -\u003epublic();\n};\n```\n\n### Route Configuration\n\nDefine routes in `config/routes.php` or `config/routes.yaml`:\n\n```php\n// routes.php\nreturn [\n    'home' =\u003e [\n        'path' =\u003e '/',\n        'controller' =\u003e 'App\\\\Controller\\\\HomeController::index',\n    ],\n    'blog_show' =\u003e [\n        'path' =\u003e '/blog/{slug}',\n        'controller' =\u003e 'App\\\\Controller\\\\BlogController::show',\n        'parameters' =\u003e [\n            'requirements' =\u003e [\n                'slug' =\u003e '[a-z0-9-]+',\n            ],\n        ],\n    ],\n];\n```\n\nOr in YAML:\n\n```yaml\n# routes.yaml\nhome:\n    path: /\n    controller: App\\Controller\\HomeController::index\n\nblog_show:\n    path: /blog/{slug}\n    controller: App\\Controller\\BlogController::show\n    parameters:\n        requirements:\n            slug: '[a-z0-9-]+'\n```\n\n## Environment Types\n\nThe kernel supports multiple environment types through constants in `EnvironmentInterface`:\n\n- `LOCAL`: Local development environment.\n- `DEVELOPMENT`: Development environment.\n- `TEST`: Testing environment.\n- `STAGING`: Staging environment.\n- `QUALITY_ASSURANCE`: QA environment.\n- `PREPRODUCTION`: Pre-production environment.\n- `PRODUCTION`: Production environment.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\nThis package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n\n---\n\nHappy coding! ✨\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderafu%2Fkernel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderafu%2Fkernel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderafu%2Fkernel/lists"}