Download the PHP package aatis/dependency-injection without Composer

On this page you can find all versions of the php package aatis/dependency-injection. 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 dependency-injection

Aatis Dependency Injection

Installation

Dependencies

Usage

Requirements

Set the environment variable APP_ENV to the name of the environment you want to use.

Create the container builder with the context of your app ($_SERVER).

Exclude files

Precise the files that are not services.

Service config

You can manage in which environment your service must be loaded and the arguments to pass to the constructor.

Finally, you can give extra tags to any service.

[!NOTE] The key of an argument must have the same name as in the constructor

[!NOTE] Tags have priority set to 0 by default. You can set it to any number you want. Services will be sorted by highest priority first when the Container return multiple services.

[!NOTE] It is also possible to define a configuration for an abstract class. This configuration will be used for all the services extending this class, and will be merged with the configuration of the service itself if provided.

Interface into constructor

When an interface is requested into the constructor of a service, the Container will try to find a service implementing this interface into your app.

[!NOTE] If multiple services implement the interface, the Container will pick the one with the highest priority. If many services implementing the interface share the highest priority, the Container will priorise an already instancied service. Otherwise, it will pick the first one found.

If you want to use a specific service, don't forget to declare it into the configuration of the service.

[!WARNING] If your want to use a specific service of the vendor, do the previous step and precise it into the includes_services part of the config.

Env variable into constructor

You can request for a env variable directly into the constructor of a service.

[!NOTE] The name of the variable must start with $_ and be followed by the env variable name in lowercase.

Container uses

Get and Set

With the container, you can get and set any service / env variable (prefixed by @_) you want with the methods get() and set().

However, to set a service, you must give an instance of the Service class. You can create it with the ServiceFactory service.

Get by tag

You can get services by tag using the ServiceTagBuilder:

Get by interface

You can easily get services implementing an interface using ServiceTagBuilder with the buildFromInterface() method.

Get single service

You can get the Service of a single service using ServiceTagOption::FROM_CLASS and ServiceTagOption::SERVICE_TARGETED options.

AsDefaultTaggedService

As said before, the priority of a tag is set to 0 by default, but when attaching the attribute AsDefaultTaggedService to a service, you can set the priority to some or all of his tags to 1.

[!NOTE] If you set the priority of the service into the config, it will override the one set by this attribute.

Service Subscription

The service subscription feature allows a service to declaratively specify which other services it wants to use. This approach allow a service to retrieve and instanciate others conditionally.

Principle

A subscriber service must implement the ServiceSubscriberInterface and define the static getSubscribedServices() method. This method returns a list of tags identifying the services to subscribe.

[!NOTE] The $container will not provide a Container but a ServiceStack which is a restricted version of the container that only allows access to the services defined in getSubscribedServices().

ServiceSubscriberTrait

To simplify implementation, you can use the ServiceSubscriberTrait which provides a builtin provide() method to retrieve and filter subscribed services.

Trait Configuration

The trait uses PHP templates for better type integration. You can specify the types of input and output services, as well as the context used for filtering.

provide(array $ctx): array

Retrieve all subscribed services and filters them according to the provided context. It returns an array of services that match the criteria.

pick(mixed $service, array $ctx): bool (protected)

Filtering method to define which services should be selected according to the context.

[!NOTE] By default this method returns true, meaning all services are selected.

transformOut(mixed $service, array $ctx): mixed (protected)

Transformation method to modify services before returning them.

[!NOTE] By default this method returns the service as is.

ServiceFactory

You can use the ServiceFactory service to create a service instance.

[!CAUTION] If the package is properly configured, you should not need to use this service.

ServiceInstanciator

You can use the ServiceInstanciator service and the setInstance() method of the Service class to instanciate a service into the container.

You can choose between two methods to instanciate a service. For the first one, you must inform the arguments to pass to the constructor into the config. For the second one, you must create the instance yourself.

[!CAUTION] If the package is properly configured, you should not need to use this service.


All versions of dependency-injection with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
aatis/tag Version ^1.0
aatis/parameter-bag Version ^1.0
symfony/yaml Version ^6.3
psr/container Version ^1.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 aatis/dependency-injection contains the following files

Loading the files please wait ....