Download the PHP package atanvarno/dependency without Composer

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

Atanvarno\Dependency

Software License Latest Version Build Status Coverage Status

A bare bones PSR-11 dependency injection container, implementing ArrayAccess.

Features

Atanvarno\Dependency does not provide auto-wiring via reflection. It is a bare bones container only.

Requirements

PHP >= 8.0 is required, but the latest stable version of PHP is recommended.

Installation

Atanvarno\Dependency is available on Packagist and can be installed using Composer:

Basic Usage

Usage

Retrieving Entries

There are two ways to retrieve an entry:

Entries retrieved from an ID will, by default, be the same instance:

You can specify that each time you get a particular ID it will be a new instance when you define your entries (see lazy loading entries).

Checking Entries

There are two ways to check if an entry is available, each returns bool:

Removing Entries

There are two ways to remove an entry:

Adding entries

There are several ways to add an entry:

$entry can be any PHP value. Atanvarno\Dependency\Container when used like this is a simple key-value store, not particularly different from an array.

Instead entries can be defined so that they are lazy loaded.

Entries can also be added via the constructor (see instantiation).

Lazy Loading Entries

Any entry can be defined as lazy loaded, so it is built only when it is accessed.

Two helper functions are included to allow you define lazy loaded entries: object().

(The examples use the set() method, but array syntax works as well.)

You can return a value from any callable using factory():

You can return an object from its class name using object():

Both factory() and object() take an array of parameters to pass to the callable or constructor. These parameters can be any PHP value or can be other container entries. Other container entries are referenced by using the entry() function:

(The container itself can referenced using the default entry ID container. If you need the container to have a different entry ID, use setSelfId().)

Both factory() and object() take an optional third bool parameter which determines whether the first value they return should be registered and subsequently always returned when the entry is retrieved (default behaviour), or whether a new value should be returned each time (pass false).

Setting Properties and Calling Methods

You may want to set public properties or call methods of newly instantiated objects in order to configure them for use.

Both factory() and object() return a Definition which provides methods with a fluent interface to allow this:

The example uses object(), but will work as well with factory(). Note if factory() does not define a object instance, these methods will do nothing.

Delegate Lookup Feature

Atanvarno\Dependency\Container implements container-interop's delegate lookup feature and can act as both a parent/composite/delegate and child container.

To add child containers (and make $container a composite container) use addChild():

Subsequent calls will add additional children.

To add a parent container (and make $container delegate its dependency lookups) use setDelegate():

Subsequent calls will replace the parent.

Fluent Interface

Atanvarno\Dependency\Container provides a fluent interface, allowing multiple calls to be chained. These methods each return the Container instance:

Instantiation

When the container is instantiated it optionally accepts an array of Definition instances (returned from factory(), object() and value()) which will be added to the container. This array is indexed by entry ID.

You can make a configuration file that returns this array:

Then include it in the constructor call:

Caching

Atanvarno\Dependency\Container can use a PSR-16 cache to persist registered items. Note it does not persist definitions; only registered values that have been returned at least once.

The cache is invisible to the user; calls to delete(),get() and set() will use and update the cache as they require.

If you want to clear the container's cache use clearCache():

The constructor accepts a cache as its second parameter and an optional key for use with the cache as its third parameter (defaults to container).

The constructor also accept an entry() that points to a cache defined in the first parameter, so the cache instance can be loaded by the container itself.

Exceptions

All exceptions thrown implement PSR-11's ContainerExceptionInterface.

Full API

See API.


All versions of dependency with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0
psr/container Version ^1.0.0
psr/simple-cache Version ^1.0.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 atanvarno/dependency contains the following files

Loading the files please wait ....