Download the PHP package lss/yacontainer without Composer

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

YAContainer: Yet Another Container

A minimal Dependency Injection Container for PHP 8.1+

The goals of this project are

This package (or earlier versions of it) have been used in production on many sites for over a decade now. No fuss. It just works.

Why another container when there are already so many that are very good?

Pull requests welcome, but bear in mind the above project goals. If you have more complex needs, the other (better written, better supported, more mature) projects mentioned above will be a better choice for you.

How to use

Create your container and pass in scalar values and aliases to the constructor eg

This is the quickest way to set up your container with static configuration.

Ask the container for any autoloaded class by name eg $container->get(My\\Namespace\\MyClass::class);. The container will automatically build dependencies in the constructor and any recursive dependencies in their constructors. For most classes this should work with no further effort. For other classes that need extra configuration, you can use aliases, scalar injection and factory methods.

Aliases

Constructors should usually depend on interfaces rather than concrete classes. So how do you tell the container which concrete class to use? Specify an alias as in the above example.

Scalar injection / Parameters

Scalar values (int,string,float,bool) can be used as constructor or setter parameters if the name matches exactly (case sensitive) and a default value is not provided.

You can also use $container->addScalar() to add more later if needed.

If a default value is provided for a constructor parameter, it will be respected and the scalar value will not be injected. If you need to pass a different value, use a factory instead.

You can also use a callable for a scalar value. The callable will be called only once then replaced with its value for all subsequent uses.

Factory methods / Callables

For classes that are complicated to build or where the class needs a lot of stuff that nothing else needs, use a factory.

Setter injection

Setter injection can be emulated via a factory method. Call your setters after

Shared instances

All generated objects are shared by default. This means that each call to get() for the same class name will return the exact same class instance each time. If you need a different instance each time, provide a function that tells the container which instances to share.

will build a new Car class instance for each get() call.

To disable sharing (create a new instance for every object every time)

Forget

If you need a shared instance most of the time, but for some special reasons occasionally need a fresh instance, use forget() to forget the current one. The next call to get() will create a fresh instance.

PSR-11 Containers

We deliberately do not implement Psr\Container\ContainerInterface because

This is NOT a Service Locator

Avoid the temptation to pass the container as a dependency to your created classes. The best way to use this is in your bootstrap code to build the parts of your application into a single unit. Auryn has a good example.


All versions of yacontainer with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
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 lss/yacontainer contains the following files

Loading the files please wait ....