Download the PHP package fluffy/connector without Composer

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

Build Status

Connector - "Signals and slots" mechanism for PHP.

This library is inspired by Qt "Signals and slots" mechanism so it's pretty similar.

Signals and slots

Signal is something that tell outer world about the internal state of an object. For example: phones can ring, cats can meow etc. Rings and meows are signals. They tell us about changing in their internal states.

You can react on that signals in some way. For example: answer the call or feed the cat. Your reactions are slots.

There are tha same situations in programming: sometimes we need to react on some changes in object's state. And that's what this library for: it makes communication between objects easier. Even easier than it could be with "Observer" pattern.

Installation

Run

or add dependency to your composer.json file

Usage

1. Signals

If you want your object will be able to emit signals you need to implement SignalInterface and use SignalTrait. For example you have some logger class and you want to emit signal somethingIsLogged when logger finished work:

To emit signal you need to call emit method and pass signal name and data. You can pass whatever you want: array, string, object or number. That's all. Now your logger emits signal to outer world. But nobody is connected to this signal yet. Let do this stuff.

2. Slots

Slot it's a usual class method. Let's define a class with a slot.

3. Connections

For now we have Logger class that emits signal and Receiver class with a slot. To react on signal with slot you need to connect them to each other. Let's do it.

Since you called ConnectionManager::connect(SignalInterface $sender, $signalName, $receiver, $slotName); method signal and slot are connected. It means that after call $logger->log() the somethingIsLogged signal will be emitted and the slotReactOnSignal slot will be called. Result will be "Received data: Some useful data". You can connect as many slots to signals as you want. Actually you can create connections like:

You can also establish multiple connections by calling ConnectionManager::initConnections(array $connections); method:

3.1. Connection types

By default ConnectionManager::connect() method creates permanent connections. It means that slot will not be disconnected from signal after first emission. But you can make one-time connection. Just pass 5th parameter to ConnectionManager::connect() method as ConnectionManager::CONNECTION_ONE_TIME. For example:

After second call of Logger::log() nothing will happen because slot will be disconnected from signal after first emission.

3.2. Connection weights

Since you can connect different receivers with different slots to one sender and signal ConnectionManager calls connected slots in a special order - by connections weights. Lower weight has higher priority. Connections weights affect on order of slots from all receivers but not on order of slots inside one receiver.

By default ConnectionManager::connect() method creates permanent connections with zero weight. But you can change it by passing 6th parameter to ConnectionManager::connect() method. For example:

4. Disconnect

If you don't want to listen signal anymore just disconnect from it.

You can also disconnect connections by conditions:

  1. Disconnect all receivers from all signals for a given sender.

  2. Disconnect all receivers from a given signal of a given sender.

  3. Disconnect all slots from a given receiver from a given signal of a given sender.

If you want to reset all existing connections call

5. Services connections

If you are using Symfony Dependency Injection component you might don't want to create objects manually but retrieve them from service container instead. For such cases you can connect your services defined in services.yml file without any manual object creation. That's how you can achieve this:

  1. Let's say you have services.yml file with next services:

  2. In order to connect a \Receiver slot slotReactOnSignal to a \Logger signal somethingIsLogged create a yaml file somewhere (let's say services.connections.yml) in you project with next content:

  3. Initialize service connections:

  4. Now yor \Logger service is ready to emit signals and \Receiver service is ready to react on signals:

Tests

Please see tests for more information and use-cases.

In order to run tests type:

$ composer install

$ ./vendor/bin/phpunit

What for?

I just like Qt's signal and slot system and want to bring it into PHP world.

Any advantages?


All versions of connector with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.0
symfony/yaml Version ^3.2
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 fluffy/connector contains the following files

Loading the files please wait ....