Download the PHP package ob-ivan/sd-dependency-injection without Composer

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

Registers services and injects them into consumers.

Installation

Usage

Terminology

In large applications a situation when some class instances are to be shared among many other classes is common. Think of a database connection instance shared among various controller classes.

Those shared classes are called services (they provide some useful functionality to others), and those sharing are called consumers (they consume the services provided).

The process of letting a consumer know all services it requires access to is called injection.

A consumer may declare formally a list of services it requires. This is called listing its dependencies. The process of taking a consumer's dependency list and injecting corresponging services into it is called, unsurprisingly, dependency injection.

A dependency injection container (DIC) is a way to implement dependency injection. It requires that each service is registered within the container under a certain common name, and that consumers list common names of their required services as formal dependency lists.

Dependecies may be injected into consumers in several different ways. In this library, these three types of dependency injection are supported:

You can use a container to register services, or to produce consumers, or to inject dependencies into arbitrary code.

Construction

A container is initialized with raw values, no Initalizers allowed:

If you have several containers, you can create a new one by merging them:

Registering services

Services are registered with ServiceInitializers:

You do not have to register container within itself, as it is self-aware by default:

You can extend registered services:

Consumer production

Consumers are produced with ConsumerInitializers (Value is not supported):

You can inject services into any Consumer:

Though discouraged, you can use container as service locator, if execution context does not let you use the power of dependency injection:

Defining a consumer

Class consumers (as opposed to callable consumers) declare their dependencies in any of following ways --- or a combination of both:

As listing common names in declareDependencies method causes heavy reduplication of common names, we recommend to define an AwareTrait for each service you define.

Here's a sample code:

This way defining a consumer in a following way will tell a container to inject ExampleService into it --- or to throw an exception if it's not available.

Service providers

You can encapsulate a service's common name further by putting it into a provider.

Then the service is registered with its provider's instance:

This way neither registration code nor consumers need to know the common name. They just refer to Provider instance and the AwareTrait, and it just works. Hey, it's magic!

Development

To run tests:


All versions of sd-dependency-injection with dependencies

PHP Build Version
Package Version
No informations.
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 ob-ivan/sd-dependency-injection contains the following files

Loading the files please wait ....