[COMPOSER] Add new php-ffmpeg package

This commit is contained in:
t3nma
2020-08-07 23:42:38 +01:00
parent 0a6bb5190f
commit c527ad0803
8874 changed files with 1090008 additions and 154 deletions

View File

@@ -0,0 +1,279 @@
# Changelog
All notable changes to this project will be documented in this file, in reverse chronological order by release.
## 3.2.1 - 2018-04-25
### Added
- [#66](https://github.com/zendframework/zend-eventmanager/pull/66) adds support for PHP 7.2.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 3.2.0 - 2017-07-11
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- [#47](https://github.com/zendframework/zend-eventmanager/pull/47) removes
support for PHP 5.5 and HHVM.
### Fixed
- Nothing.
## 3.1.0 - 2016-12-19
### Added
- [#26](https://github.com/zendframework/zend-eventmanager/pull/26) publishes
the documentation to https://zendframework.github.io/zend-eventmanager/
### Changes
- [#17](https://github.com/zendframework/zend-eventmanager/pull/17) makes a
number of internal changes to how listeners are stored in order to improve
performance, by as much as 10% in the scenario used in the MVC layer.
Additionally, it optimizes when the target and event arguments are injected
into an event, eliminating that step entirely when either is unavailable.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 3.0.1 - 2016-02-18
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#24](https://github.com/zendframework/zend-eventmanager/pull/24) updates the
zend-stdlib dependency to `^2.7.3 || ^3.0`, allowing either major version.
## 3.0.0 - 2016-01-12
### Added
- [Migration documentation](doc/book/migration/) was added.
- [Automated benchmarks](benchmarks/) were added.
- `EventManager::__construct()` now accepts an optional
`SharedEventManagerInterface` instance as the first argument, and an optional
array of identifiers as the second. As identifiers have no meaning without a
shared manager present, they are secondary to providing the shared manager.
- `EventManagerInterface::trigger()` changes its signature to
`trigger($eventName, $target = null, $argv = [])`; each argument has exactly
one possible meaning; the `$eventName` can only be a string event name. The
fourth `$callback` argument is removed.
- `EventManagerInterface::triggerUntil()` changes its signature to
`triggerUntil(callable $callback, $eventName, $target = null, $argv = null)`.
Each argument has exactly one meaning.
- `EventManagerInterface` adds two new methods for triggering provided
`EventInterface` arguments: `triggerEvent(EventInterface $event)` and
`triggerEventUntil(callable $callback, EventInterface $event)`.
- `EventManagerInterface::attach()` and `detach()` change their signatures to
`attach($eventName, callable $listener, $priority = 1)` and `detach(callable
$listener, $eventName = null)`, respectively. Note that `$eventName` can now
only be a string event name, not an array or `Traversable`.
- `EventManagerInterface::setIdentifiers()` and `addIdentifiers()` change their
signatures to each only accept an *array* of identifiers.
- `SharedEventManagerInterface::getListeners()` changes signature to
`getListeners(array $identifiers, $eventName)` and now guarantees return of an
array. Note that the second argument is now *required*.
- `SharedEventManagerInterface::attach()` changes signature to
`attach($identifier, $eventName, callable $listener, $priority = 1)`. The
`$identifier` and `$eventName` **must** be strings.
- `SharedEventManagerInterface::detach()` changes signature to `detach(callable
$listener, $identifier = null, $eventName = null)`; `$identifier` and
`$eventName` **must** be strings if passed.
- `ListenerAggregateInterface::attach()` adds an optional `$priority = 1`
argument. This was used already in v2, but not dictated by the interface.
- `FilterInterface::attach()` and `detach()` have changed signature to
`attach(callable $callback)` and `detach(callable $ilter)`, respectively.
- `LazyListener` allows wrapping:
- fetching a listener service from a container-interop container, and
- invoking a designated listener method with the provided event.
- `LazyEventListener` extends `LazyListener`, and provides metadata for
discovering the intended event name and priority at which to attach the lazy
listener; these are consumed by:
- `LazyListenerAggregate`, which, provided a list of `LazyEventListeners` and/or
definitions to use to create them, acts as an aggregate for attaching a number
of such listeners at once.
- [#20](https://github.com/zendframework/zend-eventmanager/pull/20) updates the
trait `Zend\EventManager\Test\EventListenerIntrospectionTrait` so that the
implementation will work with the v3 changes; the tests written for v2
continue to pass, allowing this trait to be used to provide compatibility
testing between v2 and v3.
### Deprecated
- Nothing.
### Removed
- `GlobalEventManager` and `StaticEventManager` are removed (with prejudice!).
- `ProvidesEvents`, which was previously deprecated, is removed.
- `EventManagerInterface::setSharedManager()` is removed. Shared managers are
now expected to be injected during instantiation.
- `EventManagerInterface::getEvents()` and `getListeners()` are removed; they
had now purpose within the implementation.
- `EventManagerInterface::setEventClass()` was renamed to `setEventPrototype()`,
which now expects an `EventInterface` instance. That instance will be cloned
whenever a new event is created.
- `EventManagerInterface::attachAggregate()` and `detachAggregate()` are
removed. Users should use the `attach()` and `detach()` methods of the
aggregates themselves.
- `SharedEventAggregateAwareInterface` and `SharedListenerAggregateInterface`
are removed. This was an undocumented and largely unused feature.
- `SharedEventManagerAwareInterface` is removed. A new interface,
`SharedEventsCapableInterface` defines the `getSharedManager()` method from
the interface, and `EventManagerInterface` extends that new interface.
- `SharedEventManagerInterface::getEvents()` is removed, as it had no purpose in
the implementation.
- `ResponseCollection::setStopped()` no longer implements a fluent interface.
### Fixed
- `FilterIterator::insert()` has been modified to raise an exception if the value provided is not a callable.
## 2.6.2 - 2016-01-12
### Added
- [#19](https://github.com/zendframework/zend-eventmanager/pull/19) adds a new
trait, `Zend\EventManager\Test\EventListenerIntrospectionTrait`, intended for
composition in unit tests. It provides a number of methods that can be used
to retrieve listeners with or without associated priority, and the assertion
`assertListenerAtPriority(callable $listener, $priority, $event, EventManager $events, $message = '')`,
which can be used for testing that a listener was registered at the specified
priority with the specified event.
The features in this patch are intended to facilitate testing against both
version 2 and version 3 of zend-eventmanager, as it provides a consistent API
for retrieving lists of events and listeners between the two versions.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 2.6.0 - 2015-09-29
### Added
- Added `Zend\EventManager\SharedEventsCapableInterface`. This interface will
largely replace `Zend\EventManager\SharedEventManagerAwareInterface` in
version 3, and the latter was updated to extend it.
- Added `EventManager::triggerEvent(EventInterface $event)` as a
forwards-compatibility feature.
- Add `EventManager::triggerEventUntil(callable $callback, EventIterface $event)`
as a forwards-compatibility feature.
- Adds [Athletic](https://github.com/polyfractal/athletic) benchmarks to aid in
gauging performanc impact of changes; these are a development change only.
### Deprecated
- Marked `GlobalEventManager` as deprecated; this class will be removed in
version 3.
- Marked `StaticEventManager` as deprecated; this class will be removed in
version 3.
- Marked `SharedListenerAggregateInterface` as deprecated; this interface will
be removed in version 3.
- Marked `SharedEventAggregateAwareInterface` as deprecated; this interface will
be removed in version 3.
- Marked `SharedEventManagerAwareInterface` as deprecated; this interface will
be removed in version 3.
- Marked `EventManager::setSharedManager()` as deprecated; this method will be
removed in version 3.
- Marked `EventManager::unsetSharedManager()` as deprecated; this method will be
removed in version 3.
- Marked `EventManagerInterface::` and `EventManager::getEvents()` as
deprecated; this method will be removed in version 3.
- Marked `EventManagerInterface::` and `EventManager::getListeners()` as
deprecated; this method will be removed in version 3.
- Marked `EventManagerInterface::` and `Eventmanager::setEventClass()` as
deprecated; this method is renamed to `setEventPrototype(EventInterface $event)`
in version 3.
- Marked `EventManagerInterface::` and `EventManager::attachAggregate()` as
deprecated; this method will be removed in version 3.
- Marked `EventManagerInterface::` and `EventManager::detachAggregate()` as
deprecated; this method will be removed in version 3.
- Marked `SharedEventManagerInterface::` and `SharedEventManager::getEvents()`
as deprecated; this method will be removed in version 3.
### Removed
- Nothing.
### Fixed
- Nothing.
## 2.5.2 - 2015-07-16
### Added
- [#5](https://github.com/zendframework/zend-eventmanager/pull/5) adds a number
of unit tests to improve test coverage, and thus maintainability and
stability.
### Deprecated
- Nothing.
### Removed
- [#3](https://github.com/zendframework/zend-eventmanager/pull/3) removes some
PHP 5.3- and 5.4-isms (such as marking Traits as requiring 5.4, and closing
over a copy of `$this`) from the test suite.
### Fixed
- [#5](https://github.com/zendframework/zend-eventmanager/pull/5) fixes a bug in
`FilterIterator` that occurs when attempting to extract from an empty heap.

View File

@@ -0,0 +1,43 @@
# Contributor Code of Conduct
The Zend Framework project adheres to [The Code Manifesto](http://codemanifesto.com)
as its guidelines for contributor interactions.
## The Code Manifesto
We want to work in an ecosystem that empowers developers to reach their
potential — one that encourages growth and effective collaboration. A space that
is safe for all.
A space such as this benefits everyone that participates in it. It encourages
new developers to enter our field. It is through discussion and collaboration
that we grow, and through growth that we improve.
In the effort to create such a place, we hold to these values:
1. **Discrimination limits us.** This includes discrimination on the basis of
race, gender, sexual orientation, gender identity, age, nationality, technology
and any other arbitrary exclusion of a group of people.
2. **Boundaries honor us.** Your comfort levels are not everyones comfort
levels. Remember that, and if brought to your attention, heed it.
3. **We are our biggest assets.** None of us were born masters of our trade.
Each of us has been helped along the way. Return that favor, when and where
you can.
4. **We are resources for the future.** As an extension of #3, share what you
know. Make yourself a resource to help those that come after you.
5. **Respect defines us.** Treat others as you wish to be treated. Make your
discussions, criticisms and debates from a position of respectfulness. Ask
yourself, is it true? Is it necessary? Is it constructive? Anything less is
unacceptable.
6. **Reactions require grace.** Angry responses are valid, but abusive language
and vindictive actions are toxic. When something happens that offends you,
handle it assertively, but be respectful. Escalate reasonably, and try to
allow the offender an opportunity to explain themselves, and possibly correct
the issue.
7. **Opinions are just that: opinions.** Each and every one of us, due to our
background and upbringing, have varying opinions. The fact of the matter, is
that is perfectly acceptable. Remember this: if you respect your own
opinions, you should respect the opinions of others.
8. **To err is human.** You might not intend it, but mistakes do happen and
contribute to build experience. Tolerate honest mistakes, and don't hesitate
to apologize if you make one yourself.

View File

@@ -0,0 +1,234 @@
# CONTRIBUTING
## RESOURCES
If you wish to contribute to Zend Framework, please be sure to
read/subscribe to the following resources:
- [Coding Standards](https://github.com/zendframework/zf2/wiki/Coding-Standards)
- [Contributor's Guide](http://framework.zend.com/participate/contributor-guide)
- ZF Contributor's mailing list:
Archives: http://zend-framework-community.634137.n4.nabble.com/ZF-Contributor-f680267.html
Subscribe: zf-contributors-subscribe@lists.zend.com
- ZF Contributor's IRC channel:
#zftalk.dev on Freenode.net
If you are working on new features or refactoring [create a proposal](https://github.com/zendframework/zend-event-manager/issues/new).
## Reporting Potential Security Issues
If you have encountered a potential security vulnerability, please **DO NOT** report it on the public
issue tracker: send it to us at [zf-security@zend.com](mailto:zf-security@zend.com) instead.
We will work with you to verify the vulnerability and patch it as soon as possible.
When reporting issues, please provide the following information:
- Component(s) affected
- A description indicating how to reproduce the issue
- A summary of the security vulnerability and impact
We request that you contact us via the email address above and give the project
contributors a chance to resolve the vulnerability and issue a new release prior
to any public exposure; this helps protect users and provides them with a chance
to upgrade and/or update in order to protect their applications.
For sensitive email communications, please use [our PGP key](http://framework.zend.com/zf-security-pgp-key.asc).
## RUNNING TESTS
> ### Note: testing versions prior to 2.4
>
> This component originates with Zend Framework 2. During the lifetime of ZF2,
> testing infrastructure migrated from PHPUnit 3 to PHPUnit 4. In most cases, no
> changes were necessary. However, due to the migration, tests may not run on
> versions < 2.4. As such, you may need to change the PHPUnit dependency if
> attempting a fix on such a version.
To run tests:
- Clone the repository:
```console
$ git clone git@github.com:zendframework/zend-event-manager.git
$ cd
```
- Install dependencies via composer:
```console
$ curl -sS https://getcomposer.org/installer | php --
$ ./composer.phar install
```
If you don't have `curl` installed, you can also download `composer.phar` from https://getcomposer.org/
- Run the tests via `phpunit` and the provided PHPUnit config, like in this example:
```console
$ ./vendor/bin/phpunit
```
You can turn on conditional tests with the phpunit.xml file.
To do so:
- Copy `phpunit.xml.dist` file to `phpunit.xml`
- Edit `phpunit.xml` to enable any specific functionality you
want to test, as well as to provide test values to utilize.
## Running Coding Standards Checks
This component uses [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) for coding
standards checks, and provides configuration for our selected checks.
`phpcs` is installed by default via Composer.
To run checks only:
```console
$ composer cs-check
```
`phpcs` also includes a tool for fixing most CS violations, `phpcbf`:
```console
$ composer cs-fix
```
If you allow `phpcbf` to fix CS issues, please re-run the tests to ensure
they pass, and make sure you add and commit the changes after verification.
## Recommended Workflow for Contributions
Your first step is to establish a public repository from which we can
pull your work into the master repository. We recommend using
[GitHub](https://github.com), as that is where the component is already hosted.
1. Setup a [GitHub account](http://github.com/), if you haven't yet
2. Fork the repository (http://github.com/zendframework/zend-event-manager)
3. Clone the canonical repository locally and enter it.
```console
$ git clone git://github.com:zendframework/zend-event-manager.git
$ cd zend-event-manager
```
4. Add a remote to your fork; substitute your GitHub username in the command
below.
```console
$ git remote add {username} git@github.com:{username}/zend-event-manager.git
$ git fetch {username}
```
### Keeping Up-to-Date
Periodically, you should update your fork or personal repository to
match the canonical ZF repository. Assuming you have setup your local repository
per the instructions above, you can do the following:
```console
$ git checkout master
$ git fetch origin
$ git rebase origin/master
# OPTIONALLY, to keep your remote up-to-date -
$ git push {username} master:master
```
If you're tracking other branches -- for example, the "develop" branch, where
new feature development occurs -- you'll want to do the same operations for that
branch; simply substitute "develop" for "master".
### Working on a patch
We recommend you do each new feature or bugfix in a new branch. This simplifies
the task of code review as well as the task of merging your changes into the
canonical repository.
A typical workflow will then consist of the following:
1. Create a new local branch based off either your master or develop branch.
2. Switch to your new local branch. (This step can be combined with the
previous step with the use of `git checkout -b`.)
3. Do some work, commit, repeat as necessary.
4. Push the local branch to your remote repository.
5. Send a pull request.
The mechanics of this process are actually quite trivial. Below, we will
create a branch for fixing an issue in the tracker.
```console
$ git checkout -b hotfix/9295
Switched to a new branch 'hotfix/9295'
```
... do some work ...
```console
$ git commit
```
... write your log message ...
```console
$ git push {username} hotfix/9295:hotfix/9295
Counting objects: 38, done.
Delta compression using up to 2 threads.
Compression objects: 100% (18/18), done.
Writing objects: 100% (20/20), 8.19KiB, done.
Total 20 (delta 12), reused 0 (delta 0)
To ssh://git@github.com/{username}/zend-event-manager.git
b5583aa..4f51698 HEAD -> master
```
To send a pull request, you have two options.
If using GitHub, you can do the pull request from there. Navigate to
your repository, select the branch you just created, and then select the
"Pull Request" button in the upper right. Select the user/organization
"zendframework" as the recipient.
If using your own repository - or even if using GitHub - you can use `git
format-patch` to create a patchset for us to apply; in fact, this is
**recommended** for security-related patches. If you use `format-patch`, please
send the patches as attachments to:
- zf-devteam@zend.com for patches without security implications
- zf-security@zend.com for security patches
#### What branch to issue the pull request against?
Which branch should you issue a pull request against?
- For fixes against the stable release, issue the pull request against the
"master" branch.
- For new features, or fixes that introduce new elements to the public API (such
as new public methods or properties), issue the pull request against the
"develop" branch.
### Branch Cleanup
As you might imagine, if you are a frequent contributor, you'll start to
get a ton of branches both locally and on your remote.
Once you know that your changes have been accepted to the master
repository, we suggest doing some cleanup of these branches.
- Local branch cleanup
```console
$ git branch -d <branchname>
```
- Remote branch removal
```console
$ git push {username} :<branchname>
```
## Conduct
Please see our [CONDUCT.md](CONDUCT.md) to understand expected behavior when interacting with others in the project.

View File

@@ -0,0 +1,28 @@
Copyright (c) 2005-2015, Zend Technologies USA, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Zend Technologies USA, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,32 @@
# zend-eventmanager
[![Build Status](https://secure.travis-ci.org/zendframework/zend-eventmanager.svg?branch=master)](https://secure.travis-ci.org/zendframework/zend-eventmanager)
[![Coverage Status](https://coveralls.io/repos/zendframework/zend-eventmanager/badge.svg?branch=master)](https://coveralls.io/r/zendframework/zend-eventmanager?branch=master)
zend-eventmanager is designed for the following use cases:
- Implementing simple subject/observer patterns.
- Implementing Aspect-Oriented designs.
- Implementing event-driven architectures.
The basic architecture allows you to attach and detach listeners to named events,
both on a per-instance basis as well as via shared collections; trigger events;
and interrupt execution of listeners.
- File issues at https://github.com/zendframework/zend-eventmanager/issues
- Documentation is at https://zendframework.github.io/zend-eventmanager/
For migration from version 2 to version 3, please [read the migration
documentation](https://zendframework.github.io/zend-eventmanager/migration/intro/).
## Benchmarks
We provide scripts for benchmarking zend-eventmanager using the
[Athletic](https://github.com/polyfractal/athletic) framework; these can be
found in the `benchmarks/` directory.
To execute the benchmarks you can run the following command:
```bash
$ vendor/bin/athletic -p benchmarks
```

View File

@@ -0,0 +1,58 @@
{
"name": "zendframework/zend-eventmanager",
"description": "Trigger and listen to events within a PHP application",
"license": "BSD-3-Clause",
"keywords": [
"zf2",
"event",
"events",
"eventmanager"
],
"homepage": "https://github.com/zendframework/zend-eventmanager",
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "3.2-dev",
"dev-develop": "3.3-dev"
}
},
"autoload": {
"psr-4": {
"Zend\\EventManager\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ZendTest\\EventManager\\": "test/",
"ZendBench\\EventManager\\": "benchmarks/"
},
"files": [
"test/_autoload.php"
]
},
"require": {
"php": "^5.6 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.2",
"athletic/athletic": "^0.1",
"zendframework/zend-stdlib": "^2.7.3 || ^3.0",
"container-interop/container-interop": "^1.1.0",
"zendframework/zend-coding-standard": "~1.0.0"
},
"suggest": {
"container-interop/container-interop": "^1.1.0, to use the lazy listeners feature",
"zendframework/zend-stdlib": "^2.7.3 || ^3.0, to use the FilterChain feature"
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
}
}

1937
vendor/zendframework/zend-eventmanager/composer.lock generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,32 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
/**
* Abstract aggregate listener
*/
abstract class AbstractListenerAggregate implements ListenerAggregateInterface
{
/**
* @var callable[]
*/
protected $listeners = [];
/**
* {@inheritDoc}
*/
public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $index => $callback) {
$events->detach($callback);
unset($this->listeners[$index]);
}
}
}

View File

@@ -0,0 +1,201 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
use ArrayAccess;
/**
* Representation of an event
*
* Encapsulates the target context and parameters passed, and provides some
* behavior for interacting with the event manager.
*/
class Event implements EventInterface
{
/**
* @var string Event name
*/
protected $name;
/**
* @var string|object The event target
*/
protected $target;
/**
* @var array|ArrayAccess|object The event parameters
*/
protected $params = [];
/**
* @var bool Whether or not to stop propagation
*/
protected $stopPropagation = false;
/**
* Constructor
*
* Accept a target and its parameters.
*
* @param string $name Event name
* @param string|object $target
* @param array|ArrayAccess $params
*/
public function __construct($name = null, $target = null, $params = null)
{
if (null !== $name) {
$this->setName($name);
}
if (null !== $target) {
$this->setTarget($target);
}
if (null !== $params) {
$this->setParams($params);
}
}
/**
* Get event name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get the event target
*
* This may be either an object, or the name of a static method.
*
* @return string|object
*/
public function getTarget()
{
return $this->target;
}
/**
* Set parameters
*
* Overwrites parameters
*
* @param array|ArrayAccess|object $params
* @throws Exception\InvalidArgumentException
*/
public function setParams($params)
{
if (! is_array($params) && ! is_object($params)) {
throw new Exception\InvalidArgumentException(
sprintf('Event parameters must be an array or object; received "%s"', gettype($params))
);
}
$this->params = $params;
}
/**
* Get all parameters
*
* @return array|object|ArrayAccess
*/
public function getParams()
{
return $this->params;
}
/**
* Get an individual parameter
*
* If the parameter does not exist, the $default value will be returned.
*
* @param string|int $name
* @param mixed $default
* @return mixed
*/
public function getParam($name, $default = null)
{
// Check in params that are arrays or implement array access
if (is_array($this->params) || $this->params instanceof ArrayAccess) {
if (! isset($this->params[$name])) {
return $default;
}
return $this->params[$name];
}
// Check in normal objects
if (! isset($this->params->{$name})) {
return $default;
}
return $this->params->{$name};
}
/**
* Set the event name
*
* @param string $name
*/
public function setName($name)
{
$this->name = (string) $name;
}
/**
* Set the event target/context
*
* @param null|string|object $target
*/
public function setTarget($target)
{
$this->target = $target;
}
/**
* Set an individual parameter to a value
*
* @param string|int $name
* @param mixed $value
*/
public function setParam($name, $value)
{
if (is_array($this->params) || $this->params instanceof ArrayAccess) {
// Arrays or objects implementing array access
$this->params[$name] = $value;
return;
}
// Objects
$this->params->{$name} = $value;
}
/**
* Stop further event propagation
*
* @param bool $flag
*/
public function stopPropagation($flag = true)
{
$this->stopPropagation = (bool) $flag;
}
/**
* Is propagation stopped?
*
* @return bool
*/
public function propagationIsStopped()
{
return $this->stopPropagation;
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
use ArrayAccess;
/**
* Representation of an event
*/
interface EventInterface
{
/**
* Get event name
*
* @return string
*/
public function getName();
/**
* Get target/context from which event was triggered
*
* @return null|string|object
*/
public function getTarget();
/**
* Get parameters passed to the event
*
* @return array|ArrayAccess
*/
public function getParams();
/**
* Get a single parameter by name
*
* @param string $name
* @param mixed $default Default value to return if parameter does not exist
* @return mixed
*/
public function getParam($name, $default = null);
/**
* Set the event name
*
* @param string $name
* @return void
*/
public function setName($name);
/**
* Set the event target/context
*
* @param null|string|object $target
* @return void
*/
public function setTarget($target);
/**
* Set event parameters
*
* @param array|ArrayAccess $params
* @return void
*/
public function setParams($params);
/**
* Set a single parameter by key
*
* @param string $name
* @param mixed $value
* @return void
*/
public function setParam($name, $value);
/**
* Indicate whether or not the parent EventManagerInterface should stop propagating events
*
* @param bool $flag
* @return void
*/
public function stopPropagation($flag = true);
/**
* Has this event indicated event propagation should stop?
*
* @return bool
*/
public function propagationIsStopped();
}

View File

@@ -0,0 +1,343 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
use ArrayObject;
/**
* Event manager: notification system
*
* Use the EventManager when you want to create a per-instance notification
* system for your objects.
*/
class EventManager implements EventManagerInterface
{
/**
* Subscribed events and their listeners
*
* STRUCTURE:
* [
* <string name> => [
* <int priority> => [
* 0 => [<callable listener>, ...]
* ],
* ...
* ],
* ...
* ]
*
* NOTE:
* This structure helps us to reuse the list of listeners
* instead of first iterating over it and generating a new one
* -> In result it improves performance by up to 25% even if it looks a bit strange
*
* @var array[]
*/
protected $events = [];
/**
* @var EventInterface Prototype to use when creating an event at trigger().
*/
protected $eventPrototype;
/**
* Identifiers, used to pull shared signals from SharedEventManagerInterface instance
*
* @var array
*/
protected $identifiers = [];
/**
* Shared event manager
*
* @var null|SharedEventManagerInterface
*/
protected $sharedManager = null;
/**
* Constructor
*
* Allows optionally specifying identifier(s) to use to pull signals from a
* SharedEventManagerInterface.
*
* @param SharedEventManagerInterface $sharedEventManager
* @param array $identifiers
*/
public function __construct(SharedEventManagerInterface $sharedEventManager = null, array $identifiers = [])
{
if ($sharedEventManager) {
$this->sharedManager = $sharedEventManager;
$this->setIdentifiers($identifiers);
}
$this->eventPrototype = new Event();
}
/**
* @inheritDoc
*/
public function setEventPrototype(EventInterface $prototype)
{
$this->eventPrototype = $prototype;
}
/**
* Retrieve the shared event manager, if composed.
*
* @return null|SharedEventManagerInterface $sharedEventManager
*/
public function getSharedManager()
{
return $this->sharedManager;
}
/**
* @inheritDoc
*/
public function getIdentifiers()
{
return $this->identifiers;
}
/**
* @inheritDoc
*/
public function setIdentifiers(array $identifiers)
{
$this->identifiers = array_unique($identifiers);
}
/**
* @inheritDoc
*/
public function addIdentifiers(array $identifiers)
{
$this->identifiers = array_unique(array_merge(
$this->identifiers,
$identifiers
));
}
/**
* @inheritDoc
*/
public function trigger($eventName, $target = null, $argv = [])
{
$event = clone $this->eventPrototype;
$event->setName($eventName);
if ($target !== null) {
$event->setTarget($target);
}
if ($argv) {
$event->setParams($argv);
}
return $this->triggerListeners($event);
}
/**
* @inheritDoc
*/
public function triggerUntil(callable $callback, $eventName, $target = null, $argv = [])
{
$event = clone $this->eventPrototype;
$event->setName($eventName);
if ($target !== null) {
$event->setTarget($target);
}
if ($argv) {
$event->setParams($argv);
}
return $this->triggerListeners($event, $callback);
}
/**
* @inheritDoc
*/
public function triggerEvent(EventInterface $event)
{
return $this->triggerListeners($event);
}
/**
* @inheritDoc
*/
public function triggerEventUntil(callable $callback, EventInterface $event)
{
return $this->triggerListeners($event, $callback);
}
/**
* @inheritDoc
*/
public function attach($eventName, callable $listener, $priority = 1)
{
if (! is_string($eventName)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects a string for the event; received %s',
__METHOD__,
(is_object($eventName) ? get_class($eventName) : gettype($eventName))
));
}
$this->events[$eventName][(int) $priority][0][] = $listener;
return $listener;
}
/**
* @inheritDoc
* @throws Exception\InvalidArgumentException for invalid event types.
*/
public function detach(callable $listener, $eventName = null, $force = false)
{
// If event is wildcard, we need to iterate through each listeners
if (null === $eventName || ('*' === $eventName && ! $force)) {
foreach (array_keys($this->events) as $eventName) {
$this->detach($listener, $eventName, true);
}
return;
}
if (! is_string($eventName)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects a string for the event; received %s',
__METHOD__,
(is_object($eventName) ? get_class($eventName) : gettype($eventName))
));
}
if (! isset($this->events[$eventName])) {
return;
}
foreach ($this->events[$eventName] as $priority => $listeners) {
foreach ($listeners[0] as $index => $evaluatedListener) {
if ($evaluatedListener !== $listener) {
continue;
}
// Found the listener; remove it.
unset($this->events[$eventName][$priority][0][$index]);
// If the queue for the given priority is empty, remove it.
if (empty($this->events[$eventName][$priority][0])) {
unset($this->events[$eventName][$priority]);
break;
}
}
}
// If the queue for the given event is empty, remove it.
if (empty($this->events[$eventName])) {
unset($this->events[$eventName]);
}
}
/**
* @inheritDoc
*/
public function clearListeners($eventName)
{
if (isset($this->events[$eventName])) {
unset($this->events[$eventName]);
}
}
/**
* Prepare arguments
*
* Use this method if you want to be able to modify arguments from within a
* listener. It returns an ArrayObject of the arguments, which may then be
* passed to trigger().
*
* @param array $args
* @return ArrayObject
*/
public function prepareArgs(array $args)
{
return new ArrayObject($args);
}
/**
* Trigger listeners
*
* Actual functionality for triggering listeners, to which trigger() delegate.
*
* @param EventInterface $event
* @param null|callable $callback
* @return ResponseCollection
*/
protected function triggerListeners(EventInterface $event, callable $callback = null)
{
$name = $event->getName();
if (empty($name)) {
throw new Exception\RuntimeException('Event is missing a name; cannot trigger!');
}
if (isset($this->events[$name])) {
$listOfListenersByPriority = $this->events[$name];
if (isset($this->events['*'])) {
foreach ($this->events['*'] as $priority => $listOfListeners) {
$listOfListenersByPriority[$priority][] = $listOfListeners[0];
}
}
} elseif (isset($this->events['*'])) {
$listOfListenersByPriority = $this->events['*'];
} else {
$listOfListenersByPriority = [];
}
if ($this->sharedManager) {
foreach ($this->sharedManager->getListeners($this->identifiers, $name) as $priority => $listeners) {
$listOfListenersByPriority[$priority][] = $listeners;
}
}
// Sort by priority in reverse order
krsort($listOfListenersByPriority);
// Initial value of stop propagation flag should be false
$event->stopPropagation(false);
// Execute listeners
$responses = new ResponseCollection();
foreach ($listOfListenersByPriority as $listOfListeners) {
foreach ($listOfListeners as $listeners) {
foreach ($listeners as $listener) {
$response = $listener($event);
$responses->push($response);
// If the event was asked to stop propagating, do so
if ($event->propagationIsStopped()) {
$responses->setStopped(true);
return $responses;
}
// If the result causes our validation callback to return true,
// stop propagation
if ($callback && $callback($response)) {
$responses->setStopped(true);
return $responses;
}
}
}
}
return $responses;
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
/**
* Interface to automate setter injection for an EventManager instance
*/
interface EventManagerAwareInterface extends EventsCapableInterface
{
/**
* Inject an EventManager instance
*
* @param EventManagerInterface $eventManager
* @return void
*/
public function setEventManager(EventManagerInterface $eventManager);
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
use Traversable;
/**
* A trait for objects that provide events.
*
* If you use this trait in an object, you will probably want to also implement
* EventManagerAwareInterface, which will make it so the default initializer in
* a ZF2 MVC application will automatically inject an instance of the
* EventManager into your object when it is pulled from the ServiceManager.
*
* @see Zend\Mvc\Service\ServiceManagerConfig
*/
trait EventManagerAwareTrait
{
/**
* @var EventManagerInterface
*/
protected $events;
/**
* Set the event manager instance used by this context.
*
* For convenience, this method will also set the class name / LSB name as
* identifiers, in addition to any string or array of strings set to the
* $this->eventIdentifier property.
*
* @param EventManagerInterface $events
*/
public function setEventManager(EventManagerInterface $events)
{
$identifiers = [__CLASS__, get_class($this)];
if (isset($this->eventIdentifier)) {
if ((is_string($this->eventIdentifier))
|| (is_array($this->eventIdentifier))
|| ($this->eventIdentifier instanceof Traversable)
) {
$identifiers = array_unique(array_merge($identifiers, (array) $this->eventIdentifier));
} elseif (is_object($this->eventIdentifier)) {
$identifiers[] = $this->eventIdentifier;
}
// silently ignore invalid eventIdentifier types
}
$events->setIdentifiers($identifiers);
$this->events = $events;
if (method_exists($this, 'attachDefaultListeners')) {
$this->attachDefaultListeners();
}
}
/**
* Retrieve the event manager
*
* Lazy-loads an EventManager instance if none registered.
*
* @return EventManagerInterface
*/
public function getEventManager()
{
if (! $this->events instanceof EventManagerInterface) {
$this->setEventManager(new EventManager());
}
return $this->events;
}
}

View File

@@ -0,0 +1,162 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
/**
* Interface for messengers
*/
interface EventManagerInterface extends SharedEventsCapableInterface
{
/**
* Create and trigger an event.
*
* Use this method when you do not want to create an EventInterface
* instance prior to triggering. You will be required to pass:
*
* - the event name
* - the event target (can be null)
* - any event parameters you want to provide (empty array by default)
*
* It will create the Event instance for you and then trigger all listeners
* related to the event.
*
* @param string $eventName
* @param null|object|string $target
* @param array|object $argv
* @return ResponseCollection
*/
public function trigger($eventName, $target = null, $argv = []);
/**
* Create and trigger an event, applying a callback to each listener result.
*
* Use this method when you do not want to create an EventInterface
* instance prior to triggering. You will be required to pass:
*
* - the event name
* - the event target (can be null)
* - any event parameters you want to provide (empty array by default)
*
* It will create the Event instance for you, and trigger all listeners
* related to the event.
*
* The result of each listener is passed to $callback; if $callback returns
* a boolean true value, the manager must short-circuit listener execution.
*
* @param callable $callback
* @param string $eventName
* @param null|object|string $target
* @param array|object $argv
* @return ResponseCollection
*/
public function triggerUntil(callable $callback, $eventName, $target = null, $argv = []);
/**
* Trigger an event
*
* Provided an EventInterface instance, this method will trigger listeners
* based on the event name, raising an exception if the event name is missing.
*
* @param EventInterface $event
* @return ResponseCollection
*/
public function triggerEvent(EventInterface $event);
/**
* Trigger an event, applying a callback to each listener result.
*
* Provided an EventInterface instance, this method will trigger listeners
* based on the event name, raising an exception if the event name is missing.
*
* The result of each listener is passed to $callback; if $callback returns
* a boolean true value, the manager must short-circuit listener execution.
*
* @param callable $callback
* @param EventInterface $event
* @return ResponseCollection
*/
public function triggerEventUntil(callable $callback, EventInterface $event);
/**
* Attach a listener to an event
*
* The first argument is the event, and the next argument is a
* callable that will respond to that event.
*
* The last argument indicates a priority at which the event should be
* executed; by default, this value is 1; however, you may set it for any
* integer value. Higher values have higher priority (i.e., execute first).
*
* You can specify "*" for the event name. In such cases, the listener will
* be triggered for every event *that has registered listeners at the time
* it is attached*. As such, register wildcard events last whenever possible!
*
* @param string $eventName Event to which to listen.
* @param callable $listener
* @param int $priority Priority at which to register listener.
* @return callable
*/
public function attach($eventName, callable $listener, $priority = 1);
/**
* Detach a listener.
*
* If no $event or '*' is provided, detaches listener from all events;
* otherwise, detaches only from the named event.
*
* @param callable $listener
* @param null|string $eventName Event from which to detach; null and '*'
* indicate all events.
* @return void
*/
public function detach(callable $listener, $eventName = null);
/**
* Clear all listeners for a given event
*
* @param string $eventName
* @return void
*/
public function clearListeners($eventName);
/**
* Provide an event prototype to use with trigger().
*
* When `trigger()` needs to create an event instance, it should clone the
* prototype provided to this method.
*
* @param EventInterface $prototype
* @return void
*/
public function setEventPrototype(EventInterface $prototype);
/**
* Get the identifier(s) for this EventManager
*
* @return array
*/
public function getIdentifiers();
/**
* Set the identifiers (overrides any currently set identifiers)
*
* @param string[] $identifiers
* @return void
*/
public function setIdentifiers(array $identifiers);
/**
* Add identifier(s) (appends to any currently set identifiers)
*
* @param string[] $identifiers
* @return void
*/
public function addIdentifiers(array $identifiers);
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
/**
* Interface indicating that an object composes an EventManagerInterface instance.
*/
interface EventsCapableInterface
{
/**
* Retrieve the event manager
*
* Lazy-loads an EventManager instance if none registered.
*
* @return EventManagerInterface
*/
public function getEventManager();
}

View File

@@ -0,0 +1,14 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager\Exception;
class DomainException extends \DomainException implements ExceptionInterface
{
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager\Exception;
/**
* Base exception interface
*/
interface ExceptionInterface
{
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager\Exception;
/**
* Invalid argument exception
*/
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager\Exception;
/**
* Invalid callback exception
*/
class InvalidCallbackException extends DomainException implements ExceptionInterface
{
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager\Exception;
use RuntimeException as SplRuntimeException;
class RuntimeException extends SplRuntimeException implements ExceptionInterface
{
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager\Filter;
use Zend\EventManager\ResponseCollection;
/**
* Interface for intercepting filter chains
*/
interface FilterInterface
{
/**
* Execute the filter chain
*
* @param string|object $context
* @param array $params
* @return mixed
*/
public function run($context, array $params = []);
/**
* Attach an intercepting filter
*
* @param callable $callback
*/
public function attach(callable $callback);
/**
* Detach an intercepting filter
*
* @param callable $filter
* @return bool
*/
public function detach(callable $filter);
/**
* Get all intercepting filters
*
* @return array
*/
public function getFilters();
/**
* Clear all filters
*
* @return void
*/
public function clearFilters();
/**
* Get all filter responses
*
* @return ResponseCollection
*/
public function getResponses();
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager\Filter;
use Zend\EventManager\Exception;
use Zend\Stdlib\FastPriorityQueue;
/**
* Specialized priority queue implementation for use with an intercepting
* filter chain.
*
* Allows removal
*/
class FilterIterator extends FastPriorityQueue
{
/**
* Does the queue contain a given value?
*
* @param mixed $datum
* @return bool
*/
public function contains($datum)
{
foreach ($this as $item) {
if ($item === $datum) {
return true;
}
}
return false;
}
/**
* Insert a value into the queue.
*
* Requires a callable.
*
* @param callable $value
* @param mixed $priority
* @return void
* @throws Exception\InvalidArgumentException for non-callable $value.
*/
public function insert($value, $priority)
{
if (! is_callable($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s can only aggregate callables; received %s',
__CLASS__,
(is_object($value) ? get_class($value) : gettype($value))
));
}
parent::insert($value, $priority);
}
/**
* Remove a value from the queue
*
* This is an expensive operation. It must first iterate through all values,
* and then re-populate itself. Use only if absolutely necessary.
*
* @param mixed $datum
* @return bool
*/
public function remove($datum)
{
$this->setExtractFlags(self::EXTR_BOTH);
// Iterate and remove any matches
$removed = false;
$items = [];
$this->rewind();
while (! $this->isEmpty()) {
$item = $this->extract();
if ($item['data'] === $datum) {
$removed = true;
continue;
}
$items[] = $item;
}
// Repopulate
foreach ($items as $item) {
$this->insert($item['data'], $item['priority']);
}
$this->setExtractFlags(self::EXTR_DATA);
return $removed;
}
/**
* Iterate the next filter in the chain
*
* Iterates and calls the next filter in the chain.
*
* @param mixed $context
* @param array $params
* @param FilterIterator $chain
* @return mixed
*/
public function next($context = null, array $params = [], $chain = null)
{
if (empty($context) || ($chain instanceof FilterIterator && $chain->isEmpty())) {
return;
}
//We can't extract from an empty heap
if ($this->isEmpty()) {
return;
}
$next = $this->extract();
return $next($context, $params, $chain);
}
}

View File

@@ -0,0 +1,112 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
/**
* FilterChain: intercepting filter manager
*/
class FilterChain implements Filter\FilterInterface
{
/**
* @var Filter\FilterIterator All filters
*/
protected $filters;
/**
* Constructor
*
* Initializes Filter\FilterIterator in which filters will be aggregated
*/
public function __construct()
{
$this->filters = new Filter\FilterIterator();
}
/**
* Apply the filters
*
* Begins iteration of the filters.
*
* @param mixed $context Object under observation
* @param mixed $argv Associative array of arguments
* @return mixed
*/
public function run($context, array $argv = [])
{
$chain = clone $this->getFilters();
if ($chain->isEmpty()) {
return;
}
$next = $chain->extract();
return $next($context, $argv, $chain);
}
/**
* Connect a filter to the chain
*
* @param callable $callback PHP Callback
* @param int $priority Priority in the queue at which to execute;
* defaults to 1 (higher numbers == higher priority)
* @return CallbackHandler (to allow later unsubscribe)
* @throws Exception\InvalidCallbackException
*/
public function attach(callable $callback, $priority = 1)
{
$this->filters->insert($callback, $priority);
return $callback;
}
/**
* Detach a filter from the chain
*
* @param callable $filter
* @return bool Returns true if filter found and unsubscribed; returns false otherwise
*/
public function detach(callable $filter)
{
return $this->filters->remove($filter);
}
/**
* Retrieve all filters
*
* @return Filter\FilterIterator
*/
public function getFilters()
{
return $this->filters;
}
/**
* Clear all filters
*
* @return void
*/
public function clearFilters()
{
$this->filters = new Filter\FilterIterator();
}
/**
* Return current responses
*
* Only available while the chain is still being iterated. Returns the
* current ResponseCollection.
*
* @return null|ResponseCollection
*/
public function getResponses()
{
return;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
use Interop\Container\ContainerInterface;
/**
* Lazy listener instance for use with LazyListenerAggregate.
*
* Used as an internal class for the LazyAggregate to allow lazy creation of
* listeners via a dependency injection container.
*
* Lazy event listener definitions add the following members to what the
* LazyListener accepts:
*
* - event: the event name to attach to.
* - priority: the priority at which to attach the listener, if not the default.
*/
class LazyEventListener extends LazyListener
{
/**
* @var string Event name to which to attach.
*/
private $event;
/**
* @var null|int Priority at which to attach.
*/
private $priority;
/**
* @param array $definition
* @param ContainerInterface $container
* @param array $env
*/
public function __construct(array $definition, ContainerInterface $container, array $env = [])
{
parent::__construct($definition, $container, $env);
if ((! isset($definition['event'])
|| ! is_string($definition['event'])
|| empty($definition['event']))
) {
throw new Exception\InvalidArgumentException(
'Lazy listener definition is missing a valid "event" member; cannot create LazyListener'
);
}
$this->event = $definition['event'];
$this->priority = isset($definition['priority']) ? (int) $definition['priority'] : null;
}
/**
* @return string
*/
public function getEvent()
{
return $this->event;
}
/**
* @return int
*/
public function getPriority($default = 1)
{
return (null !== $this->priority) ? $this->priority : $default;
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
use Interop\Container\ContainerInterface;
/**
* Lazy listener instance.
*
* Used to allow lazy creation of listeners via a dependency injection
* container.
*
* Lazy listener definitions have the following members:
*
* - listener: the service name of the listener to use.
* - method: the method name of the listener to invoke for the specified event.
*
* If desired, you can pass $env at instantiation; this will be passed to the
* container's `build()` method, if it has one, when creating the listener
* instance.
*
* Pass instances directly to the event manager's `attach()` method as the
* listener argument.
*/
class LazyListener
{
/**
* @var ContainerInterface Container from which to pull listener.
*/
private $container;
/**
* @var array Variables/options to use during service creation, if any.
*/
private $env;
/**
* @var callable Marshaled listener callback.
*/
private $listener;
/**
* @var string Method name to invoke on listener.
*/
private $method;
/**
* @var string Service name of listener.
*/
private $service;
/**
* @param array $definition
* @param ContainerInterface $container
* @param array $env
*/
public function __construct(array $definition, ContainerInterface $container, array $env = [])
{
if ((! isset($definition['listener'])
|| ! is_string($definition['listener'])
|| empty($definition['listener']))
) {
throw new Exception\InvalidArgumentException(
'Lazy listener definition is missing a valid "listener" member; cannot create LazyListener'
);
}
if ((! isset($definition['method'])
|| ! is_string($definition['method'])
|| empty($definition['method']))
) {
throw new Exception\InvalidArgumentException(
'Lazy listener definition is missing a valid "method" member; cannot create LazyListener'
);
}
$this->service = $definition['listener'];
$this->method = $definition['method'];
$this->container = $container;
$this->env = $env;
}
/**
* Use the listener as an invokable, allowing direct attachment to an event manager.
*
* @param EventInterface $event
* @return callable
*/
public function __invoke(EventInterface $event)
{
$listener = $this->fetchListener();
$method = $this->method;
return $listener->{$method}($event);
}
/**
* @return callable
*/
private function fetchListener()
{
if ($this->listener) {
return $this->listener;
}
// In the future, typehint against Zend\ServiceManager\ServiceLocatorInterface,
// which defines this message starting in v3.
if (method_exists($this->container, 'build') && ! empty($this->env)) {
$this->listener = $this->container->build($this->service, $this->env);
return $this->listener;
}
$this->listener = $this->container->get($this->service);
return $this->listener;
}
}

View File

@@ -0,0 +1,110 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
use Interop\Container\ContainerInterface;
/**
* Aggregate listener for attaching lazy listeners.
*
* Lazy listeners are listeners where creation is deferred until they are
* triggered; this removes the most costly mechanism of pulling a listener
* from a container unless the listener is actually invoked.
*
* Usage is:
*
* <code>
* $events->attachAggregate(new LazyListenerAggregate(
* $lazyEventListenersOrDefinitions,
* $container
* ));
* </code>
*/
class LazyListenerAggregate implements ListenerAggregateInterface
{
use ListenerAggregateTrait;
/**
* @var ContainerInterface Container from which to pull lazy listeners.
*/
private $container;
/**
* @var array Additional environment/option variables to use when creating listener.
*/
private $env;
/**
* Generated LazyEventListener instances.
*
* @var LazyEventListener[]
*/
private $lazyListeners = [];
/**
* Constructor
*
* Accepts the composed $listeners, as well as the $container and $env in
* order to create a listener aggregate that defers listener creation until
* the listener is triggered.
*
* Listeners may be either LazyEventListener instances, or lazy event
* listener definitions that can be provided to a LazyEventListener
* constructor in order to create a new instance; in the latter case, the
* $container and $env will be passed at instantiation as well.
*
* @var array $listeners LazyEventListener instances or array definitions
* to pass to the LazyEventListener constructor.
* @var ContainerInterface $container
* @var array $env
* @throws Exception\InvalidArgumentException for invalid listener items.
*/
public function __construct(array $listeners, ContainerInterface $container, array $env = [])
{
$this->container = $container;
$this->env = $env;
// This would raise an exception for invalid structs
foreach ($listeners as $listener) {
if (is_array($listener)) {
$listener = new LazyEventListener($listener, $container, $env);
}
if (! $listener instanceof LazyEventListener) {
throw new Exception\InvalidArgumentException(sprintf(
'All listeners must be LazyEventListener instances or definitions; received %s',
(is_object($listener) ? get_class($listener) : gettype($listener))
));
}
$this->lazyListeners[] = $listener;
}
}
/**
* Attach the aggregate to the event manager.
*
* Loops through all composed lazy listeners, and attaches them to the
* event manager.
*
* @var EventManagerInterface $events
* @var int $priority
*/
public function attach(EventManagerInterface $events, $priority = 1)
{
foreach ($this->lazyListeners as $lazyListener) {
$this->listeners[] = $events->attach(
$lazyListener->getEvent(),
$lazyListener,
$lazyListener->getPriority($priority)
);
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
/**
* Interface for self-registering event listeners.
*
* Classes implementing this interface may be registered by name or instance
* with an EventManager, without an event name. The {@link attach()} method will
* then be called with the current EventManager instance, allowing the class to
* wire up one or more listeners.
*/
interface ListenerAggregateInterface
{
/**
* Attach one or more listeners
*
* Implementors may add an optional $priority argument; the EventManager
* implementation will pass this to the aggregate.
*
* @param EventManagerInterface $events
* @param int $priority
* @return void
*/
public function attach(EventManagerInterface $events, $priority = 1);
/**
* Detach all previously attached listeners
*
* @param EventManagerInterface $events
* @return void
*/
public function detach(EventManagerInterface $events);
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
/**
* Provides logic to easily create aggregate listeners, without worrying about
* manually detaching events
*/
trait ListenerAggregateTrait
{
/**
* @var callable[]
*/
protected $listeners = [];
/**
* {@inheritDoc}
*/
public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $index => $callback) {
$events->detach($callback);
unset($this->listeners[$index]);
}
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
use SplStack;
/**
* Collection of signal handler return values
*/
class ResponseCollection extends SplStack
{
protected $stopped = false;
/**
* Did the last response provided trigger a short circuit of the stack?
*
* @return bool
*/
public function stopped()
{
return $this->stopped;
}
/**
* Mark the collection as stopped (or its opposite)
*
* @param bool $flag
*/
public function setStopped($flag)
{
$this->stopped = (bool) $flag;
}
/**
* Convenient access to the first handler return value.
*
* @return mixed The first handler return value
*/
public function first()
{
return parent::bottom();
}
/**
* Convenient access to the last handler return value.
*
* If the collection is empty, returns null. Otherwise, returns value
* returned by last handler.
*
* @return mixed The last handler return value
*/
public function last()
{
if (count($this) === 0) {
return;
}
return parent::top();
}
/**
* Check if any of the responses match the given value.
*
* @param mixed $value The value to look for among responses
* @return bool
*/
public function contains($value)
{
foreach ($this as $response) {
if ($response === $value) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,235 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
/**
* Shared/contextual EventManager
*
* Allows attaching to EMs composed by other classes without having an instance first.
* The assumption is that the SharedEventManager will be injected into EventManager
* instances, and then queried for additional listeners when triggering an event.
*/
class SharedEventManager implements SharedEventManagerInterface
{
/**
* Identifiers with event connections
* @var array
*/
protected $identifiers = [];
/**
* Attach a listener to an event emitted by components with specific identifiers.
*
* Allows attaching a listener to an event offered by an identifying
* components. As an example, the following connects to the "getAll" event
* of both an AbstractResource and EntityResource:
*
* <code>
* $sharedEventManager = new SharedEventManager();
* foreach (['My\Resource\AbstractResource', 'My\Resource\EntityResource'] as $identifier) {
* $sharedEventManager->attach(
* $identifier,
* 'getAll',
* function ($e) use ($cache) {
* if (!$id = $e->getParam('id', false)) {
* return;
* }
* if (!$data = $cache->load(get_class($resource) . '::getOne::' . $id )) {
* return;
* }
* return $data;
* }
* );
* }
* </code>
*
* @param string $identifier Identifier for event emitting component.
* @param string $event
* @param callable $listener Listener that will handle the event.
* @param int $priority Priority at which listener should execute
* @return void
* @throws Exception\InvalidArgumentException for invalid identifier arguments.
* @throws Exception\InvalidArgumentException for invalid event arguments.
*/
public function attach($identifier, $event, callable $listener, $priority = 1)
{
if (! is_string($identifier) || empty($identifier)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid identifier provided; must be a string; received "%s"',
(is_object($identifier) ? get_class($identifier) : gettype($identifier))
));
}
if (! is_string($event) || empty($event)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid event provided; must be a non-empty string; received "%s"',
(is_object($event) ? get_class($event) : gettype($event))
));
}
$this->identifiers[$identifier][$event][(int) $priority][] = $listener;
}
/**
* @inheritDoc
*/
public function detach(callable $listener, $identifier = null, $eventName = null, $force = false)
{
// No identifier or wildcard identifier: loop through all identifiers and detach
if (null === $identifier || ('*' === $identifier && ! $force)) {
foreach (array_keys($this->identifiers) as $identifier) {
$this->detach($listener, $identifier, $eventName, true);
}
return;
}
if (! is_string($identifier) || empty($identifier)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid identifier provided; must be a string, received %s',
(is_object($identifier) ? get_class($identifier) : gettype($identifier))
));
}
// Do we have any listeners on the provided identifier?
if (! isset($this->identifiers[$identifier])) {
return;
}
if (null === $eventName || ('*' === $eventName && ! $force)) {
foreach (array_keys($this->identifiers[$identifier]) as $eventName) {
$this->detach($listener, $identifier, $eventName, true);
}
return;
}
if (! is_string($eventName) || empty($eventName)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid event name provided; must be a string, received %s',
(is_object($eventName) ? get_class($eventName) : gettype($eventName))
));
}
if (! isset($this->identifiers[$identifier][$eventName])) {
return;
}
foreach ($this->identifiers[$identifier][$eventName] as $priority => $listeners) {
foreach ($listeners as $index => $evaluatedListener) {
if ($evaluatedListener !== $listener) {
continue;
}
// Found the listener; remove it.
unset($this->identifiers[$identifier][$eventName][$priority][$index]);
// Is the priority queue empty?
if (empty($this->identifiers[$identifier][$eventName][$priority])) {
unset($this->identifiers[$identifier][$eventName][$priority]);
break;
}
}
// Is the event queue empty?
if (empty($this->identifiers[$identifier][$eventName])) {
unset($this->identifiers[$identifier][$eventName]);
break;
}
}
// Is the identifier queue now empty? Remove it.
if (empty($this->identifiers[$identifier])) {
unset($this->identifiers[$identifier]);
}
}
/**
* Retrieve all listeners for a given identifier and event
*
* @param string[] $identifiers
* @param string $eventName
* @return array[]
* @throws Exception\InvalidArgumentException
*/
public function getListeners(array $identifiers, $eventName)
{
if ('*' === $eventName || ! is_string($eventName) || empty($eventName)) {
throw new Exception\InvalidArgumentException(sprintf(
'Event name passed to %s must be a non-empty, non-wildcard string',
__METHOD__
));
}
$returnListeners = [];
foreach ($identifiers as $identifier) {
if ('*' === $identifier || ! is_string($identifier) || empty($identifier)) {
throw new Exception\InvalidArgumentException(sprintf(
'Identifier names passed to %s must be non-empty, non-wildcard strings',
__METHOD__
));
}
if (isset($this->identifiers[$identifier])) {
$listenersByIdentifier = $this->identifiers[$identifier];
if (isset($listenersByIdentifier[$eventName])) {
foreach ($listenersByIdentifier[$eventName] as $priority => $listeners) {
$returnListeners[$priority][] = $listeners;
}
}
if (isset($listenersByIdentifier['*'])) {
foreach ($listenersByIdentifier['*'] as $priority => $listeners) {
$returnListeners[$priority][] = $listeners;
}
}
}
}
if (isset($this->identifiers['*'])) {
$wildcardIdentifier = $this->identifiers['*'];
if (isset($wildcardIdentifier[$eventName])) {
foreach ($wildcardIdentifier[$eventName] as $priority => $listeners) {
$returnListeners[$priority][] = $listeners;
}
}
if (isset($wildcardIdentifier['*'])) {
foreach ($wildcardIdentifier['*'] as $priority => $listeners) {
$returnListeners[$priority][] = $listeners;
}
}
}
foreach ($returnListeners as $priority => $listOfListeners) {
$returnListeners[$priority] = array_merge(...$listOfListeners);
}
return $returnListeners;
}
/**
* @inheritDoc
*/
public function clearListeners($identifier, $eventName = null)
{
if (! isset($this->identifiers[$identifier])) {
return false;
}
if (null === $eventName) {
unset($this->identifiers[$identifier]);
return;
}
if (! isset($this->identifiers[$identifier][$eventName])) {
return;
}
unset($this->identifiers[$identifier][$eventName]);
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
/**
* Interface for shared event listener collections
*/
interface SharedEventManagerInterface
{
/**
* Attach a listener to an event emitted by components with specific identifiers.
*
* @param string $identifier Identifier for event emitting component
* @param string $eventName
* @param callable $listener Listener that will handle the event.
* @param int $priority Priority at which listener should execute
*/
public function attach($identifier, $eventName, callable $listener, $priority = 1);
/**
* Detach a shared listener.
*
* Allows detaching a listener from one or more events to which it may be
* attached.
*
* @param callable $listener Listener to detach.
* @param null|string $identifier Identifier from which to detach; null indicates
* all registered identifiers.
* @param null|string $eventName Event from which to detach; null indicates
* all registered events.
* @throws Exception\InvalidArgumentException for invalid identifier arguments.
* @throws Exception\InvalidArgumentException for invalid event arguments.
*/
public function detach(callable $listener, $identifier = null, $eventName = null);
/**
* Retrieve all listeners for given identifiers
*
* @param array $identifiers
* @param string $eventName
* @return array
*/
public function getListeners(array $identifiers, $eventName);
/**
* Clear all listeners for a given identifier, optionally for a specific event
*
* @param string $identifier
* @param null|string $eventName
*/
public function clearListeners($identifier, $eventName = null);
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager;
/**
* Interface indicating that an object composes or can compose a
* SharedEventManagerInterface instance.
*/
interface SharedEventsCapableInterface
{
/**
* Retrieve the shared event manager, if composed.
*
* @return null|SharedEventManagerInterface
*/
public function getSharedManager();
}

View File

@@ -0,0 +1,152 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
*/
namespace Zend\EventManager\Test;
use PHPUnit\Framework\Assert;
use ReflectionProperty;
use Zend\EventManager\EventManager;
/**
* Trait providing utility methods and assertions for use in PHPUnit test cases.
*
* This trait may be composed into a test case, and provides:
*
* - methods for introspecting events and listeners
* - methods for asserting listeners are attached at a specific priority
*
* Some functionality in this trait duplicates functionality present in the
* version 2 EventManagerInterface and/or EventManager implementation, but
* abstracts that functionality for use in v3. As such, components or code
* that is testing for listener registration should use the methods in this
* trait to ensure tests are forwards-compatible between zend-eventmanager
* versions.
*/
trait EventListenerIntrospectionTrait
{
/**
* Retrieve a list of event names from an event manager.
*
* @param EventManager $events
* @return string[]
*/
private function getEventsFromEventManager(EventManager $events)
{
$r = new ReflectionProperty($events, 'events');
$r->setAccessible(true);
$listeners = $r->getValue($events);
return array_keys($listeners);
}
/**
* Retrieve an interable list of listeners for an event.
*
* Given an event and an event manager, returns an iterator with the
* listeners for that event, in priority order.
*
* If $withPriority is true, the key values will be the priority at which
* the given listener is attached.
*
* Do not pass $withPriority if you want to cast the iterator to an array,
* as many listeners will likely have the same priority, and thus casting
* will collapse to the last added.
*
* @param string $event
* @param EventManager $events
* @param bool $withPriority
* @return \Traversable
*/
private function getListenersForEvent($event, EventManager $events, $withPriority = false)
{
$r = new ReflectionProperty($events, 'events');
$r->setAccessible(true);
$internal = $r->getValue($events);
$listeners = [];
foreach (isset($internal[$event]) ? $internal[$event] : [] as $p => $listOfListeners) {
foreach ($listOfListeners as $l) {
$listeners[$p] = isset($listeners[$p]) ? array_merge($listeners[$p], $l) : $l;
}
}
return $this->traverseListeners($listeners, $withPriority);
}
/**
* Assert that a given listener exists at the specified priority.
*
* @param callable $expectedListener
* @param int $expectedPriority
* @param string $event
* @param EventManager $events
* @param string $message Failure message to use, if any.
*/
private function assertListenerAtPriority(
callable $expectedListener,
$expectedPriority,
$event,
EventManager $events,
$message = ''
) {
$message = $message ?: sprintf(
'Listener not found for event "%s" and priority %d',
$event,
$expectedPriority
);
$listeners = $this->getListenersForEvent($event, $events, true);
$found = false;
foreach ($listeners as $priority => $listener) {
if ($listener === $expectedListener
&& $priority === $expectedPriority
) {
$found = true;
break;
}
}
Assert::assertTrue($found, $message);
}
/**
* Returns an indexed array of listeners for an event.
*
* Returns an indexed array of listeners for an event, in priority order.
* Priority values will not be included; use this only for testing if
* specific listeners are present, or for a count of listeners.
*
* @param string $event
* @param EventManager $events
* @return callable[]
*/
private function getArrayOfListenersForEvent($event, EventManager $events)
{
return iterator_to_array($this->getListenersForEvent($event, $events));
}
/**
* Generator for traversing listeners in priority order.
*
* @param array $listeners
* @param bool $withPriority When true, yields priority as key.
*/
public function traverseListeners(array $queue, $withPriority = false)
{
krsort($queue, SORT_NUMERIC);
foreach ($queue as $priority => $listeners) {
$priority = (int) $priority;
foreach ($listeners as $listener) {
if ($withPriority) {
yield $priority => $listener;
} else {
yield $listener;
}
}
}
}
}