Download the PHP package dakujem/wire-genie without Composer

On this page you can find all versions of the php package dakujem/wire-genie. 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 wire-genie

Wire Genie 🧞

Tests Coverage Status

Autowiring Tool & Dependency Provider for PSR-11 service containers. Wire with genie powers.

💿 composer require dakujem/wire-genie

📒 Changelog

What?

A superpowered call_user_func? Yup! And more.

Wire Genie uses your PSR-11 service container to "magically" provide arguments (dependencies).

Allows you to:

... with high level of control over the arguments. 💪

Usage

That is only the basis, the process is customizable and more powerful.

For each parameter it is possible to:

How it works

There are two primary methods:

... where the variadic $pool is a list of values that will be used for unresolvable parameters.

The resolution algorithm works like the following. If any step succeeds, the rest is skipped.\ For each parameter...

  1. If the parameter name matches a named argument from the pool, use it.
  2. If #[Skip] hint is present, skip steps 3-6 and treat the parameter as unresolvable.
  3. If a #[Wire(Identifier::class)] hint (attribute) is present, resolve the hinted identifier using the container.
  4. Resolve the type-hinted identifier using the container.
  5. If #[Hot] hint is present, attempt to create the type-hinted class. Resolve cascading dependencies.
  6. If #[Make(Name::class)] hint is present, attempt to create the hinted class. Resolve cascading dependencies.
  7. When a parameter is unresolvable, try filling in an argument from the pool.
  8. If a default parameter value is defined, use it.
  9. If the parameter is nullable, use null.
  10. Fail utterly.

Hints / attributes

As you can see, the algorithm uses native attributes as hints to control the wiring.

#[Wire(Identifier::class)] tells Genie to try to wire the service registered as Identifier from the container\ #[Wire('identifier')] tells Genie to try to wire service with 'identifier' identifier from the container\ #[Hot] tells Genie to try to create the type-hinted class (works with union types too) \ #[Make(Service::class, 42, 'argument')] tells Genie to try to create Service class using 42 and 'argument' as the argument pool for the construction \ #Skip tells Genie not to use the container at all

Hot and Make work recursively, their constructor dependencies will be resolved from the container or created on the fly too.

What can it be used for?

Examples

A word of caution

Fetching services from the service container on-the-fly might solve an edge case in certain implementations where dependency injection boilerplate can not be avoided or reduced in a different way.

It is also the only way to invoke callables with dependencies not known at the time of compilation.

Normally, however, you want to wire your dependencies when building your app's service container.

Disclaimer 🤚

Improper use of this package might break established IoC principles and degrade your dependency injection container to a service locator, so use the package with caution.

Remember, it is always better to inject a service into a working class, then to fetch the service from within the working class (this is called "Inversion of Control", "IoC").

Integration

As with many other third-party libraries, you should consider wrapping code using Wire Genie into a helper class with methods like the following one:

This adds a tiny layer for flexibility, in case you decide to tweak the way you wire dependencies later on.

Static provisioning

Genie::provide() can be used to provision a callable with a fixed list of services without using reflection.

Limiting access to services

You can limit the services accessible through Genie by using a filtering proxy Limiter:

The proxy uses the instanceof type operator and throws if the requested service does not match at least one of the whitelisted classes or interface names.

Customization

A custom strategy can be inserted into Genie, and the default AttributeBasedStrategy allows for customization of the resolver mechanism, thus providing ultimate configurability.

Compatibility

Framework agnostic. Any PSR-11 container can be used.

Wonderful lamp

Flying carpet

We've already got a lamp 🪔 and a genie 🧞 ... so?

Installation

💿 composer require dakujem/wire-genie

Never heard of Composer? Go get it!

Testing

Run unit tests using the following command:

$ composer test\ or\ $ php vendor/phpunit/phpunit/phpunit tests

Contributing

Ideas, feature requests and other contribution is welcome. Please send a PR or create an issue.


Now go, do some wiring!


All versions of wire-genie with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
psr/container Version ^1
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 dakujem/wire-genie contains the following files

Loading the files please wait ....