-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from pantheon-systems/cms-399-psr14-bridge
Add Psr14Bridge class in search_api_pantheon.
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
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
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,35 @@ | ||
<?php | ||
|
||
namespace Drupal\search_api_pantheon\Solarium\EventDispatcher; | ||
|
||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
/** | ||
* A proxy for events defined by symfony contracts to be used with older Drupal. | ||
*/ | ||
class EventProxy extends Event { | ||
/** | ||
* @var \Symfony\Contracts\EventDispatcher\Event | ||
*/ | ||
protected $event; | ||
|
||
public function __construct($event) { | ||
$this->event = $event; | ||
} | ||
|
||
public function isPropagationStopped() { | ||
return $this->event->isPropagationStopped(); | ||
} | ||
|
||
public function stopPropagation() { | ||
$this->event->stopPropagation(); | ||
} | ||
|
||
/** | ||
* Proxies all method calls to the original event. | ||
*/ | ||
public function __call($method, $arguments) { | ||
return $this->event->{$method}(...$arguments); | ||
} | ||
|
||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace Drupal\search_api_pantheon\Solarium\EventDispatcher; | ||
|
||
use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher; | ||
use Psr\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
/** | ||
* A helper to decorate the legacy EventDispatcherInterface::dispatch(). | ||
*/ | ||
final class Psr14Bridge extends ContainerAwareEventDispatcher implements EventDispatcherInterface { | ||
|
||
/** | ||
* @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher | ||
*/ | ||
protected $dispatcher; | ||
|
||
public function __construct(ContainerAwareEventDispatcher $eventDispatcher) { | ||
$this->dispatcher = $eventDispatcher; | ||
} | ||
|
||
public function dispatch($event, Event $null = NULL) { | ||
if (\is_object($event)) { | ||
return $this->dispatcher->dispatch(\get_class($event), new EventProxy($event)); | ||
} | ||
return $this->dispatcher->dispatch($event, $null); | ||
} | ||
|
||
public function addListener($event_name, $listener, $priority = 0) { | ||
$this->dispatcher->addListener($event_name, $listener, $priority); | ||
} | ||
|
||
} |