Remove unused private ForwardEmitter and LegacyEmittertags/v21.0.0beta1
@@ -1117,8 +1117,6 @@ return array( | |||
'OC\\Hooks\\BasicEmitter' => $baseDir . '/lib/private/Hooks/BasicEmitter.php', | |||
'OC\\Hooks\\Emitter' => $baseDir . '/lib/private/Hooks/Emitter.php', | |||
'OC\\Hooks\\EmitterTrait' => $baseDir . '/lib/private/Hooks/EmitterTrait.php', | |||
'OC\\Hooks\\ForwardingEmitter' => $baseDir . '/lib/private/Hooks/ForwardingEmitter.php', | |||
'OC\\Hooks\\LegacyEmitter' => $baseDir . '/lib/private/Hooks/LegacyEmitter.php', | |||
'OC\\Hooks\\PublicEmitter' => $baseDir . '/lib/private/Hooks/PublicEmitter.php', | |||
'OC\\Http\\Client\\Client' => $baseDir . '/lib/private/Http/Client/Client.php', | |||
'OC\\Http\\Client\\ClientService' => $baseDir . '/lib/private/Http/Client/ClientService.php', |
@@ -1146,8 +1146,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c | |||
'OC\\Hooks\\BasicEmitter' => __DIR__ . '/../../..' . '/lib/private/Hooks/BasicEmitter.php', | |||
'OC\\Hooks\\Emitter' => __DIR__ . '/../../..' . '/lib/private/Hooks/Emitter.php', | |||
'OC\\Hooks\\EmitterTrait' => __DIR__ . '/../../..' . '/lib/private/Hooks/EmitterTrait.php', | |||
'OC\\Hooks\\ForwardingEmitter' => __DIR__ . '/../../..' . '/lib/private/Hooks/ForwardingEmitter.php', | |||
'OC\\Hooks\\LegacyEmitter' => __DIR__ . '/../../..' . '/lib/private/Hooks/LegacyEmitter.php', | |||
'OC\\Hooks\\PublicEmitter' => __DIR__ . '/../../..' . '/lib/private/Hooks/PublicEmitter.php', | |||
'OC\\Http\\Client\\Client' => __DIR__ . '/../../..' . '/lib/private/Http/Client/Client.php', | |||
'OC\\Http\\Client\\ClientService' => __DIR__ . '/../../..' . '/lib/private/Http/Client/ClientService.php', |
@@ -1,66 +0,0 @@ | |||
<?php | |||
/** | |||
* @copyright Copyright (c) 2016, ownCloud, Inc. | |||
* | |||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | |||
* @author Morris Jobke <hey@morrisjobke.de> | |||
* @author Robin Appelman <robin@icewind.nl> | |||
* | |||
* @license AGPL-3.0 | |||
* | |||
* This code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License, version 3, | |||
* as published by the Free Software Foundation. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License, version 3, | |||
* along with this program. If not, see <http://www.gnu.org/licenses/> | |||
* | |||
*/ | |||
namespace OC\Hooks; | |||
/** | |||
* Class ForwardingEmitter | |||
* | |||
* allows forwarding all listen calls to other emitters | |||
* | |||
* @package OC\Hooks | |||
*/ | |||
abstract class ForwardingEmitter extends BasicEmitter { | |||
/** | |||
* @var \OC\Hooks\Emitter[] array | |||
*/ | |||
private $forwardEmitters = []; | |||
/** | |||
* @param string $scope | |||
* @param string $method | |||
* @param callable $callback | |||
*/ | |||
public function listen($scope, $method, callable $callback) { | |||
parent::listen($scope, $method, $callback); | |||
foreach ($this->forwardEmitters as $emitter) { | |||
$emitter->listen($scope, $method, $callback); | |||
} | |||
} | |||
/** | |||
* @param \OC\Hooks\Emitter $emitter | |||
*/ | |||
protected function forward(Emitter $emitter) { | |||
$this->forwardEmitters[] = $emitter; | |||
//forward all previously connected hooks | |||
foreach ($this->listeners as $key => $listeners) { | |||
list($scope, $method) = explode('::', $key, 2); | |||
foreach ($listeners as $listener) { | |||
$emitter->listen($scope, $method, $listener); | |||
} | |||
} | |||
} | |||
} |
@@ -1,40 +0,0 @@ | |||
<?php | |||
/** | |||
* @copyright Copyright (c) 2016, ownCloud, Inc. | |||
* | |||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | |||
* @author Lukas Reschke <lukas@statuscode.ch> | |||
* @author Morris Jobke <hey@morrisjobke.de> | |||
* @author Robin Appelman <robin@icewind.nl> | |||
* | |||
* @license AGPL-3.0 | |||
* | |||
* This code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License, version 3, | |||
* as published by the Free Software Foundation. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License, version 3, | |||
* along with this program. If not, see <http://www.gnu.org/licenses/> | |||
* | |||
*/ | |||
namespace OC\Hooks; | |||
abstract class LegacyEmitter extends BasicEmitter { | |||
/** | |||
* @param string $scope | |||
* @param string $method | |||
* @param array $arguments | |||
* | |||
* @suppress PhanAccessMethodProtected | |||
*/ | |||
protected function emit($scope, $method, array $arguments = []) { | |||
\OC_Hook::emit($scope, $method, $arguments); | |||
parent::emit($scope, $method, $arguments); | |||
} | |||
} |
@@ -1,75 +0,0 @@ | |||
<?php | |||
/** | |||
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> | |||
* This file is licensed under the Affero General Public License version 3 or | |||
* later. | |||
* See the COPYING-README file. | |||
*/ | |||
namespace Test\Hooks; | |||
use OC\Hooks\PublicEmitter; | |||
class DummyForwardingEmitter extends \OC\Hooks\ForwardingEmitter { | |||
public function emitEvent($scope, $method, $arguments = []) { | |||
$this->emit($scope, $method, $arguments); | |||
} | |||
/** | |||
* @param \OC\Hooks\Emitter $emitter | |||
*/ | |||
public function forward(\OC\Hooks\Emitter $emitter) { | |||
parent::forward($emitter); | |||
} | |||
} | |||
/** | |||
* Class ForwardingEmitter | |||
* | |||
* allows forwarding all listen calls to other emitters | |||
* | |||
* @package OC\Hooks | |||
*/ | |||
class ForwardingEmitterTest extends BasicEmitterTest { | |||
public function testSingleForward() { | |||
$baseEmitter = new PublicEmitter(); | |||
$forwardingEmitter = new DummyForwardingEmitter(); | |||
$forwardingEmitter->forward($baseEmitter); | |||
$hookCalled = false; | |||
$forwardingEmitter->listen('Test', 'test', function () use (&$hookCalled) { | |||
$hookCalled = true; | |||
}); | |||
$baseEmitter->emit('Test', 'test'); | |||
$this->assertTrue($hookCalled); | |||
} | |||
public function testMultipleForwards() { | |||
$baseEmitter1 = new PublicEmitter(); | |||
$baseEmitter2 = new PublicEmitter(); | |||
$forwardingEmitter = new DummyForwardingEmitter(); | |||
$forwardingEmitter->forward($baseEmitter1); | |||
$forwardingEmitter->forward($baseEmitter2); | |||
$hookCalled = 0; | |||
$forwardingEmitter->listen('Test', 'test1', function () use (&$hookCalled) { | |||
$hookCalled++; | |||
}); | |||
$forwardingEmitter->listen('Test', 'test2', function () use (&$hookCalled) { | |||
$hookCalled++; | |||
}); | |||
$baseEmitter1->emit('Test', 'test1'); | |||
$baseEmitter1->emit('Test', 'test2'); | |||
$this->assertEquals(2, $hookCalled); | |||
} | |||
public function testForwardExistingHooks() { | |||
$baseEmitter = new PublicEmitter(); | |||
$forwardingEmitter = new DummyForwardingEmitter(); | |||
$hookCalled = false; | |||
$forwardingEmitter->listen('Test', 'test', function () use (&$hookCalled) { | |||
$hookCalled = true; | |||
}); | |||
$forwardingEmitter->forward($baseEmitter); | |||
$baseEmitter->emit('Test', 'test'); | |||
$this->assertTrue($hookCalled); | |||
} | |||
} |
@@ -1,58 +0,0 @@ | |||
<?php | |||
/** | |||
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> | |||
* This file is licensed under the Affero General Public License version 3 or | |||
* later. | |||
* See the COPYING-README file. | |||
*/ | |||
namespace Test\Hooks; | |||
/** | |||
* Class DummyLegacyEmitter | |||
* | |||
* class to make LegacyEmitter::emit publicly available | |||
* | |||
* @package Test\Hooks | |||
*/ | |||
class DummyLegacyEmitter extends \OC\Hooks\LegacyEmitter { | |||
public function emitEvent($scope, $method, $arguments = []) { | |||
$this->emit($scope, $method, $arguments); | |||
} | |||
} | |||
class LegacyEmitterTest extends BasicEmitterTest { | |||
//we can't use exceptions here since OC_Hooks catches all exceptions | |||
private static $emitted = false; | |||
protected function setUp(): void { | |||
parent::setUp(); | |||
$this->emitter = new DummyLegacyEmitter(); | |||
self::$emitted = false; | |||
\OC_Hook::clear('Test','test'); | |||
} | |||
public static function staticLegacyCallBack() { | |||
self::$emitted = true; | |||
} | |||
public static function staticLegacyArgumentsCallBack($arguments) { | |||
if ($arguments['foo'] == 'foo' and $arguments['bar'] == 'bar') { | |||
self::$emitted = true; | |||
} | |||
} | |||
public function testLegacyHook() { | |||
\OC_Hook::connect('Test', 'test', '\Test\Hooks\LegacyEmitterTest', 'staticLegacyCallBack'); | |||
$this->emitter->emitEvent('Test', 'test'); | |||
$this->assertEquals(true, self::$emitted); | |||
} | |||
public function testLegacyArguments() { | |||
\OC_Hook::connect('Test', 'test', '\Test\Hooks\LegacyEmitterTest', 'staticLegacyArgumentsCallBack'); | |||
$this->emitter->emitEvent('Test', 'test', ['foo' => 'foo', 'bar' => 'bar']); | |||
$this->assertEquals(true, self::$emitted); | |||
} | |||
} |