Download the PHP package flyokai/amphp-injector without Composer

On this page you can find all versions of the php package flyokai/amphp-injector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package amphp-injector

flyokai/amphp-injector

User docs → AGENTS.md

A dependency injection container for PHP 8.1+ with weaver-based parameter resolution, ordered compositions, attribute-driven wiring, and lifecycle management.

flyokai/amphp-injector is a substantially-evolved descendant of amphp/injector. The container is now driven by weavers (composable parameter resolvers), built around an immutable Application that owns a Container and an Injector, with first-class support for Composition collections, PHP 8 attributes, lifecycle hooks, and alias resolution.

Heads up. Despite the package name and namespace, this is a fork. If you arrived here looking for upstream amphp/injector's Injector::make(), define(), share(), delegate() API — that API is gone. Read on for what replaced it.

Features

Installation

The package's composer.json replaces amphp/injector so the namespace Amp\Injector\… resolves to this fork.

Quick start

Build flow

  1. Create a Definitions collection containing service / object / value / factory / composition definitions.
  2. Create an Injector with a root Weaver (typically any(...) chaining several weavers).
  3. Construct Application(injector, definitions, name, ?aliasResolver).
  4. The Application calls definition->build($injector) for every definition and registers providers in the Container.
  5. application->start() walks the providers and starts every Lifecycle instance in dependency order.
  6. $container->get($id) retrieves services.
  7. application->stop() stops in reverse order.

Definition helpers

singleton(Definition, mustStart = false)

Wraps any definition to cache the instance — subsequent get() calls return the same object. mustStart=true requires the service to be started before first get().

object(string $class, ?Arguments $arguments = null)

Prototype factory — creates a new instance via constructor reflection every call. Wrap in singleton() for sharing.

value(mixed $value)

Wraps a literal — no construction logic.

factory(\Closure $factory, ?Arguments $arguments = null)

Prototype factory from a closure. The closure can accept a ProviderContext to inspect the injection site:

injectableFactory(string $class, ?\Closure $factory = null, ?Arguments $arguments = null)

Returns a callable from the container, not an instance. Some parameters are pre-injected; remaining ones are passed at call time:

compositionFactory(\Closure $factory, ?Definitions $itemDefinitions = null, ?Arguments $arguments = null)

Creates a composition — a collection of items built from sub-definitions. The factory receives all items as named arguments.

compositionItem(Definition $definition, array $before = [], array $after = [], array $depends = [])

Wraps a definition as a CompositionItem for use inside CompositionOrdered:

Weavers

Weavers resolve constructor / function parameters to definitions. They're chained inside Arguments — first match wins.

names(array $definitions = [])

Resolves by parameter name — the most common weaver:

types(array $definitions = [])

Resolves by parameter type — explicit class → definition mapping. Also indexes parent classes / interfaces.

runtimeTypes(Definitions $defs, AliasResolver $aliasResolver)

Resolves via PHP 8 attributes on parameters. Supported attributes:

Attribute Resolves to
#[ServiceParameter] shared singleton instance of the parameter's type
#[SharedParameter] shared instance scoped to the current definition
#[PrivateParameter] new instance per injection site
#[FactoryParameter(Class::class)] injectable factory (callable) returning a Class instance

automaticTypes(Definitions $defs, AliasResolver $aliasResolver)

Auto-wires by type from all registered definitions. Returns a definition only if exactly one matches the type — ambiguous matches return null.

any(Weaver ...$weavers)

Tries multiple weavers in order, returns the first match. Typical setup:

Alias resolution

Maps interfaces to implementations via AliasResolverImpl. Aliases are one-way — requesting Foo yields FooImpl, but requesting FooImpl directly resolves through FooImpl's own definition.

Compositions (ordered collections)

CompositionOrdered items get topologically sorted via before / after / depends:

CompositionImpl is the simple unordered variant. Use selfFactory() as the factory closure for both.

Lifecycle

Services implementing Lifecycle are managed by the application:

Lazy proxies

Pluggable via custom Definitions using ocramius/proxy-manager. See examples/proxy.php:

The built-in ProxyDefinition currently throws not supported yet — provide your own Definition subclass.

Examples

The examples/ directory contains runnable scripts for every feature:

File Demonstrates
singleton.php Basic singleton + value definitions
runtime.php Attribute-driven runtime types + compositions
delegation.php Factories and injectableFactory
logger.php ProviderContext for site-aware factories
proxy.php Lazy-loading proxy definitions
benchmark.php Performance harness

Gotchas

Differences from upstream amphp/injector

Upstream This fork
Injector::make(), define(), share(), delegate(), prepare() gone — replaced by Application + Definitions + weavers
define() arrays arguments(names()->with(...))
share() singleton(...)
alias() (Injector method) AliasResolverImpl (separate object)
Per-injector instance API Immutable Application / Container / Definitions
No compositions Composition, CompositionOrdered, CompositionItem first-class
No attribute-driven wiring #[ServiceParameter], #[SharedParameter], #[PrivateParameter], #[FactoryParameter]
No formal lifecycle Lifecycle::start() / stop() walked in dependency order

See also

License

MIT


All versions of amphp-injector with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
psr/container Version ^1.1 | ^2
marcj/topsort Version ^2.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package flyokai/amphp-injector contains the following files

Loading the files please wait ...