PHPackages                             ioc-interop/interface - 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. ioc-interop/interface

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

ioc-interop/interface
=====================

Interoperable IOC container interfaces for PHP.

1.x-dev(1mo ago)11.9k12MITPHPPHP &gt;=8.4CI passing

Since Feb 3Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/ioc-interop/interface)[ Packagist](https://packagist.org/packages/ioc-interop/interface)[ RSS](/packages/ioc-interop-interface/feed)WikiDiscussions 1.x Synced today

READMEChangelog (2)Dependencies (5)Versions (2)Used By (2)

Ioc-Interop Standard Interface Package
======================================

[](#ioc-interop-standard-interface-package)

[![PDS Skeleton](https://camo.githubusercontent.com/50d01a5094afcc3a827c3cadaec43d23b2a256cb249f5fdd6e5ffdb53ea7971c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7064732d736b656c65746f6e2d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/php-pds/skeleton)[![PDS Composer Script Names](https://camo.githubusercontent.com/0c17df07fd0a51ad878f1de0d4c17ea8e460f2e96ce796c8cd58e6c96ed9c08d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7064732d636f6d706f7365722d2d7363726970742d2d6e616d65732d626c75653f7374796c653d666c61742d737175617265)](https://github.com/php-pds/composer-script-names)

Ioc-Interop provides an interoperable package of standard interfaces for inversion-of-control (IOC) service container functionality. It reflects, refines, and reconciles the common practices identified within [several pre-existing projects](./README-RESEARCH.md).

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [BCP 14](https://datatracker.ietf.org/doc/bcp14/) ([RFC 2119](https://datatracker.ietf.org/doc/html/rfc2119), [RFC 8174](https://datatracker.ietf.org/doc/html/rfc8174)).

This package attempts to adhere to the [Package Development Standards](https://php-pds.com/) approach to [naming and versioning](https://php-pds.com/#naming-and-versioning).

Interfaces
----------

[](#interfaces)

This package defines the following interfaces:

- [*IocContainer*](#ioccontainer) affords obtaining services by name.
- [*IocContainerFactory*](#ioccontainerfactory) affords obtaining a new instance of [*IocContainer*](#ioccontainer).
- [*IocThrowable*](#iocthrowable) extends [*Throwable*](https://php.net/Throwable) to mark an [*Exception*](https://php.net/Exception) as IOC-related.
- [*IocTypeAliases*](#ioctypealiases) provides custom PHPStan types to aid static analysis.

### *IocContainer*

[](#ioccontainer)

[*IocContainer*](#ioccontainer) affords obtaining services by name.

- Notes:

    - **This interface does not afford service management.** The container will need to obtain services somehow, e.g. from a [Service-Interop](https://github.com/service-interop/interface)implementation.

#### *IocContainer* Methods

[](#ioccontainer-methods)

- ```
    public function hasService(ioc_service_name_string $serviceName) : bool;
    ```

    - Is the container able to return an instance of the `$serviceName`?
    - Notes:

        - **The logic for this method is expressly unspecified.** The ability check may be accomplished by querying a service management subsystem, or by some other means.
- ```
    public function getService(
        ioc_service_name_string $serviceName,
    ) : ioc_service_object;
    ```

    - Returns an instance of the `$serviceName`.
    - Directives:

        - Implementations MUST throw [*IocThrowable*](#iocthrowable) if the container cannot return an instance of the `$serviceName`.
    - Notes:

        - **The logic for this method is expressly unspecified.** Retrieval may be accomplished via a service management subsystem, or by some other means.
        - **The returned instance may be new or shared.** The retrieval logic defines the service lifetime, not the container (per se) and not the caller requesting the service.

### *IocContainerFactory*

[](#ioccontainerfactory)

[*IocContainerFactory*](#ioccontainerfactory) affords obtaining a new instance of [*IocContainer*](#ioccontainer).

#### *IocContainerFactory* Methods

[](#ioccontainerfactory-methods)

- ```
    public function newContainer() : IocContainer;
    ```

    - Returns a new instance of [*IocContainer*](#ioccontainer).
    - Notes:

        - **Container instantiation logic is not specified.** Implementations might use providers, configuration files, attribute or annotation collection, or some other means to create and populate a container. Implementations might also choose to return a compiled or otherwise reconstituted container.

### *IocThrowable*

[](#iocthrowable)

[*IocThrowable*](#iocthrowable) extends [*Throwable*](https://php.net/Throwable) to mark an [*Exception*](https://php.net/Exception) as IOC-related.

It adds no class members.

### *IocTypeAliases*

[](#ioctypealiases)

[*IocTypeAliases*](#ioctypealiases) provides custom PHPStan types to aid static analysis.

- ```
    ioc_service_name_string class-string|non-empty-string

    ```

    - A `class-string` or `string` name for a service.
- ```
    ioc_service_object ($serviceName is class-string ? T : object)

    ```

    - The service `object` for a given service name.

Implementations
---------------

[](#implementations)

Implementations MAY define additional class members not defined in these interfaces.

Notes:

- **Reference implementations** are available at .

Q &amp; A
---------

[](#q--a)

### How is Ioc-Interop different from PSR-11?

[](#how-is-ioc-interop-different-from-psr-11)

[PSR-11](https://www.php-fig.org/psr/psr-11/) is an earlier recommendation that offers an interface to `get`items from a container, and to see if that container `has` a particular item.

Ioc-Interop is functionally almost identical to PSR-11. However, Ioc-Interop is intended to contain only services (`object`). PSR-11 is intended to contain anything (`mixed`).

Ioc-Interop also offers an [*IocContainerFactory*](#ioccontainerfactory) interface, whereas PSR-11 offers none.

### Is Ioc-Interop compatible with PSR-11?

[](#is-ioc-interop-compatible-with-psr-11)

No, in the sense that the method names, signatures, and intents are different.

Yes, in the sense that both may be implemented on the same class; the method names are different, and so are non-conflicting.

### Why does Ioc-Interop not afford service management?

[](#why-does-ioc-interop-not-afford-service-management)

Ioc-Interop is focused on the concerns around *obtaining* and *consuming*services. The affordances for *managing* and *producing* services are a set of separate concerns.

Earlier drafts of Ioc-Interop were much more expansive, including a resolver subsystem and a service management subsystem. These have been extracted to separate standards, each of which is dependent on Ioc-Interop:

- [Service-Interop](https://github.com/service-interop/interface)
- [Resolver-Interop](https://github.com/resolver-interop/interface)

This separation helps to maintain a boundary between the needs of service consumers (afforded by Ioc-Interop) and service producers (afforded by [Service-Interop](https://github.com/service-interop/interface) and [Resolver-Interop](https://github.com/resolver-interop/interface)).

Note that Ioc-Interop is independent of [Service-Interop](https://github.com/service-interop/interface) and [Resolver-Interop](https://github.com/resolver-interop/interface). Ioc-Interop implementations can use them, or avoid them, as implementors see fit.

### Is [*IocContainer*](#ioccontainer) for Dependency Injection or is it a Service Locator?

[](#is-ioccontainer-for-dependency-injection-or-is-it-a-service-locator)

[*IocContainer*](#ioccontainer) acts a Service Locator only when it is used as a dependency in order to retrieve other dependencies from it.

### Why does [*IocContainer*](#ioccontainer) disallow non-object values?

[](#why-does-ioccontainer-disallow-non-object-values)

[*IocContainer*](#ioccontainer) is explicitly a *service* container, not a general config container for [scalar](https://www.php.net/manual/en/language.types.type-system.php#language.types.type-system.atomic.scalar) or [array](https://www.php.net/manual/en/language.types.array.php) values.

Limiting services to objects helps maintain consistent expectations regarding service types and behavior. Of the researched projects, 10 return `object`, and 8 return `mixed`, so this restriction is consistent with the majority.

Ioc-Interop recognizes that implementors and consumers often want to make config values easily available, though Ioc-Interop questions what it means (or if it is possible) to get a "shared" scalar or array that works the same as a "shared" object.

With that in mind, Ioc-Interop encourages the use of one or more config services or value objects to make those values available, instead of storing config values directly inside a container.

### Why does [*IocContainer*](#ioccontainer) define `getService()` and not just `get()` ?

[](#why-does-ioccontainer-define-getservice-and-not-just-get-)

The vast majority of researched projects, whether PSR-11 conforming or not, use the method name `get()`. Contra the research, Ioc-Interop asserts that `get()`is too generic, and that the method name should hint at what is being gotten; thus, `getService()`.

---

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance88

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 93.2% 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 ~90 days

Total

2

Last Release

59d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25754?v=4)[Paul M. Jones](/maintainers/pmjones)[@pmjones](https://github.com/pmjones)

---

Top Contributors

[![pmjones](https://avatars.githubusercontent.com/u/25754?v=4)](https://github.com/pmjones "pmjones (41 commits)")[![niden](https://avatars.githubusercontent.com/u/1073784?v=4)](https://github.com/niden "niden (3 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ioc-interop-interface/health.svg)

```
[![Health](https://phpackages.com/badges/ioc-interop-interface/health.svg)](https://phpackages.com/packages/ioc-interop-interface)
```

PHPackages © 2026

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