PHPackages                             vaibhavpandeyvpz/katora - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. vaibhavpandeyvpz/katora

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

vaibhavpandeyvpz/katora
=======================

Simple service container implementing PSR-11 for PHP &gt;= 8.2.

2.0.0(4mo ago)656512MITPHPPHP ^8.2CI passing

Since Sep 17Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/vaibhavpandeyvpz/katora)[ Packagist](https://packagist.org/packages/vaibhavpandeyvpz/katora)[ Docs](https://github.com/vaibhavpandeyvpz/katora)[ RSS](/packages/vaibhavpandeyvpz-katora/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (4)Used By (2)

Katora
======

[](#katora)

[![Latest Version](https://camo.githubusercontent.com/ec753aed5357e8107d7e4fb1533569d2928965230833bdf6ccbd54c4c2621f34/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7661696268617670616e64657976707a2f6b61746f72612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vaibhavpandeyvpz/katora)[![Downloads](https://camo.githubusercontent.com/9c16c10bee1ba39609880879f18189d49089f58770dd9d7d0f79c4b54ab64d42/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7661696268617670616e64657976707a2f6b61746f72612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vaibhavpandeyvpz/katora)[![PHP Version](https://camo.githubusercontent.com/4f776d2d9337c563ebe1182b908c80cfeb3f1544fb372c5d0d84face99a472b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7661696268617670616e64657976707a2f6b61746f72612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vaibhavpandeyvpz/katora)[![License](https://camo.githubusercontent.com/49fb0fc9975580b5971825d0193cee383949b1cdeba748fb3c166977ff5f7fac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7661696268617670616e64657976707a2f6b61746f72612e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/097fd7bb6f775ae496aef66f0dd5f8cfc22cda4389ea1a154da36ea1bc5d32bc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7661696268617670616e64657976707a2f6b61746f72612f74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/vaibhavpandeyvpz/katora/actions)[![Code Coverage](https://camo.githubusercontent.com/994d68acb2aadf1c3c7711ddcb3b30429246a6c05da9e601f62c3f932ac795a8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/vaibhavpandeyvpz/katora)

Simple, lightweight service container implementing [PSR-11](https://www.php-fig.org/psr/psr-11/) for PHP 8.2+.

> **Katora** (`कटोरा`) means "Bowl" in Hindi - a container that holds things together.

Features
--------

[](#features)

- ✅ **PSR-11 Compliant** - Full implementation of the ContainerInterface standard
- ✅ **Lazy Resolution** - Services defined as callables are resolved only when accessed
- ✅ **Singleton Support** - Built-in `share()` method for singleton pattern
- ✅ **Service Providers** - Modular service registration via providers
- ✅ **Multiple Access Patterns** - Use methods, array access, or property access
- ✅ **Type Safe** - Full PHP 8.2+ type hints and return types
- ✅ **100% Test Coverage** - Comprehensive test suite with full coverage
- ✅ **Zero Dependencies** - Only requires PSR-11 interface (no other dependencies)

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

[](#installation)

Install via Composer:

```
composer require vaibhavpandeyvpz/katora
```

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

[](#quick-start)

```
use Katora\Container;

// Create a container
$container = new Container();

// Register a simple value
$container->set('app.name', 'My Application');

// Register a service with lazy resolution
$container->set('database', fn() => new DatabaseConnection());

// Retrieve services
$appName = $container->get('app.name');
$db = $container->get('database');
```

Usage
-----

[](#usage)

### Basic Operations

[](#basic-operations)

#### Setting Services

[](#setting-services)

```
use Katora\Container;

$container = new Container();

// Simple values
$container->set('config.debug', true);
$container->set('config.timezone', 'UTC');

// Objects
$container->set('logger', new Logger());

// Lazy resolution with closures
$container->set('cache', fn() => new RedisCache());
```

#### Getting Services

[](#getting-services)

```
// Direct method call
$logger = $container->get('logger');

// Check if service exists
if ($container->has('logger')) {
    $logger = $container->get('logger');
}
```

#### Multiple Access Patterns

[](#multiple-access-patterns)

```
// Method access
$container->set('service', 'value');
$value = $container->get('service');

// Array access
$container['service'] = 'value';
$value = $container['service'];

// Property access
$container->service = 'value';
$value = $container->service;
```

### Lazy Service Resolution

[](#lazy-service-resolution)

Services defined as callables are automatically resolved when accessed:

```
$container->set('user.repository', function (ContainerInterface $c) {
    return new UserRepository($c->get('database'));
});

// The closure is only executed when get() is called
$userRepo = $container->get('user.repository');
```

### Singleton Pattern

[](#singleton-pattern)

Use `share()` to ensure a service is resolved only once:

```
$container->set('singleton.service', $container->share(function () {
    return new ExpensiveService();
}));

// First call resolves and caches
$service1 = $container->get('singleton.service');

// Subsequent calls return the cached instance
$service2 = $container->get('singleton.service');
// $service1 === $service2
```

### Raw Callables

[](#raw-callables)

Prevent automatic resolution when you need to store a callable as a value:

```
$container->set('callback', $container->raw(function () {
    return 'This is a callable, not a service';
}));

// Returns the callable itself, not its result
$callback = $container->get('callback');
$result = $callback(); // Call it manually
```

### Service Providers

[](#service-providers)

Organize service registration with providers:

```
use Katora\Container;
use Katora\ServiceProviderInterface;

class DatabaseServiceProvider implements ServiceProviderInterface
{
    public function provide(Container $container): void
    {
        $container->set('database.config', [
            'host' => 'localhost',
            'port' => 3306,
        ]);

        $container->set('database', $container->share(function (ContainerInterface $c) {
            $config = $c->get('database.config');
            return new Database($config);
        }));
    }
}

// Install the provider
$container->install(new DatabaseServiceProvider());
```

### Constructor Initialization

[](#constructor-initialization)

You can pre-populate the container:

```
$container = new Container([
    'app.name' => 'My App',
    'app.version' => '1.0.0',
    'database' => fn() => new Database(),
]);
```

### Method Chaining

[](#method-chaining)

Most methods return `$this` for fluent interfaces:

```
$container
    ->set('service1', 'value1')
    ->set('service2', 'value2')
    ->install(new ServiceProvider())
    ->set('service3', 'value3');
```

### Container-Aware Classes

[](#container-aware-classes)

Use the `HasContainer` trait to make classes container-aware:

```
use Katora\Extra\HasContainer;
use Katora\Extra\KeepsContainer;
use Psr\Container\ContainerInterface;

class MyService implements KeepsContainer
{
    use HasContainer;

    public function doSomething(): void
    {
        $logger = $this->getContainer()->get('logger');
        $logger->info('Doing something');
    }
}

$service = new MyService();
$service->setContainer($container);
```

API Reference
-------------

[](#api-reference)

### Container

[](#container)

#### `__construct(array $entries = [])`

[](#__constructarray-entries--)

Creates a new container instance, optionally with initial entries.

#### `get(string $id): mixed`

[](#getstring-id-mixed)

Retrieves a service from the container. Throws `NotFoundException` if the service doesn't exist.

**Throws:** `NotFoundException`

#### `has(string $id): bool`

[](#hasstring-id-bool)

Checks if a service exists in the container.

#### `set(string $id, mixed $entry): static`

[](#setstring-id-mixed-entry-static)

Registers a service in the container. Returns `$this` for method chaining.

#### `install(ServiceProviderInterface $provider): static`

[](#installserviceproviderinterface-provider-static)

Installs a service provider. Returns `$this` for method chaining.

#### `share(callable $entry): callable`

[](#sharecallable-entry-callable)

Wraps a callable to ensure it's only resolved once (singleton pattern).

#### `raw(callable $entry): callable`

[](#rawcallable-entry-callable)

Wraps a callable to prevent automatic resolution when retrieved.

### Exceptions

[](#exceptions)

#### `ContainerException`

[](#containerexception)

Base exception for container-related errors. Extends `InvalidArgumentException` and implements `ContainerExceptionInterface`.

#### `NotFoundException`

[](#notfoundexception)

Thrown when a requested service is not found. Extends `ContainerException` and implements `NotFoundExceptionInterface`.

### Interfaces

[](#interfaces)

#### `ServiceProviderInterface`

[](#serviceproviderinterface)

Interface for service providers. Implement this to create modular service registration.

**Methods:**

- `provide(Container $container): void` - Registers services with the container

#### `KeepsContainer`

[](#keepscontainer)

Interface for container-aware classes. Use with the `HasContainer` trait.

**Methods:**

- `getContainer(): ?ContainerInterface` - Gets the container instance
- `setContainer(ContainerInterface $container): void` - Sets the container instance

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- PSR-11 Container Interface

Testing
-------

[](#testing)

Run the test suite with PHPUnit:

```
vendor/bin/phpunit
```

With coverage:

```
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text
```

License
-------

[](#license)

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

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Author
------

[](#author)

**Vaibhav Pandey**

- GitHub: [@vaibhavpandeyvpz](https://github.com/vaibhavpandeyvpz)
- Email:

Support
-------

[](#support)

For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/vaibhavpandeyvpz/katora).

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance75

Regular maintenance activity

Popularity19

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~1511 days

Total

3

Last Release

136d ago

Major Versions

1.0.1 → 2.0.02025-12-27

PHP version history (3 changes)1.0PHP ^5.3||^7.0

1.0.1PHP ^5.4||^7.0

2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/4cf0d090043e41bf330d9ef1d0e7e799f1946145ddb3569ba38a003d47929378?d=identicon)[vaibhavpandeyvpz](/maintainers/vaibhavpandeyvpz)

---

Top Contributors

[![vaibhavpandeyvpz](https://avatars.githubusercontent.com/u/6647172?v=4)](https://github.com/vaibhavpandeyvpz "vaibhavpandeyvpz (6 commits)")

---

Tags

containerphppsr-11servicecontainerPSR-11dependency-injectiondiiocservice

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vaibhavpandeyvpz-katora/health.svg)

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)

PHPackages © 2026

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