Download the PHP package patterns/event-channel without Composer

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

Patterns — Event Channel

A transport-agnostic contract for publishing and subscribing to named events.

Part of the Patterns collection: small, rock-solid, dependency-free building blocks. One pattern, one package.


Install

This package ships contracts only — no implementation, no adapters, no transport. That is deliberate: one stable contract, shared by libraries, is what makes a complex behaviour cheap to reuse. Redis, NATS, WebSocket, MQTT, Gun, an in-process emitter — each becomes an adapter behind the same contract, and a caller written against it never learns which one it got.

Why

Without a contract, every script picks its own transport and its own topology and its own client library:

Whether that is NATS, Redis or a WebSocket is a decision made once, where the adapter is constructed — not in every call site. That is the whole pattern.

The contract

Five contracts, six methods between them, and no verb in two places. Event is the message, EventPublisher and EventSubscriber are its two halves, EventChannel is those halves plus a transport's lifecycle, and EventProvider is the one thing a transport adapter has to implement.

Nothing is declared twice, so nothing can be quietly bypassed: a logger depends on EventPublisher alone, a consuming worker on EventSubscriber alone, and neither is asked for a connect() it will never call.

Contract

Member Declared by Guarantee
Event::type() Event The routing key. Dotted and hierarchical, so it doubles as a native subject on every broker (a.b.*, a/b/+, a.b.#).
publish($event) EventPublisher Deliver to every subscriber of $event->type(). Never swallows transport failures.
on($type, $handler) EventSubscriber Subscribe by key, or "*" for everything. Returns an unsubscribe callable that is idempotent and safe to call from inside the handler.
connect() EventChannel Establishes the transport handshake. Must be called before on() / publish().
close() EventChannel Release resources. publish() throws afterwards.
channel($topic) EventProvider The channel for a topic. Implementations may return the same channel for the same topic, and must not hand out two different ones.

Key vs envelope

The port needs exactly one thing from an event: its routing key. Everything else about an event is envelope, and the port must never need it.

Belongs to Example
Key the contract — type(): string lt.stock.updated
Envelope the implementation id, source, occurredAt, payload
Payload your domain — anything, including a ValueObject or a Unit new StockUpdated($sku, $qty)

That is why Event has one method and stays that way. The moment it grows id(), source() or occurredAt() it has become an envelope interface, and every implementation is forced into the same envelope shape.

A useful consequence: the key is stable data. Renaming or moving the class that carries an event does not change the protocol, and the same key works from any language.

A shape, not a policy

publish() returns nothing and signals failure by throwing. The contract does not return a Result, and that is a decision, not an omission:

For the same reason the contract carries no retry, no reconnection, no backpressure strategy and no state machine. Those are adapter options (set when the adapter is constructed) and caller decisions.

What is deliberately absent

Not in the contract Where it goes
once() Derived: call the unsubscribe handle you already hold after the first delivery. Across processes "once" means dedupe-by-id, which is a shared-state concern.
getState(), CONNECTING/DISCONNECTING A synchronous client has no such states — either the call returned or it threw.
reconnect, authToken, filters Adapter constructor options.
EventSelector (compound filters, prefixes) Implementation sugar. The contract defines "*" and nothing more.
getId() Identity for leases/registries is a shared-state concern.
emit() A deprecated alias in the original TypeScript. One name per operation.
getChannels(), removeChannel(), disconnect() Provider bookkeeping. close() ends a channel's life, and a caller that cares can keep its own list.
start(), stop() A server's words for what connect() and close() already say.
getStats() Metrics. Observability, not a contract.
a provider options bag (authToken, reconnect, transportOptions, limits) Adapter constructor arguments. Put it in a pattern and the pattern ships policy.

Implementing an adapter

  1. Implement Patterns\EventProvider — one method, channel(string $topic). Transport configuration (endpoint, credentials, pool size) belongs in your adapter's constructor, exactly as it does for S3.
  2. Implement Patterns\EventChannel for the channels it hands out.
  3. Map $type onto your transport's native subject (stock.updated → a NATS subject, a Redis channel, an MQTT topic).
  4. Throw on connection or publish failure — do not swallow it.
  5. Return an idempotent unsubscribe callable from on().
  6. Make close() release everything, and publish() after close() throw.
  7. Run the contract test suite against your adapter.

The test suite is the specification

Because no implementation ships, tests/EventChannelContractTest.php is the executable definition of the contract: routing by key, wildcard delivery, unsubscribe semantics, self-unsubscribing handlers, lifecycle ordering and the failure rules. tests/Fakes/InMemoryEventChannel.php is the smallest thing that satisfies it and doubles as a worked example of an adapter.

tests/EventTest.php guards the message: it fails if Event ever grows a second method. tests/EventFamilyTest.php guards the family: it fails if any two contracts declare the same verb, if EventChannel defines anything beyond connect()/close(), or if a state, metric or transport verb reappears on any of them. tests/EventProviderTest.php guards the provider port, including the absence of an options bag.

PHP notes (vs the TypeScript original)

Tests

License

MIT.


All versions of event-channel with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
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 patterns/event-channel contains the following files

Loading the files please wait ...