Download the PHP package phpwatch/simple-container without Composer

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

Simple Container

A fast and minimal PSR-11 compatible Dependency Injection Container with array-syntax and without auto-wiring.

Latest Stable Version CI codecov Scrutinizer Code Quality License

Design goals

Installation

Usage

Simple Container supports array-syntax for setting and fetching of services and values. You can mark certain services as factory or protected later too.

Declare services and values

Fetch services

Do not use this class as a service locator. The closures you declare for each service will get the Container instance, from which you can fetch services using the array syntax:

Create container from definitions

Factory and Protected Services

If the service definition is a closure (similar to the database example above), the return value will be cached, and returned for subsequent calls without instantiating again. This is often the use expected behavior for databases and other reusable services.

Factory Services

To execute the provided closure every-time a service is requested (for example, to return an HTTP client), you can use factories.

The example above will always return a new curl handler resource everytime $container->get('http.client') is called, with the User-Agent string set to the http.user-agent value from container.

You can also mark a container service as a factory method later if it's already set:

If you have already declared the http.client service, it will now be marked as factory. If the existing declaration is not set, or is not a callable, a PHPWatch\SimpleContainer\Exception\BadMethodCallExceptionTest exception will be thrown.

Protected Services

Simple Container expects the service declarations to be closures, and it will execute the closure by itself to return the service. However, in some situations, you need to return a closure itself as the service.

This behavior is probably not what you wanted. You can mark the service as factory to retrieve different values every-time it is called. You can also mark it as protected, which will return the closure itself, so you can call it on your code:


Extend container

Just use the array syntax and add/remove services


Freezing container

By design, container is not allowed to be frozen. The Container class is extensible (get, getOffset, or the Container class itself are not declared final) if you absolutely need this feature.

Contributing

You are welcome to raise an issue or a PR if you have any questions or suggestions. Please keep in mind that this container aims to be the simplest and fastest container, and follow SOLID principles. Any feature that steps outside these goals (see design goals above) will likely not be accepted. However, your contributions will be appreciated and considered regardless of their nature.

Credits and Inspiration

This project is inspired by the Pimple project. It is no closed for new features and modifications, and does not support PSR-11. This sparked the idea of this project, and Pimple deserves the credit for its solid architecture and minimal set of features, including the support for array syntax.

Although separate projects, Simple Container is largely compatible with Pimple. This project is used in PHP.Watch and drop-in replaced Pimple.


All versions of simple-container with dependencies

PHP Build Version
Package Version
Requires psr/container Version ^2.0
php Version ^8.3
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 phpwatch/simple-container contains the following files

Loading the files please wait ....