Download the PHP package renakdup/simple-dic without Composer

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

Simple DIC - PHP DI Container in one file for your WordPress.

UnitTests Test Coverage PHPStan

Latest Stable Version PHP Version Require Total Downloads

Simple DI Container with autowiring in a single file with NO dependencies allows you to easily use it in your PHP applications and especially convenient for WordPress plugins and themes.

Why choose Simple DI Container

  1. Easy to integrate in your WordPress project - just copy one file or install via Composer.
  2. No dependencies on other scripts or libraries.
  3. Supports auto-wiring __constructor parameters for classes as well as for scalar types that have default values.
  4. Supports PHP ^7.4|^8.
  5. Allow you following the best practices for developing your code.
  6. No PHPCS conflicts.
  7. Supports Lazy Load class instantiating.
  8. Lightweight and fast.

How to install in a project

There are several ways, you can choose what you more prefer:

Install via Composer

Copy and paste file

  1. Just copy the file ./src/Container.php to your plugin directory or theme.
  2. Rename namespace in the file
    from Renakdup\SimpleDIC to <Your_Plugin_Name>\SimpleDIC
  3. Include the file.

How to use it

Get started:

  1. Create container instance.
  2. Set a service
  3. Get a service
  4. Use object

SimpleDIC allows to set values for the container for primitive types:

Method get() can resolve not set object in the $container and then save resolved results in the $container. It means when you run $container->get( $service ) several times you get the same object.

If you want to instantiate service several time use make() method.


Factory

Factory is an anonymous function that wrap creating an instance.
Allows to configure how an object will be created and allows to use Conainer instance inside the factory.

As well factories create objects in the Lazy Load mode. It means that object will be created just when you resolve it by using get() method:


Container inside factory

SimpleDIC allows to get a Container instance inside a factory if you add parameter in a callback ( Container $c ). This allows to get or resolve another services inside for building an object:


Autowiring

SimpleDIС autowiring feature allows to Container automatically create and inject dependencies.

I'll show an example:

And then when you create Paypal::class, you run $container->get(Paypal::class), and Container identifies all classes in the constructor and resolves them. As if it's:


Container autowiring can resolve default values for primitive parameters in a constructor:

You can use auto-wiring feature that allows to Container create an instances that requires in the __constructor of class as well as it resolves constructor dependencies for

[!NOTE] But if object creating is more complex and requires configuring and you don't have parameters with default values in the constructor then you need to use factory for preparing service.


Create an instance every time

Method make() resolves services by its name. It returns a new instance of service every time and supports auto-wiring.

[!NOTE]
Constructor's dependencies will not instantiate every time.
If dependencies were resolved before then they will be passed as resolved dependencies.

Consider example:

Dependencies of PayPal service will not be recreated and will be taken from already resolved objects.


PSR11 Compatibility

in progress

Roadmap

Nice to have

License

The MIT License (MIT). Please see the License File for more information.


All versions of simple-dic with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8
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 renakdup/simple-dic contains the following files

Loading the files please wait ....