Download the PHP package krak/cargo without Composer

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

Cargo

Cargo is yet another container library. Its feature set and semantics closely follow Pimple; however, it's design is more modular so that it can be extended. It was designed to be compatible with Pimple; so you can easily use any Pimple service providers with Cargo.

Pimple is a great service container; however it suffers from one problem... extendability. Pimple was never designed to properly extended or decorated which makes it very hard to add features without modifying the core. Cargo is a container that manages to keep the simplicity of Pimple while allowing powerful extensions.

Installation

Install with composer at krak/cargo

Usage

Creating a Container

There are several ways to create cargo containers. The easiest way is to just create the default container like so:

Which is just the same as doing:

Cargo is designed to be extendable and flexible, so each container decorator adds a feature that can be removed if not desired.

If you want just a bare bones container, you can use the following:

This just implements the Box and BoxFactory container which caches services as singletons by default.

Defining Services

Services can defined and configured several ways.

Due to the BoxFactoryContainer, all Closures are treated as lazy services. Meaning, they are not invoked until needed. The Singleton container also defaults all services to be singletons, so the result of the service definition closure is cached so that it's not invoked twice. These semantics mimic the behavior of the Pimple Container;

Accessing the Container

You can either use the ArrayAccess methods or get to retrieve values and invoke services.

Factory or Singleton Services

You can specify if you want to define a service as a factory or singleton with these two helper methods.

Parameters/Values

Anything added to the container that isn't a service is defined as value.

Values are stored and retrieved as is. No processing is done to them.

If you want to use a closure as a parameter, you can use the protect method:

Env Parameters

You can register parameters to be read from the environment with the env method:

Wrapping Services

Similar to Pimple's extend, Cargo allows you to wrap service definitions for decoration.

If you want to replace a definition, you would simply redefine it; however, if you want to decorate or modify a definition, you wrap it:

Service Freezing

Services by default will be frozen due to the FreezingContainer. You can redefine entries as much you'd like, but once a service is invoked, it is considered frozen and will throw an exception if you try to redefine it.

Aliasing Entries

It's often useful to use class names as the identifier, but then also provide aliases for a quick reference.

Auto Wiring

Auto wiring allows the container to try and automatically instantiate services if they aren't already defined in the container. To enable auto-wiring, you need to:

  1. Install the Auto Args Library (composer install krak/auto-args)
  2. Use the AutoWireContainer

In addition, you can bind any class to be auto wired:

a and b will resolve to their respective classes. This only works on singleton/factory entries, else it'll just treat the service like a string value and won't try to auto-resolve it.

Service Providers

Cargo\ServiceProvider provides a simple interface for defining multiple related services.

You can register service providers with a given container with the register method:

Container Interop

Krak\Cargo\Container is not compatible with the ContainerInterop interface by default. However, you can easily export the container to an Interop container using the toInterop function.

Pimple Interop

Achieving Pimple compatibility is simple with the toPimple function.

Delegate Containers

In an effort to provide better integration with other containers, we provide delegate containers to allow you to default to a cargo definitions, but fallback to the delegate container.

ArrayAccessDelegateContainer and PsrDelegateContainer both act as delegate containers. The first will accept any array or ArrayAccess object (like Pimple), and the other will accept any Psr Container.

Cargo Design

Container Interface for Decoration

To do...

Boxes

To do...

API

function alias(Container $c, $id, ...$aliases)

Aliases an entry $id into $aliases for the container $c. Each alias will share the same box reference as the original entry.

function env(Container $c, $var_name, $id = null)

Adds an EnvBox entry into the container $c with $var_name being the name of the env var and $id is the entry name. If $id is left null, then it will default to $var_name.


All versions of cargo with dependencies

PHP Build Version
Package Version
Requires krak/array Version ^0.4.0
psr/container Version ^1.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 krak/cargo contains the following files

Loading the files please wait ....