Download the PHP package sasa-b/container without Composer

On this page you can find all versions of the php package sasa-b/container. 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 container

IOC container

Lightweight dependency injection container with laravel like autowiring, interface/abstract class binding and contextual binding. PSR-11 compliant.


To use the library clone the repo or just use composer to install it.

composer require sasa-b/container

Usage examples

Binding/Registering services

A service (bound value) can be a string representation of a class, an anonymous function which returns an object instance, or an object instance itself. If you bind an object instance itself, that service will essentially act as a singleton because the same instance will always be returned.

Singletons

Mapping services to keys

For convenience you can map your services to keys and there are multiple ways of doing it.

  1. With mapTo method via method chaining

  2. With the key method

  3. Directly with the bind statement

When you directly bind services to a key, they will only be accessible by that key and those services can't be used for autowiring (injecting by type hinting), unless the service you are binding/registering is a string representaton of a class, in that case the service will automatically be mapped to the given key.

In case of mapTo and key bound/registered services are accessible by both the key and their class name, and because of that they can be used for autowiring.

Binding/Registering multiple services

For registering multiple services at once you can use the register method or it's alias bindMany.

Registering multiple singletons

Abstract binding

You can bind/register services to interfaces and abstract classes as well. These abstract bindings are convenient when used with autowiring, because you can type hint with abstractions (abstract classes and interfaces) and not concretions (implementations).

Contextual binding

When you want to bind/register multiple different services to a same interface or abstract class you need to provide context otherwise one will override the other. Context is the third parameter to the bind method, and it can be a string representation of a class or a key mapped to a class, and that class needs to be the one in whose constructor or method the interface/abstract class is used as a typehint.

Retrieveing services


All versions of container with dependencies

PHP Build Version
Package Version
Requires 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 sasa-b/container contains the following files

Loading the files please wait ....