Download the PHP package tueena-lib/dependency-injection without Composer

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

tueena-lib/dependency-injection

This package provides two classes to realize dependency injection for php 7 applications.

You register services to a service locator by telling the service locator the interface name that identifies the service within the service locator and either the name of the class that will be instantiated to create the service or a factory method (a closure) that will return the service instance.

Other services that are required by the constructor or factory method of the service are injected automatically.

All services are only build on demand and only once.

The second class of the library is a static Injector class. It provides methods to inject services into constructors, methods, static methods, closures, functions and invoke methods.

Features and design decisions

Usage

Register services to the ServiceLocator:

Use the injector to inject services into all kind of callables.

In practice, you will not have to deal with the ServiceLocator or the Injector very much in your application. In fact, you don't want to.

Here an example use case: Let's say you have all the application agnostic business logic in classes in a namespace myApp\core. Now you have several applications that uses that core: A REST API, an administration tool, some command line tools. Let's say, the REST API requires an OrderInteractor. It manages order entities and requires an object, that knows how to persist orders somewhere.

You could write a script core/init.php, that returns a service locator:

You'll import that into your application:

As you can see, you're not going to deal with database connection within the applications. But, you can use the database anyways to store application specific data.

Now your REST API controller could look like this:

The OrderInteractor could look something like that:

As you can see, all the stuff that binds your code to tueena-lib is placed in one file per module. In a bootstrap file at the entry point of the module or the front controller. All the other files and classes are absolutely independent of tueena-lib. No annotations, no calls to Injector, no global service locator instance.

Best practices and notes

License

MIT

Requirements

php >= 7.0.0

Installation

If you use Composer:

Otherwise just download the two classes and the interface and use it.

Contact

Bastian Fenske [email protected]


All versions of dependency-injection with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 tueena-lib/dependency-injection contains the following files

Loading the files please wait ....