Download the PHP package zalas/injector without Composer

On this page you can find all versions of the php package zalas/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 injector

Injector

Build

Injects services from a PSR-11 dependency injection container into objects. Service information is read from class properties annotated with @inject, but extension points are provided to read them from any source.

Example of a class that default implementation of injector can work with:

Why?

The library is useful in situations when we have no control over how objects are instantiated, so we can't use proper dependency injection. One use case is feeding services from an application container to integration test cases. Test cases are instantiated by a test framework, so it's not possible to provide additional dependencies during construction time. However, since test frameworks usually give ways to hook into the initialization process, it's still possible to provide additional dependencies before test cases are called.

PHPUnit integration is actually implemented in zalas/phpunit-injector (github repository: https://github.com/jakzal/phpunit-injector).

Installation

Usage

Properties should be annotated with @inject in order for them to be recognised by the default injector implementation:

The injector can be used to feed services into properties of an already instantiated object:

Extension points

Zalas\Injector\Service\Injector injects services to objects. Services are provided by a PSR-11 container (Psr\Container\ContainerInterface). Details of services to inject are read with an extractor (Zalas\Injector\Service\Extractor).

Both collaborators are accessed via their factories (Zalas\Injector\Service\ContainerFactory and Zalas\Injector\Service\ExtractorFactory).

The injector provides two extension points:

Container factory

The Zalas\Injector\Factory\DefaultContainerFactory is a default factory implementation that always returns an instance of container created externally.

The Zalas\Injector\Service\ContainerFactory interface needs to be implemented to provide customised way of creating the service container to be used with injector.

Extractor & extractor factory

The default implementation of extractor (Zalas\Injector\Reflection\ReflectionExtractor) leverages PHP's reflection for annotation parsing. It uses the @inject annotation to read service information. The annotation accepts service id as an optional value. Otherwise the type is used. Zalas\Injector\Factory\DefaultExtractorFactory creates this default implementation of extractor.

Implement the Zalas\Injector\Service\Extractor interface to support your own way of extracting definitions of services to inject. A factory that implements the Zalas\Injector\Service\ExtractorFactory will also need to be created to instantiate the custom extractor.

Contributing

Please read the Contributing guide to learn about contributing to this project. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.


All versions of injector with dependencies

PHP Build Version
Package Version
Requires php Version ~8.1.0 || ~8.2.0 || ~8.3.0
psr/container Version ^1.0 || ^2.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 zalas/injector contains the following files

Loading the files please wait ....