Download the PHP package bluepsyduck/zend-autowire-factory without Composer

On this page you can find all versions of the php package bluepsyduck/zend-autowire-factory. 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 zend-autowire-factory

Zend Auto-Wire Factory

GitHub release (latest SemVer) Codecov

DEPRECATED: Use package bluepsyduck/laminas-autowire-factory instead.

bluepsyduck/laminas-autowire-factory contains the same functionality as this package, with the only difference being the namespace. Except for the imports no changes are required.


This library provides few factories helping with auto-wiring service classes to make writing actual factories less common.

AutoWireFactory

The AutoWireFactory uses reflection on the constructor of the actual service class to determine how to resolve the dependencies and creating the actual service. The factory is adopting Symfony's approach of handling auto wiring, especially dealing with multiple implementations of the same type.

Resolving strategies

The factory uses the following strategies to resolve a parameter of the constructor, depending on how it is type-hinted. The first alias available in the container will be used to resolve the dependency. If no alias is available, an exception gets triggered.

Each parameter is resolved on its own, so they can be combined in any way.

Parameter with class type-hint

Example:

If the parameter has a class name as type-hint, then the following aliases are checked in the container:

  1. FancyClass $fancy: The combination of class name and parameter name. This allows for multiple implementations of the same interface as stated in the Symphony documentation.
  2. FancyClass: "Default" case of registering a class with its name to the container.
  3. $fancy: Fallback of using the parameter name alone, mostly to make the aliases uniform between cases.

The first alias which can be provided by the container will be used.

Parameter with scalar type-hint

Example:

If the parameter is type-hinted with a scalar type, e.g. to pull config values into the service, the following aliases are checked:

  1. array $fancyConfig: The combination of type and parameter name, the same as for class type-hints.
  2. $fancyConfig: Fallback using only the parameter name.

Note that the type alone, array, is not used as alias.

Parameter without type-hint

Example:

In this case, only one alias can be checked due to missing information:

  1. $fancyParameter: Fallback is the only possible alias.

AutoWireFactory as AbstractFactory

Next to the FactoryInterface to use the AutoWireFactoryas an explicit factory in the container configuration, it also implements the AbstractFactoryInterface: If you add this factory as an abstract factory, it will try to auto-wire everything it can. This will make configuring the container mostly obsolete, with the exception of parameters using scalar values or multiple implementations (where the parameter name is part of the container alias).

Caching

The AutoWireFactory uses reflections to resolve dependencies. To make things faster, the factory offers building up a cache on the filesystem to avoid using reflections on each script call. To enable the cache, add the following line e.g. in the config/container.php file:

ConfigReaderFactory

To help further with making self-written factories obsolete, the ConfigReaderFactory is able to provide values from the application config to the container to be e.g. used together with auto-wiring.

Usage

The ConfigReaderFactory requires the application config to be added as array to the container. If the alias for the config differs from the default "config", call ConfigReaderFactory::setConfigAlias('yourAlias') to set the alias.

Then, use the readConfig(string ...$keys) function (or new ConfigReaderFactory(string ...$keys)) to read a config value for the container, where $keys are the array keys to reach your desired value in the config. Note that if a key is not set, an exception will be triggered by the factory.

AliasArrayInjectorFactory

The AliasArrayInjectorFactory reads an array of aliases from the config (using the ConfigReaderFactory), and creates all instances to these aliases and returns them to be injected into other services. All aliases must be known to the container.

To use this factory, simply call injectAliasArray(string ...$configKeys) (or new AliasArrayInjectorFactory(string ...$configKeys)) within the container config.

Example

The following example should show how to use both the AutoWireFactory and the ConfigReaderFactory to auto-wire a service class.

Let's assume we have the following application config from which we want to take a value:

We want to auto-wire the following service class:

The following configuration can be used for the container without writing any factories:

This configuration can be made even shorter if we use the AutoWireFactory as an abstract factory:

Of course it is always possible to add a concrete factory to any service if auto-wiring is not possible due to more complex initialization requirements.


All versions of zend-autowire-factory with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
zendframework/zend-servicemanager Version ^3.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 bluepsyduck/zend-autowire-factory contains the following files

Loading the files please wait ....