Download the PHP package webiny/service-manager without Composer

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

Service Manager

Install the component

The best way to install the component is using Composer.

For additional versions of the package, visit the Packagist page.

Usage

Available service configuration parameters are:

Extra parameters, for factory services, are:

There are 2 possible types of scope:

Service definition

To register a service you need to create a service config object (using ConfigObject class) and pass it to ServiceManager

You can either create your configuration files in YAML or use plain PHP and build arrays straight from your code. If using PHP - call new ConfigObject($configArray) to build a proper config object. If using YAML - call $config = Config::getInstance()->yaml($pathToYourConfigFile);

Basic service definition takes only Class parameter:

You can group your services in logic groups, by creating an array of service definitions and then registering them as a group:

Constructor arguments

You can provide constructor arguments to your service class, by using Arguments parameter. Argument can be any value, including class name (it will be instantiated and passed to constructor as a PHP object) and a reference to another service (enter service reference using @ character):

In case you need to provide constructor parameters to your argument class or service, you will need to use an extended arguments syntax (here is a config example written in YAML):

Creating service from a YAML config file

To create a ConfigObject out of your YAML file and register a new service, simply call:

Service object method calls

In case you need to call some methods on your service instance, you can specify them using Calls parameter:

Abstract services and parameters

Service manager also supports abstract services. When you have 2 or more services sharing similar functionality, you can extract common stuff into an abstract service. In the following example we also use Parameters. Parameters are like variables, define them once, and reuse whenever you need them.

Parameters config file:

NOTE: At the moment, parameters can not be used in ObjectArguments.

Services config file (this can also be defined in plain PHP array):

Now we need to register parameters and services with ServiceManager:

In this example we defined and abstract service TrayLoggerAbstract and 2 real loggers that extend the abstract service, WebinySystem and WebinyEcommerce. These 2 loggers share same class and method calls, but have different constructor arguments.

You can also specify arguments in abstract class and later override them in the real class. Also, you can add more method calls from child service:

In this last example, WebinySystem service will be constructed using the arguments from parent service and will also add an extra method call. WebinyEcommerce will provide it's own arguments to the parent constructor and will inherit the parent's Calls.

If you need to replace a method in Calls parameter, specify the third argument in call definition with the index of method to replace. In the following example, child method setSomething will replace the parent method at index 0, which is addHandler:

If you want to replace all of the parent Calls, put an exclamation mark in front of the Calls key, and make it look like this - !Calls:

In this case, child service Calls will completely replace parent Calls.

Accessing services from PHP

To use ServiceManager in your code, the easiest way is to simply use ServiceManagerTrait. This will give you access to $this->service().

If you do need to access ServiceManager class directly, use it like this:

Accessing services by tags

You can group services by using tags and load all of related services using single call. To achieve that, you need to add tags key to your service configuration:

Now execute the following piece of code. The result will be an array containing two services: WebinySystem and WebinyCustom:

You can also tell ServiceManager to filter the services using a given interface or a class name. It fill first fetch all services containing the requested tag and then filter them using the given class or interface name, before returning the final result set to you. This way you are sure you only get what you need and don't have to make checks yourself, resulting in a cleaner code:

Resources

To run unit tests, you need to use the following command:

$ cd path/to/Webiny/Component/ServiceManager/
$ composer.phar install
$ phpunit

All versions of service-manager with dependencies

PHP Build Version
Package Version
Requires php Version ^7
webiny/config Version ~1.6
webiny/std-lib Version ~1.6
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 webiny/service-manager contains the following files

Loading the files please wait ....