From 2f9aeacfce9b8c8c8d9f739b771fa2a890b86121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 11 May 2014 01:51:32 +0200 Subject: [PATCH 1/2] Use PSR-4 layout under src/ --- composer.json | 2 +- phpunit.xml.dist | 2 +- {Icmp => src}/Factory.php | 0 {Icmp => src}/Icmp.php | 0 {Icmp => src}/Message.php | 0 {Icmp => src}/MessageFactory.php | 0 6 files changed, 2 insertions(+), 2 deletions(-) rename {Icmp => src}/Factory.php (100%) rename {Icmp => src}/Icmp.php (100%) rename {Icmp => src}/Message.php (100%) rename {Icmp => src}/MessageFactory.php (100%) diff --git a/composer.json b/composer.json index e70503a..05d4e6d 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,6 @@ "e-butik/iodophor": "1.*" }, "autoload": { - "psr-0": {"Icmp": ""} + "psr-4": {"Icmp\\": "src"} } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 19bb847..5afd1b4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,7 +7,7 @@ - ./Icmp + ./src \ No newline at end of file diff --git a/Icmp/Factory.php b/src/Factory.php similarity index 100% rename from Icmp/Factory.php rename to src/Factory.php diff --git a/Icmp/Icmp.php b/src/Icmp.php similarity index 100% rename from Icmp/Icmp.php rename to src/Icmp.php diff --git a/Icmp/Message.php b/src/Message.php similarity index 100% rename from Icmp/Message.php rename to src/Message.php diff --git a/Icmp/MessageFactory.php b/src/MessageFactory.php similarity index 100% rename from Icmp/MessageFactory.php rename to src/MessageFactory.php From e04311449e50700946b2df4a7b30657263e96ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 11 May 2014 02:02:54 +0200 Subject: [PATCH 2/2] Use namespace Clue\React\Icmp --- CHANGELOG.md | 5 +++++ README.md | 12 ++++++------ composer.json | 2 +- example/dump-all-received.php | 4 ++-- example/ping.php | 2 +- src/Factory.php | 2 +- src/Icmp.php | 6 +++--- src/Message.php | 4 ++-- src/MessageFactory.php | 4 ++-- tests/FactoryTest.php | 5 +++-- tests/IcmpTest.php | 4 ++-- tests/MessageFactoryTest.php | 10 +++++----- tests/MessageTest.php | 4 ++-- 13 files changed, 35 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9d8fb9..29bcd27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ This file is a manually maintained list of changes for each release. Feel free to add your changes here when sending pull requests. Also send corrections if you spot any mistakes. +## 0.2.0 (2014-05-xx) + +* BC break: Rename namespace to `Clue\React\Icmp` and use PSR-4 layout + ([#4](https://github.com/clue/icmp-react/pull/4)) + ## 0.1.0 (2014-03-18) * First tagged release diff --git a/README.md b/README.md index 6abf0ad..184212b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ one). ### Factory -The `Icmp\Factory` is a convenient wrapper that helps you initialize the correct +The `Clue\React\Icmp\Factory` is a convenient wrapper that helps you initialize the correct loop and an ICMP handler. #### Simple factory @@ -37,7 +37,7 @@ you're recommend to let the factory do the work for you and let it create the recommended loop implementation: ```php -$factory = new Icmp\Factory(); +$factory = new Clue\React\Icmp\Factory(); $icmp = $factory->createIcmp4(); ``` @@ -67,7 +67,7 @@ factory like this: ```php $loop = React\EventLoop\Factory::create(); -$factory = new Icmp\Factory($loop); +$factory = new Clue\React\Icmp\Factory($loop); ``` While this will allow you to attach any number of streams to the loop, this @@ -112,7 +112,7 @@ message if it matches the expected ping result. You can also listen to any incoming messages yourself like this: ```php -$icmp->on('message', function (Icmp\Message $message, $peerAddress) { +$icmp->on('message', function (Clue\React\Icmp\Message $message, $peerAddress) { echo 'Message type ' . $message->getType() . ' from ' . $peerAddress . PHP_EOL; }); ``` @@ -123,13 +123,13 @@ If you want to send arbitrary ICMP messages, you can either construct a `Message` object yourself like this ```php -$message = new Icmp\Message($type, $code, $checksum, $header, $payload) +$message = new Clue\React\Icmp\Message($type, $code, $checksum, $header, $payload) ``` or you can use the `MessageFactory` to create common types of messages like this ```php -$factory = new Icmp\MessageFactory(); +$factory = new Clue\React\Icmp\MessageFactory(); $message = $factory->createMessagePing(); ``` diff --git a/composer.json b/composer.json index 05d4e6d..607565c 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,6 @@ "e-butik/iodophor": "1.*" }, "autoload": { - "psr-4": {"Icmp\\": "src"} + "psr-4": {"Clue\\React\\Icmp\\": "src"} } } diff --git a/example/dump-all-received.php b/example/dump-all-received.php index 3f46c15..b277949 100644 --- a/example/dump-all-received.php +++ b/example/dump-all-received.php @@ -66,12 +66,12 @@ function getCodeText($type, $code) return $messages[$type][$code]; } -$factory = new Icmp\Factory(); +$factory = new Clue\React\Icmp\Factory(); $icmp = $factory->createIcmp4(); $n = 0; -$icmp->on('message', function (Icmp\Message $message, $peerAddress) use (&$n) { +$icmp->on('message', function (Clue\React\Icmp\Message $message, $peerAddress) use (&$n) { echo 'Message #' . ++$n . ' received from ' . $peerAddress . ':' . PHP_EOL; echo 'Type: ' . getTypeText($message->getType()) . ' (' . $message->getType() . ')' . PHP_EOL; echo 'Code: ' . getCodeText($message->getType(), $message->getCode()) . ' (' . $message->getCode() . ')' . PHP_EOL; diff --git a/example/ping.php b/example/ping.php index ed49822..6d21da0 100755 --- a/example/ping.php +++ b/example/ping.php @@ -6,7 +6,7 @@ $timeout = 3.0; -$factory = new Icmp\Factory(); +$factory = new Clue\React\Icmp\Factory(); $icmp = $factory->createIcmp4(); echo 'Pinging "' . $remote . '"...' . PHP_EOL; diff --git a/src/Factory.php b/src/Factory.php index 710bf9a..021a9eb 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -1,6 +1,6 @@ assertInstanceOf('Icmp\Icmp', $icmp); + $this->assertInstanceOf('Clue\React\Icmp\Icmp', $icmp); } public function testLoopArgument() diff --git a/tests/IcmpTest.php b/tests/IcmpTest.php index d38e4c2..e99faf7 100644 --- a/tests/IcmpTest.php +++ b/tests/IcmpTest.php @@ -1,6 +1,6 @@ assertInstanceOf('Icmp\Icmp', $icmp); + $this->assertInstanceOf('Clue\React\Icmp\Icmp', $icmp); return $icmp; } diff --git a/tests/MessageFactoryTest.php b/tests/MessageFactoryTest.php index 6467f91..bf9ab2b 100644 --- a/tests/MessageFactoryTest.php +++ b/tests/MessageFactoryTest.php @@ -1,7 +1,7 @@ factory->createFromString($string); - $this->assertInstanceOf('Icmp\Message', $message); + $this->assertInstanceOf('Clue\React\Icmp\Message', $message); $this->assertEquals(Message::TYPE_ECHO_REQUEST, $message->getType()); $this->assertEquals(0, $message->getCode()); @@ -54,7 +54,7 @@ public function testCreateMessagePing() { $message = $this->factory->createMessagePing(); - $this->assertInstanceOf('Icmp\Message', $message); + $this->assertInstanceOf('Clue\React\Icmp\Message', $message); $this->assertEquals(Message::TYPE_ECHO_REQUEST, $message->getType()); $this->assertEquals(0, $message->getCode()); @@ -72,7 +72,7 @@ public function testCreateMessagePong(Message $ping) { $message = $this->factory->createMessagePong($ping); - $this->assertInstanceOf('Icmp\Message', $message); + $this->assertInstanceOf('Clue\React\Icmp\Message', $message); $this->assertEquals(Message::TYPE_ECHO_REPLY, $message->getType()); $this->assertEquals(0, $message->getCode()); diff --git a/tests/MessageTest.php b/tests/MessageTest.php index fc9a40d..36c13ad 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -1,7 +1,7 @@