PHPackages                             scriptmancer/kiler - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. scriptmancer/kiler

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

scriptmancer/kiler
==================

A lightweight, attribute-based dependency injection container for PHP

v0.9.8(1y ago)02MITPHPPHP ^8.1

Since May 7Pushed 1y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

Kiler - Dependency Injection Container
======================================

[](#kiler---dependency-injection-container)

[![PHP Version](https://camo.githubusercontent.com/89899a77bdce65fc4c3d3423dfacff9c6461066a0b5354dc18d7721c23ba596e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d626c75652e737667)](https://php.net)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

Kiler is a lightweight, feature-rich dependency injection container for PHP applications. It provides a simple yet powerful way to manage dependencies and services in your application.

Features
--------

[](#features)

- 🚀 Simple and intuitive API
- 🔄 Support for both dynamic and compiled containers
- 🏷️ Service registration with attributes
- 🔌 Interface-based dependency injection
- 🏷️ Service tagging and grouping
- 🔒 Singleton and factory services
- 📦 PSR-11 Compliance &amp; Framework Compatibility

Kiler implements the [PSR-11 Container Interface](https://www.php-fig.org/psr/psr-11/), making it compatible with any library or framework that supports PSR-11 containers. You can use Kiler as a drop-in DI container for custom projects or integrate it with popular frameworks (such as Laravel, Symfony, Slim, etc.) as long as they support PSR-11 or allow custom containers.

- **Service Providers:** Extend `AbstractServiceProvider` for modular service registration and boot logic.
- **Optional Priority &amp; Dependencies:** Providers can optionally override `getPriority()` and `getDependencies()` for advanced initialization order control.
- **No Framework Lock-in:** Kiler does not require any framework-specific code, ensuring portability and reusability.

Installation
------------

[](#installation)

```
composer require scriptmancer/kiler
```

Quick Start
-----------

[](#quick-start)

```
use Scriptmancer\Kiler\Container;
use Scriptmancer\Kiler\Attributes\Service;

// Define a service
#[Service]
class Database
{
    public function __construct(
        private readonly string $dsn = 'mysql:host=localhost;dbname=test'
    ) {}
}

// Get container instance
$container = Container::getInstance();

// Register service
$container->register(Database::class);

// Use service
$db = $container->get(Database::class);
```

Service Registration
--------------------

[](#service-registration)

### Using Attributes

[](#using-attributes)

```
use Scriptmancer\Kiler\Attributes\Service;

#[Service(
    implements: DatabaseInterface::class,
    group: 'database',
    tags: ['storage', 'persistence'],
    singleton: true
)]
class Database implements DatabaseInterface
{
    // ...
}
```

### Manual Registration

[](#manual-registration)

```
$container->register(Database::class, 'db');
$container->registerFactory('db.factory', fn() => new Database());
```

Interface Resolution
--------------------

[](#interface-resolution)

```
interface LoggerInterface
{
    public function log(string $message): void;
}

#[Service(implements: LoggerInterface::class)]
class FileLogger implements LoggerInterface
{
    public function log(string $message): void
    {
        // ...
    }
}

// Resolve interface to implementation
$logger = $container->get(LoggerInterface::class);
```

Service Groups and Tags
-----------------------

[](#service-groups-and-tags)

```
// Register service with group and tags
$container->register(Database::class);

// Get all services in a group
$databaseServices = $container->getServicesByGroup('database');

// Get all services with a tag
$storageServices = $container->getServicesByTag('storage');
```

Compiled Container
------------------

[](#compiled-container)

For production environments, Kiler provides a compiled container that improves performance:

```
use Scriptmancer\Kiler\Container;
use Scriptmancer\Kiler\ContainerCompiler;

// In development
$container = Container::getInstance();
$container->register(Database::class);

// Compile container
$compiler = new ContainerCompiler('/path/to/cache', 'App\\Bootstrap');
$containerPath = $compiler->compile($container);

// In production
$container = new App\Bootstrap\Container();
$db = $container->get(Database::class);
```

Event System
------------

[](#event-system)

Kiler integrates with event systems through the `EventDispatcherInterface`:

```
use Scriptmancer\Kiler\Event\EventDispatcherInterface;

$container->setEventDispatcher($eventDispatcher);
```

Available events:

- `container.service.registered`: Fired when a service is registered
- `container.service.resolved`: Fired when a service is resolved

Service Providers
-----------------

[](#service-providers)

A service provider is a class responsible for registering related services in the container. You can create your own providers by extending the `AbstractServiceProvider` class.

```
use Scriptmancer\Kiler\AbstractServiceProvider;
use Scriptmancer\Kiler\Container;

class MyServiceProvider extends AbstractServiceProvider
{
    public function register(Container $container): void
    {
        // Register your services here
    }
    public function boot(Container $container): void
    {
        // Perform initialization after all services are registered
    }
}

$container->addServiceProvider(new DatabaseServiceProvider());
$container->registerProviders();
```

Best Practices
--------------

[](#best-practices)

1. Use attributes for service configuration
2. Register services in service providers
3. Use interface-based dependency injection
4. Compile container for production
5. Use groups and tags for service organization
6. Keep services stateless when possible

Contributing
------------

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Credits
-------

[](#credits)

Kiler is part of the [Nazım Framework](https://github.com/scriptmancer/nazim) project.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance49

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

374d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e04b6e1ccafee369abcccccf6dd26837ff2715af44482bba02f163d702b2b90e?d=identicon)[gsarigul84](/maintainers/gsarigul84)

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/scriptmancer-kiler/health.svg)

```
[![Health](https://phpackages.com/badges/scriptmancer-kiler/health.svg)](https://phpackages.com/packages/scriptmancer-kiler)
```

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k431.1M7.5k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

705122.9M10.1k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31178.1M2.0k](/packages/illuminate-container)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
