Download the PHP package anonymous-php/simple-di without Composer

On this page you can find all versions of the php package anonymous-php/simple-di. 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 simple-di

Simple DI

Actually this library is more about the dependency container than auto-wiring but don't worry auto-wiring is there. You have the possibility to create instances of classes with auto-wiring of their arguments and to inject dependencies to called methods.

History

I like PHP-DI very much but when I started new project I understood it needs another approach of determining it's definitions and dependencies. I wanted to have the simplest as possible syntax of definitions and powerful, but not complex at the same time, mechanism of injection. So I just wrote my own DI.

Peculiarities

I didn't want to wrap any definition to unnecessary functions which just marks this definition as an instantiable class. I already know what is it while write a code and I want to decide how to use this information in my application.

My colleague asked me about the primitives injection in my library. I don't think is a good idea. Just make the dependency for the Container and get the value you need. Keep this type of values under control by yourself.

Compatibility

Auto-wiring is DISABLED by default.

Installation

Methods

Сlass Container implements \Psr\Container\ContainerInterface interface so it has two methods has($id) which works as usual and get($id) which can has the behavior different from your preferred library. There is the method set($id, $value) which does exactly the same it means.

get($id)

The method responds with a primitive with the only one exception - Closures. In case of Closure the library resolves it with the injection of it's dependencies. The Closure may to return any primitive or an instance of any class you wish. This method caches results of the resolving.

instantiate($id, array $arguments = [], $instanceOf = null)

This method creates an instance of the certain class. It tries to resolve the definition or instantiate provided class in case of definition absence. The method creates the new one instance on each call. In case of closure as argument instantiate resolves it each time too.

make($id, array $arguments = [], $recreate = false)

Almost the same as previous but with the cache. It means you will get the same instance on each method call. If method make will be called after instantiate using the same $id you will get already cached instance of class you provided.

injectOn($callable, array $arguments = [])

Injects arguments to the method of provided instance and calls it. If array of arguments doesn't contain all variables which called method wait for the library tries to resolve them. Notice: Closure is an object with the method __invoke so you can use injectOn on it.

call($callable, array $arguments = [])

Almost the same as injectOn but provides the possibility to resolve and instantiate provided class.

Todo:


All versions of simple-di 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 anonymous-php/simple-di contains the following files

Loading the files please wait ....