1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 05:11:42 +01:00

Merge pull request #62 from async-interop/cleanup-namespace

Cleanup namespace
This commit is contained in:
Bob Weinand 2016-05-26 17:27:23 +02:00
commit 6c8d31bc8a
7 changed files with 25 additions and 24 deletions

View File

@ -2,17 +2,20 @@
namespace Interop\Async;
use Interop\Async\Loop\Driver;
use Interop\Async\Loop\DriverFactory;
final class Loop
{
use Registry;
use Loop\Registry;
/**
* @var LoopDriverFactory
* @var DriverFactory
*/
private static $factory = null;
/**
* @var LoopDriver
* @var Driver
*/
private static $driver = null;
@ -29,8 +32,10 @@ final class Loop
*
* The factory will be invoked if none is passed to Loop::execute. A default driver will be created to support
* synchronous waits in traditional applications.
*
* @param DriverFactory|null $factory
*/
public static function setFactory(LoopDriverFactory $factory = null)
public static function setFactory(DriverFactory $factory = null)
{
if (self::$level > 0) {
throw new \RuntimeException("Setting a new factory while running isn't allowed!");
@ -51,11 +56,11 @@ final class Loop
* Execute a callback within the scope of an event loop driver.
*
* @param callable $callback The callback to execute
* @param LoopDriver $driver The event loop driver
* @param Driver $driver The event loop driver
*
* @return void
*/
public static function execute(callable $callback, LoopDriver $driver = null)
public static function execute(callable $callback, Driver $driver = null)
{
$previousRegistry = self::$registry;
$previousDriver = self::$driver;
@ -90,9 +95,9 @@ final class Loop
$driver = self::$factory->create();
if (!$driver instanceof LoopDriver) {
if (!$driver instanceof Driver) {
$type = is_object($driver) ? "an instance of " . get_class($driver) : gettype($driver);
throw new \LogicException("Loop driver factory returned {$type}, but must return an instance of LoopDriver.");
throw new \LogicException("Loop driver factory returned {$type}, but must return an instance of Driver.");
}
return $driver;
@ -101,7 +106,7 @@ final class Loop
/**
* Retrieve the event loop driver that is in scope.
*
* @return LoopDriver
* @return Driver
*/
public static function get()
{

View File

@ -1,8 +1,8 @@
<?php
namespace Interop\Async;
namespace Interop\Async\Loop;
interface LoopDriver
interface Driver
{
/**
* Start the event loop.

View File

@ -1,13 +1,13 @@
<?php
namespace Interop\Async;
namespace Interop\Async\Loop;
interface LoopDriverFactory
interface DriverFactory
{
/**
* Create a new event loop driver instance.
*
* @return LoopDriver
* @return Driver
*/
public function create();
}

View File

@ -1,6 +1,6 @@
<?php
namespace Interop\Async;
namespace Interop\Async\Loop;
/**
* State registry to be used in Interop\Async\Loop.

View File

@ -1,6 +1,6 @@
<?php
use Interop\Async;
use Interop\Async\Loop;
/**
* Must be thrown if a feature is not supported by the system.

View File

@ -3,8 +3,6 @@
namespace Interop\Async\Loop;
use Interop\Async\Loop;
use Interop\Async\LoopDriver;
use Interop\Async\LoopDriverFactory;
class LoopTest extends \PHPUnit_Framework_TestCase
{
@ -18,9 +16,9 @@ class LoopTest extends \PHPUnit_Framework_TestCase
* @expectedExceptionMessage new factory while running isn't allowed
*/
public function setFactoryFailsIfRunning() {
$driver = $this->getMockBuilder(LoopDriver::class)->getMock();
$driver = $this->getMockBuilder(Driver::class)->getMock();
$factory = $this->getMockBuilder(LoopDriverFactory::class)->getMock();
$factory = $this->getMockBuilder(DriverFactory::class)->getMock();
$factory->method("create")->willReturn($driver);
Loop::setFactory($factory);
@ -32,8 +30,8 @@ class LoopTest extends \PHPUnit_Framework_TestCase
/** @test */
public function executeStackReturnsScopedDriver() {
$driver1 = $this->getMockBuilder(LoopDriver::class)->getMock();
$driver2 = $this->getMockBuilder(LoopDriver::class)->getMock();
$driver1 = $this->getMockBuilder(Driver::class)->getMock();
$driver2 = $this->getMockBuilder(Driver::class)->getMock();
Loop::execute(function () use ($driver1, $driver2) {
$this->assertSame($driver1, Loop::get());

View File

@ -2,8 +2,6 @@
namespace Interop\Async\Loop;
use Interop\Async\Registry;
class RegistryTest extends \PHPUnit_Framework_TestCase
{
use Registry;