This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/event-traits' of https://github.com/EvanDotPro/zf2
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_EventManager | ||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
/** | ||
* @namespace | ||
*/ | ||
namespace Zend\EventManager; | ||
|
||
use Traversable; | ||
|
||
/** | ||
* A trait for objects that provide events | ||
* | ||
* @category Zend | ||
* @package Zend_EventManager | ||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
trait ProvidesEvents | ||
{ | ||
/** | ||
* @var EventCollection | ||
*/ | ||
protected $events; | ||
|
||
/** | ||
* Set the event manager instance used by this context | ||
* | ||
* @param EventCollection $events | ||
* @return mixed | ||
*/ | ||
public function setEventManager(EventCollection $events) | ||
{ | ||
$this->events = $events; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Retrieve the event manager | ||
* | ||
* Lazy-loads an EventManager instance if none registered. | ||
* | ||
* @return EventCollection | ||
*/ | ||
public function events() | ||
{ | ||
if (!$this->events instanceof EventCollection) { | ||
$identifiers = array(__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 | ||
} | ||
$this->setEventManager(new EventManager($identifiers)); | ||
} | ||
return $this->events; | ||
} | ||
} |