Download the PHP package dastur/capsule without Composer

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

Capsule

Capsule is a PHP dependency injection container. It allows you to bind instances to the container so you can retrieve them when they are required. If you would like to make sure none of your dependencies are hidden, you can use the automatic dependency injection provided by this package.

Table of Contents

Install

Composer

Run the following command from your projects base directory:

Usage

To start using capsule, create a new Capsule instance.

Binding

To bind a class to the container, use the bind method

$name parameter is the bindings alias. $path parameter is a class constant or string (that contains the full namespace). This is used by the Capsule when it needs to resolve a classes dependencies. $value parameter is a callable that returns the service that you are binding. $singleton parameter is whether or not you want the instance to only be resolved once.

Example:

By default, Capsule creates a new instance every time you get something from the container. If you want something to only be resolved once, use the singleton() method.

Resolving

When you need to get an instance from the container, use the get method

$name parameter is the name or class constant for the class that is being resolved. This method will only resolve classes that are stored in the Capsule.

Example:

Alternatively, you may use the following syntax:

If you need to create a class that is not binded in the container, use the make method.

$path is the class constant for the class you are resolving. You may use a string for this parameter as well, but make sure it is formatted correctly or else an error will be thrown. $parameters parameter is an array of overrides you would like to define.

For example:

Lets say you have the class Service that is dependant upon AnotherService and also requires a random string in its constructor.

Now, using the make method, the Capsule can resolve this service for you.

Now, if you try to access the $string and $anotherService properties, they will return randomString and a AnotherService instance respectively.

This is especially powerful when you have some important singletons bound into the container (ie. Router, Logger, etc...). Capsule can resolve those parameters for you.

Example:

Binding with Making (Resolving)

If there is a class, and you simply want to bind it into the framework without any configuration you can do the following:

If capsule sees this, it will bind Service into the container using the make method. This is the equivalent of doing the following:

If you need to specify overrides, you may specify a third parameter.

Destroying

If you need to destroy an instance in the container, you can do so using the destroy method.

Example:

Alternatively, you can also use the following syntax:

Contribute

This repository is accepting contributions. Check out the Contributing guide.

License

MIT © Dastur1970


All versions of capsule with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
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 dastur/capsule contains the following files

Loading the files please wait ....