Skip to content

Commit 6c8d31b

Browse files
committed
Merge pull request #62 from async-interop/cleanup-namespace
Cleanup namespace
2 parents 12102e7 + 7a2c5cd commit 6c8d31b

File tree

7 files changed

+25
-24
lines changed

7 files changed

+25
-24
lines changed

src/Loop.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
namespace Interop\Async;
44

5+
use Interop\Async\Loop\Driver;
6+
use Interop\Async\Loop\DriverFactory;
7+
58
final class Loop
69
{
7-
use Registry;
10+
use Loop\Registry;
811

912
/**
10-
* @var LoopDriverFactory
13+
* @var DriverFactory
1114
*/
1215
private static $factory = null;
1316

1417
/**
15-
* @var LoopDriver
18+
* @var Driver
1619
*/
1720
private static $driver = null;
1821

@@ -29,8 +32,10 @@ final class Loop
2932
*
3033
* The factory will be invoked if none is passed to Loop::execute. A default driver will be created to support
3134
* synchronous waits in traditional applications.
35+
*
36+
* @param DriverFactory|null $factory
3237
*/
33-
public static function setFactory(LoopDriverFactory $factory = null)
38+
public static function setFactory(DriverFactory $factory = null)
3439
{
3540
if (self::$level > 0) {
3641
throw new \RuntimeException("Setting a new factory while running isn't allowed!");
@@ -51,11 +56,11 @@ public static function setFactory(LoopDriverFactory $factory = null)
5156
* Execute a callback within the scope of an event loop driver.
5257
*
5358
* @param callable $callback The callback to execute
54-
* @param LoopDriver $driver The event loop driver
59+
* @param Driver $driver The event loop driver
5560
*
5661
* @return void
5762
*/
58-
public static function execute(callable $callback, LoopDriver $driver = null)
63+
public static function execute(callable $callback, Driver $driver = null)
5964
{
6065
$previousRegistry = self::$registry;
6166
$previousDriver = self::$driver;
@@ -90,9 +95,9 @@ private static function createDriver()
9095

9196
$driver = self::$factory->create();
9297

93-
if (!$driver instanceof LoopDriver) {
98+
if (!$driver instanceof Driver) {
9499
$type = is_object($driver) ? "an instance of " . get_class($driver) : gettype($driver);
95-
throw new \LogicException("Loop driver factory returned {$type}, but must return an instance of LoopDriver.");
100+
throw new \LogicException("Loop driver factory returned {$type}, but must return an instance of Driver.");
96101
}
97102

98103
return $driver;
@@ -101,7 +106,7 @@ private static function createDriver()
101106
/**
102107
* Retrieve the event loop driver that is in scope.
103108
*
104-
* @return LoopDriver
109+
* @return Driver
105110
*/
106111
public static function get()
107112
{

src/LoopDriver.php renamed to src/Loop/Driver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace Interop\Async;
3+
namespace Interop\Async\Loop;
44

5-
interface LoopDriver
5+
interface Driver
66
{
77
/**
88
* Start the event loop.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace Interop\Async;
3+
namespace Interop\Async\Loop;
44

5-
interface LoopDriverFactory
5+
interface DriverFactory
66
{
77
/**
88
* Create a new event loop driver instance.
99
*
10-
* @return LoopDriver
10+
* @return Driver
1111
*/
1212
public function create();
1313
}

src/Registry.php renamed to src/Loop/Registry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Interop\Async;
3+
namespace Interop\Async\Loop;
44

55
/**
66
* State registry to be used in Interop\Async\Loop.

src/UnsupportedFeatureException.php renamed to src/Loop/UnsupportedFeatureException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use Interop\Async;
3+
use Interop\Async\Loop;
44

55
/**
66
* Must be thrown if a feature is not supported by the system.

test/LoopTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace Interop\Async\Loop;
44

55
use Interop\Async\Loop;
6-
use Interop\Async\LoopDriver;
7-
use Interop\Async\LoopDriverFactory;
86

97
class LoopTest extends \PHPUnit_Framework_TestCase
108
{
@@ -18,9 +16,9 @@ protected function setUp() {
1816
* @expectedExceptionMessage new factory while running isn't allowed
1917
*/
2018
public function setFactoryFailsIfRunning() {
21-
$driver = $this->getMockBuilder(LoopDriver::class)->getMock();
19+
$driver = $this->getMockBuilder(Driver::class)->getMock();
2220

23-
$factory = $this->getMockBuilder(LoopDriverFactory::class)->getMock();
21+
$factory = $this->getMockBuilder(DriverFactory::class)->getMock();
2422
$factory->method("create")->willReturn($driver);
2523

2624
Loop::setFactory($factory);
@@ -32,8 +30,8 @@ public function setFactoryFailsIfRunning() {
3230

3331
/** @test */
3432
public function executeStackReturnsScopedDriver() {
35-
$driver1 = $this->getMockBuilder(LoopDriver::class)->getMock();
36-
$driver2 = $this->getMockBuilder(LoopDriver::class)->getMock();
33+
$driver1 = $this->getMockBuilder(Driver::class)->getMock();
34+
$driver2 = $this->getMockBuilder(Driver::class)->getMock();
3735

3836
Loop::execute(function () use ($driver1, $driver2) {
3937
$this->assertSame($driver1, Loop::get());

test/RegistryTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Interop\Async\Loop;
44

5-
use Interop\Async\Registry;
6-
75
class RegistryTest extends \PHPUnit_Framework_TestCase
86
{
97
use Registry;

0 commit comments

Comments
 (0)