Download the PHP package apex/container without Composer

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

Apex Container

A lightweight, straight forward dependency injection container that simply works, and works well. Supports config file and all standard injection methods -- constructor, setter, annotation, plus also attributes. Also includes a Di wrapper class that allows container methods to be accessed statically for greater simplicity and efficiency.

Installation

Install via Composer with:

composer require apex/container

Basic Usage

Supports the standard container methods -- has, get, set, make, call,


use Apex\Container\Container;

$cntr = new Container('/path/to/definitions.php');

// Set and get
$cntr->set('full_name', 'John Doe');
// Get service
$logger = $cntr->get(LoggerInterface::class);
$logger->info("Here I am");

// Make and set
$user = $cntr->makeset(User::class, ['id' => 311]);

// Call via method setter injection
$cntr->call([$user, 'updateStatus'], ['status' => 'inactive']);

Constructor

Constructor takes the following parameters, none of which are required.

Parameter Type Description
$config_file string Location of the definitions file which defines starting items and services. Should be a PHP file that returns an associative array. Please see the Definitions File page for details. If defind in the constructor, will be automatically loaded.
$use_autowiring bool Whether or not to enable auto-wiring. If true, the use declarations of all files will be loaded, and checked for injection parameters. Defaults to true.
$use_attributes bool If true, will scan attributes in all files for injection properties. Please see the Attributes Injection page for details. Defaults to false.
$use_annotations bool If true, will scan the properties and doc blocks of all files for injected properties. Please see the Annotation Injection page for details. Defaults to false.

Mark Items as Services

You must explicitly mark necessary items as services, meaning the first time they are retrived from the container, they will be automatically instantiated with the new object instance set in the container for future use. Retrieving instantiable items from the container that are not marked as services will simply return the class name / closure, and will not instantiate the object.

You may easily mark items as services with the markItemAsService() method, for example:

use Apex\Container\Container;
use Apex\Psr\Log\LoggerInterface;

$cntr = new Container();
$cntr->markItemAsService(LoggerInterface::class);
$cntr->markItemAsService('debugger');

Methods

The following base methods are supported, as per all containers.

Method Description
has(string $name):bool Check whether or not item is available in container.
get(string $name):mixed Gets an item from the container. If does not already exist, will try to make and set the item. Returns null on non-existent item.
set(string $name, mixed $item):void Sets an item in the container.
make(string $name, array $params = []):mixed Creates new instance of the class with provided parameters.
makeset(string $name, array $params = []):mixed Creates new instance of the class with provided parameters, and also sets class name into container for future use.
call(callable | array $callable, array $params = []):mixed Used for method / setter injection, and will call given method with injected parameters. Callable may also be a two element array, the first element being a class name and second being an array of constructor parameters.
buildContainer(string $config_file):void Build container with the specified definitions file. Useful if you didn't pass a definitions file to the constructor, or if you're using the Di class to access the container statically.

Singleton Di Class

This package includes the Di class which acts as a singleton and allows container methods to be accessed statically, instead of passing the container object from class to class, method to method. This is done to provide efficiency and simplicity, and also assumes you're only managing one DI container per-request.

Modify the properties within the /src/Di.php file as they are used as the constructor parameters for the container. Example usage is below.


namespace myApp;

use Apex\Container\Di;
use myApp\Users\User;

// Get logger
$logger = Di::get(LoggerInterface::Class);

// Make user object
Di::make(User::class, ['id' => 52]);

// Set and get variable
Di::set('full_name', 'John Doe');
$name = Di::get('full_name');   // John Doe

Follow Apex

Loads of good things coming in the near future including new quality open source packages, more advanced articles / tutorials that go over down to earth useful topics, et al. Stay informed by joining the mailing list on our web site, or follow along on Twitter at @mdizak1.


All versions of container with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
psr/container Version ^2.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 apex/container contains the following files

Loading the files please wait ....