Download the PHP package buonaparte/bnp-service-definition without Composer

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

BnpServiceDefinition

Build Status Coverage Status Latest Stable Version Latest Unstable Version

This module allows you define ServiceManager factories through simple, yet verbose configuration.

Changelog

1.0.2

Installation

Setup

  1. Add this project to your composer.json:

  2. Now tell composer to download BnpServiceDefinition by running the command:

Post installation

Enabling it in your application.config.php file.

Configuration

Configure the module, by copying and adjusting config/bnp-service-definition.global.php.dist to your config include path.

Definition

In a default ZF2 Application you will define all dependencies through Factories, writing a Factory class for each service ofter takes a lot of time and becomes an additional overhead, for fast prototyping developers usually define Factories using Closures - the problem with Closures, is they cannot be cached. Many of Zf2 developer use Zend\Di for prototyping, however this one comes with even bigger overhead, besides too much magic. BnpServiceDefinition propose an alternative way of defining Factories, through all "beloved" array configuration, right in your module config. All definitions are represented by arrays, following the bellow structure (we will use short array syntax here, but this module has no dependency for PHP 5.4):

The above example illustrates a pretty simple MovieLister service definition. Notice an additional key under your service_manager configuration. Each service definition can contain the following:

The MovieLister service is an instance of MyApp\Service\MovieLister having one single constructor argument with a pretty strange syntax, an array ['type' => 'service', 'value' => 'MovieFinder'], this tells the definition parser to look for a MovieFinder instance in the Applications service locator (this is called a Definition Parameter).

A definition parameter is a simple string or a an array containing 2 entries: type and value. Parameters are used to specify a service class name, constructor arguments, method names to call as well as it's parameters and conditions. By default BnpServiceDefinition comes with these resolvable parameter types:

Every parameter gets compiled to the dsl type form by BnpServiceDefinition\Service\ParameterResolver, to evaluate or compile config and service types, for this purpose, the Symfony Expression Language is extended with 2 functions:

Supposing the MovieLister behaviour will be retrieved from database, the method_call definition could become:

Method calls also support conditions, so this the method will be called if all conditions will be evaluated to true, each condition is a Definition Parameter as well, this way the bellow is absolutely legal:

There are many cases when some of our services has the same constructor arguments, or part of them is the same. Because using Abstract Factories could not be the right choice or is simply impossible, you can define the repeating Service Factory stuff as an abstract definition, and all concrete factories will specify it as parant (parents are resolved recursively):

Notice order key for parameters, this is optional and by default all parameters are given the order of 0, however, at the compile time, all arguments are sorted in ascending order of this key value, SettingsMappers first constructor argument will be a value pulled from the config.

Using definitions from PluginManager scopes

You can add definitions support for each Plugin Manager, by specifying it in definition-aware-containers under bnp-service-definition configuration key, Ex:

!!! Notice service type parameters or service dsl function using from this scopes will point to the ZF2's Application Service Manager, to access a plugin from current scope you can use this dsl syntax: service('ControllerManager').get('some_service').

Supposing a MoviesController, we can now inject the MovieLister service as a hard dependency:

How it works

During Application bootstrap event, BnpServiceDefinition module registers an additional Abstract Factory to the Application's ServiceManager, at the same time, definition-aware-containers under bnp-service-definition configuration key is read and an Abstract Factory instance is registered for each of containers specified. The Abstract Factory will look for definitions key under ServiceManager configuration key it belongs to and is responsible to create on the fly or delegate the creation to a compiled version of all "terminal" (do not contain 'abstract' => true) definitions.

If dump-abstract-factories under bnp-service-definition is set to true, The Abstract Factory will delegate all it's calls to the compiled (dumped) version, or each requested definition will be compiled to Symfony Expression Language and evaluated on the fly otherwise.

For performance considerations you will always use dump-abstract-factories set to true, the module will check if your definitions have changed and regenerate the compiled version on the fly, all you will care about is specify a writable directory for storing that abstract factories, ex: ./data/bnp-service-definitions

A dumped version for the MovieLister service example will be generated in a file BnpGeneratedAbstractFactory_a81f0487f49ba10e22972a55497525bc.php with this content:


All versions of bnp-service-definition with dependencies

PHP Build Version
Package Version
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 buonaparte/bnp-service-definition contains the following files

Loading the files please wait ....