From e9e8bc916e1e19b8e4c7e19afa8dc50a8a30d947 Mon Sep 17 00:00:00 2001 From: James Harris Date: Thu, 2 Jul 2015 11:01:25 +1000 Subject: [PATCH 01/24] Updated version constraints to use caret syntax. --- composer.json | 10 +++++----- composer.lock | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 26e35b4..0005bc9 100644 --- a/composer.json +++ b/composer.json @@ -24,13 +24,13 @@ ], "require": { "php": ">=5.5", - "evenement/evenement": "~2", - "icecave/repr": "~1", - "react/react": "0.4.0|~0.4.2", - "react/promise": "~2" + "evenement/evenement": "^2", + "icecave/repr": "^1", + "react/react": "0.4.0|^0.4.2", + "react/promise": "^2" }, "require-dev": { - "icecave/archer": "~1", + "icecave/archer": "^1", "phake/phake": "2.0.0-alpha4 as v1.0.3" }, "autoload": { diff --git a/composer.lock b/composer.lock index 3c40350..e667286 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "6c46870c8c4b6ec529f2e4a3c08df6aa", + "hash": "8ae6511a852533898a9492b46d95b922", "packages": [ { "name": "evenement/evenement", From c81619b6822530bb87f242c7128302afd555797c Mon Sep 17 00:00:00 2001 From: James Harris Date: Sun, 5 Jul 2015 11:56:45 +1000 Subject: [PATCH 02/24] Updated deps. --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index e667286..596765c 100644 --- a/composer.lock +++ b/composer.lock @@ -558,16 +558,16 @@ }, { "name": "react/promise", - "version": "v2.2.0", + "version": "v2.2.1", "source": { "type": "git", "url": "https://github.com/reactphp/promise.git", - "reference": "365fcee430dfa4ace1fbc75737ca60ceea7eeeef" + "reference": "3b6fca09c7d56321057fa8867c8dbe1abf648627" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/365fcee430dfa4ace1fbc75737ca60ceea7eeeef", - "reference": "365fcee430dfa4ace1fbc75737ca60ceea7eeeef", + "url": "https://api.github.com/repos/reactphp/promise/zipball/3b6fca09c7d56321057fa8867c8dbe1abf648627", + "reference": "3b6fca09c7d56321057fa8867c8dbe1abf648627", "shasum": "" }, "require": { @@ -594,11 +594,11 @@ "authors": [ { "name": "Jan Sorgalla", - "email": "jsorgalla@googlemail.com" + "email": "jsorgalla@gmail.com" } ], "description": "A lightweight implementation of CommonJS Promises/A for PHP", - "time": "2014-12-30 13:32:42" + "time": "2015-07-03 13:48:55" }, { "name": "react/react", From 5b3cb8fbea1b3c5a510e42f292f379cbba8f9c7a Mon Sep 17 00:00:00 2001 From: James Harris Date: Thu, 30 Jul 2015 09:52:39 +1000 Subject: [PATCH 03/24] Minor claification to README [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c1f918..f3352f0 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ function multiply($a, $b) ### Throwing and catching exceptions One of the major advantages made available by coroutines is that errors can be reported using familiar exception -handling techniques. Unlike `return`, the `throw` keyword can be used in the standard way inside PHP generators. +handling techniques. The `throw` keyword can be used in the standard way inside PHP generators in both PHP version 5 and 7. ```php function multiply($a, $b) From 292bc1bed7a93675c6a69131b7ecca21914d3ca2 Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 22 Sep 2015 12:52:58 +1000 Subject: [PATCH 04/24] Narrowed the scope of dependency on React. - Changed react/react to react/event-loop - Moved react/promise and react/stream to require-dev, they can be optionally require'd by end projects to make use of related functionality - Added react/dns to require-dev as it's used in examples --- composer.json | 8 +- composer.lock | 1279 ++++++++++++++++++------------------------------- 2 files changed, 482 insertions(+), 805 deletions(-) diff --git a/composer.json b/composer.json index 0005bc9..51c89ea 100644 --- a/composer.json +++ b/composer.json @@ -26,12 +26,14 @@ "php": ">=5.5", "evenement/evenement": "^2", "icecave/repr": "^1", - "react/react": "0.4.0|^0.4.2", - "react/promise": "^2" + "react/event-loop": "^0.4" }, "require-dev": { "icecave/archer": "^1", - "phake/phake": "2.0.0-alpha4 as v1.0.3" + "phake/phake": "2.0.0-alpha4 as v1.0.3", + "react/dns": "^0.4", + "react/promise": "^2", + "react/stream": "^0.4" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 596765c..6a0828f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "8ae6511a852533898a9492b46d95b922", + "hash": "e62d6e776262d6f066f312892afa3857", "packages": [ { "name": "evenement/evenement", @@ -52,6 +52,102 @@ ], "time": "2012-11-02 14:49:47" }, + { + "name": "icecave/repr", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/IcecaveStudios/repr.git", + "reference": "8a3d2953adf5f464a06e3e2587aeacc97e2bed07" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/IcecaveStudios/repr/zipball/8a3d2953adf5f464a06e3e2587aeacc97e2bed07", + "reference": "8a3d2953adf5f464a06e3e2587aeacc97e2bed07", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "icecave/archer": "~1" + }, + "suggest": { + "eloquent/asplode": "Drop-in exception-based error handling." + }, + "type": "library", + "autoload": { + "psr-4": { + "Icecave\\Repr\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "James Harris", + "email": "james.harris@icecave.com.au", + "homepage": "https://github.com/jmalloc" + } + ], + "description": "A library for generating string representations of any value, inspired by Python's reprlib library.", + "homepage": "https://github.com/IcecaveStudios/repr", + "keywords": [ + "human", + "readable", + "repr", + "representation", + "string" + ], + "time": "2014-07-25 05:44:41" + }, + { + "name": "react/event-loop", + "version": "v0.4.1", + "source": { + "type": "git", + "url": "https://github.com/reactphp/event-loop.git", + "reference": "18c5297087ca01de85518e2b55078f444144aa1b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/event-loop/zipball/18c5297087ca01de85518e2b55078f444144aa1b", + "reference": "18c5297087ca01de85518e2b55078f444144aa1b", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "suggest": { + "ext-event": "~1.0", + "ext-libev": "*", + "ext-libevent": ">=0.1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.4-dev" + } + }, + "autoload": { + "psr-4": { + "React\\EventLoop\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Event loop abstraction layer that libraries can use for evented I/O.", + "keywords": [ + "event-loop" + ], + "time": "2014-02-26 17:36:58" + } + ], + "packages-dev": [ { "name": "guzzle/guzzle", "version": "v3.9.3", @@ -148,42 +244,49 @@ "time": "2015-03-18 18:23:50" }, { - "name": "guzzlehttp/psr7", - "version": "1.1.0", + "name": "icecave/archer", + "version": "1.3.2", "source": { "type": "git", - "url": "https://github.com/guzzle/psr7.git", - "reference": "af0e1758de355eb113917ad79c3c0e3604bce4bd" + "url": "https://github.com/IcecaveStudios/archer.git", + "reference": "4b82c195cbc7d65780dbdeffda2c6ba92e56684c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/af0e1758de355eb113917ad79c3c0e3604bce4bd", - "reference": "af0e1758de355eb113917ad79c3c0e3604bce4bd", + "url": "https://api.github.com/repos/IcecaveStudios/archer/zipball/4b82c195cbc7d65780dbdeffda2c6ba92e56684c", + "reference": "4b82c195cbc7d65780dbdeffda2c6ba92e56684c", "shasum": "" }, "require": { - "php": ">=5.4.0", - "psr/http-message": "~1.0" - }, - "provide": { - "psr/http-message-implementation": "1.0" + "phake/phake": "~1", + "php": ">=5.3", + "sami/sami": "~3", + "satooshi/php-coveralls": "~0.6", + "symfony/console": "~2", + "symfony/process": "~2" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "eloquent/liberator": "~1", + "phpunit/phpunit": "~4", + "symfony/event-dispatcher": "~2.1" + }, + "suggest": { + "ext-openssl": "OpenSSL is required to encrypt GitHub OAuth tokens for artifact publication." }, + "bin": [ + "bin/archer", + "bin/woodhouse" + ], "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-develop": "1.3.x-dev" } }, "autoload": { "psr-4": { - "GuzzleHttp\\Psr7\\": "src/" - }, - "files": [ - "src/functions.php" - ] + "Icecave\\Archer\\": "src" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -191,637 +294,220 @@ ], "authors": [ { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" + "name": "Erin Millard", + "email": "ezzatron@gmail.com", + "homepage": "http://ezzatron.com/" + }, + { + "name": "James Harris", + "email": "james.harris@icecave.com.au", + "homepage": "https://github.com/jmalloc" } ], - "description": "PSR-7 message implementation", + "description": "Testing, CI and documentation of PHP projects by convention.", + "homepage": "https://github.com/IcecaveStudios/archer", "keywords": [ - "http", - "message", - "stream", - "uri" + "api", + "artifacts", + "convention", + "coverage", + "documentation", + "phake", + "phpunit", + "project", + "test", + "testing", + "unit" ], - "time": "2015-06-24 19:55:15" + "time": "2015-03-26 02:38:44" }, { - "name": "icecave/repr", - "version": "1.0.1", + "name": "michelf/php-markdown", + "version": "1.5.0", "source": { "type": "git", - "url": "https://github.com/IcecaveStudios/repr.git", - "reference": "8a3d2953adf5f464a06e3e2587aeacc97e2bed07" + "url": "https://github.com/michelf/php-markdown.git", + "reference": "e1aabe18173231ebcefc90e615565742fc1c7fd9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/IcecaveStudios/repr/zipball/8a3d2953adf5f464a06e3e2587aeacc97e2bed07", - "reference": "8a3d2953adf5f464a06e3e2587aeacc97e2bed07", + "url": "https://api.github.com/repos/michelf/php-markdown/zipball/e1aabe18173231ebcefc90e615565742fc1c7fd9", + "reference": "e1aabe18173231ebcefc90e615565742fc1c7fd9", "shasum": "" }, "require": { - "php": ">=5.3" - }, - "require-dev": { - "icecave/archer": "~1" - }, - "suggest": { - "eloquent/asplode": "Drop-in exception-based error handling." + "php": ">=5.3.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-lib": "1.4.x-dev" + } + }, "autoload": { - "psr-4": { - "Icecave\\Repr\\": "src" + "psr-0": { + "Michelf": "" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "James Harris", - "email": "james.harris@icecave.com.au", - "homepage": "https://github.com/jmalloc" + "name": "John Gruber", + "homepage": "http://daringfireball.net/" + }, + { + "name": "Michel Fortin", + "email": "michel.fortin@michelf.ca", + "homepage": "https://michelf.ca/", + "role": "Developer" } ], - "description": "A library for generating string representations of any value, inspired by Python's reprlib library.", - "homepage": "https://github.com/IcecaveStudios/repr", + "description": "PHP Markdown", + "homepage": "https://michelf.ca/projects/php-markdown/", "keywords": [ - "human", - "readable", - "repr", - "representation", - "string" + "markdown" ], - "time": "2014-07-25 05:44:41" + "time": "2015-03-01 12:03:08" }, { - "name": "psr/http-message", - "version": "1.0", + "name": "nikic/php-parser", + "version": "v1.4.1", "source": { "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "f78af2c9c86107aa1a34cd1dbb5bbe9eeb0d9f51" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", - "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f78af2c9c86107aa1a34cd1dbb5bbe9eeb0d9f51", + "reference": "f78af2c9c86107aa1a34cd1dbb5bbe9eeb0d9f51", "shasum": "" }, "require": { - "php": ">=5.3.0" + "ext-tokenizer": "*", + "php": ">=5.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.4-dev" } }, "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } + "files": [ + "lib/bootstrap.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "name": "Nikita Popov" } ], - "description": "Common interface for HTTP messages", + "description": "A PHP parser written in PHP", "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" + "parser", + "php" ], - "time": "2015-05-04 20:22:00" + "time": "2015-09-19 14:15:08" }, { - "name": "react/cache", - "version": "v0.4.0", + "name": "phake/phake", + "version": "v2.0.0-alpha4", "source": { "type": "git", - "url": "https://github.com/reactphp/cache.git", - "reference": "9882ab5d8b00617baae83c6996f5a34668c11beb" + "url": "https://github.com/mlively/Phake.git", + "reference": "89c15ef5213b553d4a34f2d6d57d0682a29336ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/cache/zipball/9882ab5d8b00617baae83c6996f5a34668c11beb", - "reference": "9882ab5d8b00617baae83c6996f5a34668c11beb", + "url": "https://api.github.com/repos/mlively/Phake/zipball/89c15ef5213b553d4a34f2d6d57d0682a29336ec", + "reference": "89c15ef5213b553d4a34f2d6d57d0682a29336ec", "shasum": "" }, "require": { - "php": ">=5.4.0", - "react/promise": "~2.0" + "php": ">=5.3.3" + }, + "require-dev": { + "davedevelopment/hamcrest-php": "dev-master", + "doctrine/common": "2.3.*", + "ext-soap": "*", + "phpunit/phpunit": "3.7.*" + }, + "suggest": { + "davedevelopment/hamcrest-php": "Use Hamcrest matchers.", + "doctrine/common": "Allows mock annotations to use import statements for classes." }, "type": "library", "extra": { "branch-alias": { - "dev-master": "0.4-dev" + "dev-master": "2.0-dev" } }, "autoload": { - "psr-4": { - "React\\Cache\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Async caching.", - "keywords": [ - "cache" - ], - "time": "2014-02-02 01:11:26" - }, - { - "name": "react/child-process", - "version": "v0.4.0", - "source": { - "type": "git", - "url": "https://github.com/reactphp/child-process.git", - "reference": "8bf211533bcbb2034e00528a47400367570dc3d7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/child-process/zipball/8bf211533bcbb2034e00528a47400367570dc3d7", - "reference": "8bf211533bcbb2034e00528a47400367570dc3d7", - "shasum": "" - }, - "require": { - "evenement/evenement": "~2.0", - "php": ">=5.4.0", - "react/event-loop": "0.4.*", - "react/stream": "0.4.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.4-dev" - } - }, - "autoload": { - "psr-4": { - "React\\ChildProcess\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Library for executing child processes.", - "keywords": [ - "process" - ], - "time": "2014-02-02 01:11:26" - }, - { - "name": "react/dns", - "version": "v0.4.1", - "source": { - "type": "git", - "url": "https://github.com/reactphp/dns.git", - "reference": "8c5ccc35dcb4b06b70eb9201842363fac7b0f3cf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/dns/zipball/8c5ccc35dcb4b06b70eb9201842363fac7b0f3cf", - "reference": "8c5ccc35dcb4b06b70eb9201842363fac7b0f3cf", - "shasum": "" - }, - "require": { - "php": ">=5.4.0", - "react/cache": "0.4.*", - "react/promise": "~2.0", - "react/socket": "0.4.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.4-dev" - } - }, - "autoload": { - "psr-4": { - "React\\Dns\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Async DNS resolver.", - "keywords": [ - "dns", - "dns-resolver" - ], - "time": "2014-04-12 14:09:10" - }, - { - "name": "react/event-loop", - "version": "v0.4.1", - "source": { - "type": "git", - "url": "https://github.com/reactphp/event-loop.git", - "reference": "18c5297087ca01de85518e2b55078f444144aa1b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/event-loop/zipball/18c5297087ca01de85518e2b55078f444144aa1b", - "reference": "18c5297087ca01de85518e2b55078f444144aa1b", - "shasum": "" - }, - "require": { - "php": ">=5.4.0" - }, - "suggest": { - "ext-event": "~1.0", - "ext-libev": "*", - "ext-libevent": ">=0.1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.4-dev" - } - }, - "autoload": { - "psr-4": { - "React\\EventLoop\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Event loop abstraction layer that libraries can use for evented I/O.", - "keywords": [ - "event-loop" - ], - "time": "2014-02-26 17:36:58" - }, - { - "name": "react/http", - "version": "v0.4.1", - "source": { - "type": "git", - "url": "https://github.com/reactphp/http.git", - "reference": "f575989d67b7db0a65f5dd7e431d8f47af6c2f7b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/http/zipball/f575989d67b7db0a65f5dd7e431d8f47af6c2f7b", - "reference": "f575989d67b7db0a65f5dd7e431d8f47af6c2f7b", - "shasum": "" - }, - "require": { - "evenement/evenement": "^2.0", - "guzzlehttp/psr7": "^1.0", - "php": ">=5.4.0", - "react/socket": "^0.4", - "react/stream": "^0.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.5-dev" - } - }, - "autoload": { - "psr-4": { - "React\\Http\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Library for building an evented http server.", - "keywords": [ - "http" - ], - "time": "2015-05-21 20:12:09" - }, - { - "name": "react/http-client", - "version": "v0.4.4", - "source": { - "type": "git", - "url": "https://github.com/reactphp/http-client.git", - "reference": "391e1e771c2255954226204edcdc5a2764938e6a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/http-client/zipball/391e1e771c2255954226204edcdc5a2764938e6a", - "reference": "391e1e771c2255954226204edcdc5a2764938e6a", - "shasum": "" - }, - "require": { - "evenement/evenement": "~2.0", - "guzzle/parser": "~3.0", - "php": ">=5.4.0", - "react/dns": "0.4.*", - "react/event-loop": "0.4.*", - "react/socket-client": "0.4.*", - "react/stream": "0.4.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.5-dev" - } - }, - "autoload": { - "psr-4": { - "React\\HttpClient\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Asynchronous HTTP client library.", - "keywords": [ - "http" - ], - "time": "2015-06-16 20:58:52" - }, - { - "name": "react/promise", - "version": "v2.2.1", - "source": { - "type": "git", - "url": "https://github.com/reactphp/promise.git", - "reference": "3b6fca09c7d56321057fa8867c8dbe1abf648627" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/3b6fca09c7d56321057fa8867c8dbe1abf648627", - "reference": "3b6fca09c7d56321057fa8867c8dbe1abf648627", - "shasum": "" - }, - "require": { - "php": ">=5.4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "psr-4": { - "React\\Promise\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jan Sorgalla", - "email": "jsorgalla@gmail.com" - } - ], - "description": "A lightweight implementation of CommonJS Promises/A for PHP", - "time": "2015-07-03 13:48:55" - }, - { - "name": "react/react", - "version": "v0.4.2", - "source": { - "type": "git", - "url": "https://github.com/reactphp/react.git", - "reference": "457b6b8a16a37c11278cac0870d6d2ff911c5765" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/react/zipball/457b6b8a16a37c11278cac0870d6d2ff911c5765", - "reference": "457b6b8a16a37c11278cac0870d6d2ff911c5765", - "shasum": "" - }, - "require": { - "php": ">=5.4.0", - "react/cache": "0.4.*", - "react/child-process": "0.4.*", - "react/dns": "0.4.*", - "react/event-loop": "0.4.*", - "react/http": "0.4.*", - "react/http-client": "0.4.*", - "react/promise": "~2.1", - "react/socket": "0.4.*", - "react/socket-client": "0.4.*", - "react/stream": "0.4.*" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "suggest": { - "ext-event": "Allows for use of a more performant event-loop implementation.", - "ext-libev": "Allows for use of a more performant event-loop implementation.", - "ext-libevent": "Allows for use of a more performant event-loop implementation." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.5-dev" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Nuclear Reactor written in PHP.", - "keywords": [ - "asynchronous", - "event-loop", - "reactor" - ], - "time": "2014-12-11 02:06:55" - }, - { - "name": "react/socket", - "version": "v0.4.2", - "source": { - "type": "git", - "url": "https://github.com/reactphp/socket.git", - "reference": "a6acf405ca53fc6cfbfe7c77778ededff46aa7cc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/socket/zipball/a6acf405ca53fc6cfbfe7c77778ededff46aa7cc", - "reference": "a6acf405ca53fc6cfbfe7c77778ededff46aa7cc", - "shasum": "" - }, - "require": { - "evenement/evenement": "~2.0", - "php": ">=5.4.0", - "react/event-loop": "0.4.*", - "react/stream": "0.4.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.4-dev" - } - }, - "autoload": { - "psr-4": { - "React\\Socket\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Library for building an evented socket server.", - "keywords": [ - "Socket" - ], - "time": "2014-05-25 17:02:16" - }, - { - "name": "react/socket-client", - "version": "v0.4.3", - "source": { - "type": "git", - "url": "https://github.com/reactphp/socket-client.git", - "reference": "1375dac21b1881cba31c2b38f412dc039566673f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/socket-client/zipball/1375dac21b1881cba31c2b38f412dc039566673f", - "reference": "1375dac21b1881cba31c2b38f412dc039566673f", - "shasum": "" - }, - "require": { - "php": ">=5.4.0", - "react/dns": "0.4.*", - "react/event-loop": "0.4.*", - "react/promise": "~2.0", - "react/stream": "0.4.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.4-dev" - } - }, - "autoload": { - "psr-4": { - "React\\SocketClient\\": "src" + "psr-0": { + "Phake": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" - ], - "description": "Async connector to open TCP/IP and SSL/TLS based connections.", - "keywords": [ - "Socket" + "BSD-3-Clause" ], - "time": "2015-03-20 15:24:06" - }, - { - "name": "react/stream", - "version": "v0.4.2", - "source": { - "type": "git", - "url": "https://github.com/reactphp/stream.git", - "reference": "acc7a5fec02e0aea674560e1d13c40ed0c8c5465" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/stream/zipball/acc7a5fec02e0aea674560e1d13c40ed0c8c5465", - "reference": "acc7a5fec02e0aea674560e1d13c40ed0c8c5465", - "shasum": "" - }, - "require": { - "evenement/evenement": "~2.0", - "php": ">=5.4.0" - }, - "require-dev": { - "react/event-loop": "0.4.*", - "react/promise": "~2.0" - }, - "suggest": { - "react/event-loop": "0.4.*", - "react/promise": "~2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.5-dev" - } - }, - "autoload": { - "psr-4": { - "React\\Stream\\": "src" + "authors": [ + { + "name": "Mike Lively", + "email": "m@digitalsandwich.com" } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" ], - "description": "Basic readable and writable stream interfaces that support piping.", + "description": "The Phake mock testing library", + "homepage": "https://github.com/mlively/Phake", "keywords": [ - "pipe", - "stream" + "mock", + "testing" ], - "time": "2014-09-10 03:32:31" + "time": "2013-08-06 22:31:04" }, { - "name": "symfony/event-dispatcher", - "version": "v2.7.1", + "name": "phpdocumentor/reflection-docblock", + "version": "2.0.4", "source": { "type": "git", - "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "be3c5ff8d503c46768aeb78ce6333051aa6f26d9" + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/be3c5ff8d503c46768aeb78ce6333051aa6f26d9", - "reference": "be3c5ff8d503c46768aeb78ce6333051aa6f26d9", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.3.3" }, "require-dev": { - "psr/log": "~1.0", - "symfony/config": "~2.0,>=2.0.5", - "symfony/dependency-injection": "~2.6", - "symfony/expression-language": "~2.6", - "symfony/phpunit-bridge": "~2.7", - "symfony/stopwatch": "~2.3" + "phpunit/phpunit": "~4.0" }, "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { - "psr-4": { - "Symfony\\Component\\EventDispatcher\\": "" + "psr-0": { + "phpDocumentor": [ + "src/" + ] } }, "notification-url": "https://packagist.org/downloads/", @@ -830,63 +516,38 @@ ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "Mike van Riel", + "email": "mike.vanriel@naenius.com" } ], - "description": "Symfony EventDispatcher Component", - "homepage": "https://symfony.com", - "time": "2015-06-08 09:37:21" - } - ], - "packages-dev": [ + "time": "2015-02-03 12:10:50" + }, { - "name": "icecave/archer", - "version": "1.3.2", + "name": "pimple/pimple", + "version": "v3.0.2", "source": { "type": "git", - "url": "https://github.com/IcecaveStudios/archer.git", - "reference": "4b82c195cbc7d65780dbdeffda2c6ba92e56684c" + "url": "https://github.com/silexphp/Pimple.git", + "reference": "a30f7d6e57565a2e1a316e1baf2a483f788b258a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/IcecaveStudios/archer/zipball/4b82c195cbc7d65780dbdeffda2c6ba92e56684c", - "reference": "4b82c195cbc7d65780dbdeffda2c6ba92e56684c", + "url": "https://api.github.com/repos/silexphp/Pimple/zipball/a30f7d6e57565a2e1a316e1baf2a483f788b258a", + "reference": "a30f7d6e57565a2e1a316e1baf2a483f788b258a", "shasum": "" }, "require": { - "phake/phake": "~1", - "php": ">=5.3", - "sami/sami": "~3", - "satooshi/php-coveralls": "~0.6", - "symfony/console": "~2", - "symfony/process": "~2" - }, - "require-dev": { - "eloquent/liberator": "~1", - "phpunit/phpunit": "~4", - "symfony/event-dispatcher": "~2.1" - }, - "suggest": { - "ext-openssl": "OpenSSL is required to encrypt GitHub OAuth tokens for artifact publication." + "php": ">=5.3.0" }, - "bin": [ - "bin/archer", - "bin/woodhouse" - ], "type": "library", "extra": { "branch-alias": { - "dev-develop": "1.3.x-dev" + "dev-master": "3.0.x-dev" } }, "autoload": { - "psr-4": { - "Icecave\\Archer\\": "src" + "psr-0": { + "Pimple": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -895,221 +556,167 @@ ], "authors": [ { - "name": "Erin Millard", - "email": "ezzatron@gmail.com", - "homepage": "http://ezzatron.com/" - }, - { - "name": "James Harris", - "email": "james.harris@icecave.com.au", - "homepage": "https://github.com/jmalloc" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" } ], - "description": "Testing, CI and documentation of PHP projects by convention.", - "homepage": "https://github.com/IcecaveStudios/archer", + "description": "Pimple, a simple Dependency Injection Container", + "homepage": "http://pimple.sensiolabs.org", "keywords": [ - "api", - "artifacts", - "convention", - "coverage", - "documentation", - "phake", - "phpunit", - "project", - "test", - "testing", - "unit" + "container", + "dependency injection" ], - "time": "2015-03-26 02:38:44" + "time": "2015-09-11 15:10:35" }, { - "name": "michelf/php-markdown", - "version": "1.5.0", + "name": "psr/log", + "version": "1.0.0", "source": { "type": "git", - "url": "https://github.com/michelf/php-markdown.git", - "reference": "e1aabe18173231ebcefc90e615565742fc1c7fd9" + "url": "https://github.com/php-fig/log.git", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/michelf/php-markdown/zipball/e1aabe18173231ebcefc90e615565742fc1c7fd9", - "reference": "e1aabe18173231ebcefc90e615565742fc1c7fd9", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", "shasum": "" }, - "require": { - "php": ">=5.3.0" - }, "type": "library", - "extra": { - "branch-alias": { - "dev-lib": "1.4.x-dev" - } - }, "autoload": { "psr-0": { - "Michelf": "" + "Psr\\Log\\": "" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "John Gruber", - "homepage": "http://daringfireball.net/" - }, - { - "name": "Michel Fortin", - "email": "michel.fortin@michelf.ca", - "homepage": "https://michelf.ca/", - "role": "Developer" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "PHP Markdown", - "homepage": "https://michelf.ca/projects/php-markdown/", + "description": "Common interface for logging libraries", "keywords": [ - "markdown" + "log", + "psr", + "psr-3" ], - "time": "2015-03-01 12:03:08" + "time": "2012-12-21 11:40:51" }, { - "name": "nikic/php-parser", - "version": "v1.3.0", + "name": "react/cache", + "version": "v0.4.0", "source": { "type": "git", - "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "dff239267fd1befa1cd40430c9ed12591aa720ca" + "url": "https://github.com/reactphp/cache.git", + "reference": "9882ab5d8b00617baae83c6996f5a34668c11beb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/dff239267fd1befa1cd40430c9ed12591aa720ca", - "reference": "dff239267fd1befa1cd40430c9ed12591aa720ca", + "url": "https://api.github.com/repos/reactphp/cache/zipball/9882ab5d8b00617baae83c6996f5a34668c11beb", + "reference": "9882ab5d8b00617baae83c6996f5a34668c11beb", "shasum": "" }, "require": { - "ext-tokenizer": "*", - "php": ">=5.3" + "php": ">=5.4.0", + "react/promise": "~2.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "0.4-dev" } }, "autoload": { - "files": [ - "lib/bootstrap.php" - ] + "psr-4": { + "React\\Cache\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Nikita Popov" - } + "MIT" ], - "description": "A PHP parser written in PHP", + "description": "Async caching.", "keywords": [ - "parser", - "php" + "cache" ], - "time": "2015-05-02 15:40:40" + "time": "2014-02-02 01:11:26" }, { - "name": "phake/phake", - "version": "v2.0.0-alpha4", + "name": "react/dns", + "version": "v0.4.1", "source": { "type": "git", - "url": "https://github.com/mlively/Phake.git", - "reference": "89c15ef5213b553d4a34f2d6d57d0682a29336ec" + "url": "https://github.com/reactphp/dns.git", + "reference": "8c5ccc35dcb4b06b70eb9201842363fac7b0f3cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mlively/Phake/zipball/89c15ef5213b553d4a34f2d6d57d0682a29336ec", - "reference": "89c15ef5213b553d4a34f2d6d57d0682a29336ec", + "url": "https://api.github.com/repos/reactphp/dns/zipball/8c5ccc35dcb4b06b70eb9201842363fac7b0f3cf", + "reference": "8c5ccc35dcb4b06b70eb9201842363fac7b0f3cf", "shasum": "" }, "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "davedevelopment/hamcrest-php": "dev-master", - "doctrine/common": "2.3.*", - "ext-soap": "*", - "phpunit/phpunit": "3.7.*" - }, - "suggest": { - "davedevelopment/hamcrest-php": "Use Hamcrest matchers.", - "doctrine/common": "Allows mock annotations to use import statements for classes." + "php": ">=5.4.0", + "react/cache": "0.4.*", + "react/promise": "~2.0", + "react/socket": "0.4.*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "0.4-dev" } }, "autoload": { - "psr-0": { - "Phake": "src/" + "psr-4": { + "React\\Dns\\": "" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Mike Lively", - "email": "m@digitalsandwich.com" - } + "MIT" ], - "description": "The Phake mock testing library", - "homepage": "https://github.com/mlively/Phake", + "description": "Async DNS resolver.", "keywords": [ - "mock", - "testing" + "dns", + "dns-resolver" ], - "time": "2013-08-06 22:31:04" + "time": "2014-04-12 14:09:10" }, { - "name": "phpdocumentor/reflection-docblock", - "version": "2.0.4", + "name": "react/promise", + "version": "v2.2.1", "source": { "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" + "url": "https://github.com/reactphp/promise.git", + "reference": "3b6fca09c7d56321057fa8867c8dbe1abf648627" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", + "url": "https://api.github.com/repos/reactphp/promise/zipball/3b6fca09c7d56321057fa8867c8dbe1abf648627", + "reference": "3b6fca09c7d56321057fa8867c8dbe1abf648627", "shasum": "" }, "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "suggest": { - "dflydev/markdown": "~1.0", - "erusev/parsedown": "~1.0" + "php": ">=5.4.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "2.0-dev" } }, "autoload": { - "psr-0": { - "phpDocumentor": [ - "src/" - ] - } + "psr-4": { + "React\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1117,114 +724,120 @@ ], "authors": [ { - "name": "Mike van Riel", - "email": "mike.vanriel@naenius.com" + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com" } ], - "time": "2015-02-03 12:10:50" + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "time": "2015-07-03 13:48:55" }, { - "name": "pimple/pimple", - "version": "v3.0.0", + "name": "react/socket", + "version": "v0.4.2", "source": { "type": "git", - "url": "https://github.com/silexphp/Pimple.git", - "reference": "876bf0899d01feacd2a2e83f04641e51350099ef" + "url": "https://github.com/reactphp/socket.git", + "reference": "a6acf405ca53fc6cfbfe7c77778ededff46aa7cc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/silexphp/Pimple/zipball/876bf0899d01feacd2a2e83f04641e51350099ef", - "reference": "876bf0899d01feacd2a2e83f04641e51350099ef", + "url": "https://api.github.com/repos/reactphp/socket/zipball/a6acf405ca53fc6cfbfe7c77778ededff46aa7cc", + "reference": "a6acf405ca53fc6cfbfe7c77778ededff46aa7cc", "shasum": "" }, "require": { - "php": ">=5.3.0" + "evenement/evenement": "~2.0", + "php": ">=5.4.0", + "react/event-loop": "0.4.*", + "react/stream": "0.4.*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "0.4-dev" } }, "autoload": { - "psr-0": { - "Pimple": "src/" + "psr-4": { + "React\\Socket\\": "src" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Pimple is a simple Dependency Injection Container for PHP 5.3", - "homepage": "http://pimple.sensiolabs.org", + "description": "Library for building an evented socket server.", "keywords": [ - "container", - "dependency injection" + "Socket" ], - "time": "2014-07-24 09:48:15" + "time": "2014-05-25 17:02:16" }, { - "name": "psr/log", - "version": "1.0.0", + "name": "react/stream", + "version": "v0.4.2", "source": { "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + "url": "https://github.com/reactphp/stream.git", + "reference": "acc7a5fec02e0aea674560e1d13c40ed0c8c5465" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "url": "https://api.github.com/repos/reactphp/stream/zipball/acc7a5fec02e0aea674560e1d13c40ed0c8c5465", + "reference": "acc7a5fec02e0aea674560e1d13c40ed0c8c5465", "shasum": "" }, + "require": { + "evenement/evenement": "~2.0", + "php": ">=5.4.0" + }, + "require-dev": { + "react/event-loop": "0.4.*", + "react/promise": "~2.0" + }, + "suggest": { + "react/event-loop": "0.4.*", + "react/promise": "~2.0" + }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.5-dev" + } + }, "autoload": { - "psr-0": { - "Psr\\Log\\": "" + "psr-4": { + "React\\Stream\\": "src" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", + "description": "Basic readable and writable stream interfaces that support piping.", "keywords": [ - "log", - "psr", - "psr-3" + "pipe", + "stream" ], - "time": "2012-12-21 11:40:51" + "time": "2014-09-10 03:32:31" }, { "name": "sami/sami", - "version": "v3.0.5", + "version": "v3.0.8", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/Sami.git", - "reference": "0828c3700604eee9ec3f6f4affa6a9224f4ce76a" + "reference": "c7f82710279c9aaa673b1ad27148749e9bf7223c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/Sami/zipball/0828c3700604eee9ec3f6f4affa6a9224f4ce76a", - "reference": "0828c3700604eee9ec3f6f4affa6a9224f4ce76a", + "url": "https://api.github.com/repos/FriendsOfPHP/Sami/zipball/c7f82710279c9aaa673b1ad27148749e9bf7223c", + "reference": "c7f82710279c9aaa673b1ad27148749e9bf7223c", "shasum": "" }, "require": { "michelf/php-markdown": "~1.3", "nikic/php-parser": "~1.0", - "php": ">=5.3.3", + "php": ">=5.3.9", "phpdocumentor/reflection-docblock": "~2.0", "pimple/pimple": "~3.0", "symfony/console": "~2.1", @@ -1232,7 +845,7 @@ "symfony/finder": "~2.1", "symfony/process": "~2.1", "symfony/yaml": "~2.1", - "twig/twig": "~1.13" + "twig/twig": "~1.20|~2.0" }, "bin": [ "sami.php" @@ -1263,7 +876,7 @@ "keywords": [ "phpdoc" ], - "time": "2015-05-30 16:31:24" + "time": "2015-08-13 07:35:12" }, { "name": "satooshi/php-coveralls", @@ -1335,16 +948,16 @@ }, { "name": "symfony/config", - "version": "v2.7.1", + "version": "v2.7.4", "source": { "type": "git", "url": "https://github.com/symfony/Config.git", - "reference": "58ded81f1f582a87c528ef3dae9a859f78b5f374" + "reference": "5ab9ff48b3cb5b40951a607f77fc1cbfd29edba8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Config/zipball/58ded81f1f582a87c528ef3dae9a859f78b5f374", - "reference": "58ded81f1f582a87c528ef3dae9a859f78b5f374", + "url": "https://api.github.com/repos/symfony/Config/zipball/5ab9ff48b3cb5b40951a607f77fc1cbfd29edba8", + "reference": "5ab9ff48b3cb5b40951a607f77fc1cbfd29edba8", "shasum": "" }, "require": { @@ -1381,20 +994,20 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2015-06-11 14:06:56" + "time": "2015-08-27 06:45:45" }, { "name": "symfony/console", - "version": "v2.7.1", + "version": "v2.7.4", "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "564398bc1f33faf92fc2ec86859983d30eb81806" + "reference": "9ff9032151186bd66ecee727d728f1319f52d1d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/564398bc1f33faf92fc2ec86859983d30eb81806", - "reference": "564398bc1f33faf92fc2ec86859983d30eb81806", + "url": "https://api.github.com/repos/symfony/Console/zipball/9ff9032151186bd66ecee727d728f1319f52d1d8", + "reference": "9ff9032151186bd66ecee727d728f1319f52d1d8", "shasum": "" }, "require": { @@ -1438,20 +1051,78 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2015-06-10 15:30:22" + "time": "2015-09-03 11:40:38" + }, + { + "name": "symfony/event-dispatcher", + "version": "v2.7.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/EventDispatcher.git", + "reference": "b58c916f1db03a611b72dd702564f30ad8fe83fa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/b58c916f1db03a611b72dd702564f30ad8fe83fa", + "reference": "b58c916f1db03a611b72dd702564f30ad8fe83fa", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.0,>=2.0.5", + "symfony/dependency-injection": "~2.6", + "symfony/expression-language": "~2.6", + "symfony/phpunit-bridge": "~2.7", + "symfony/stopwatch": "~2.3" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2015-08-24 07:13:45" }, { "name": "symfony/filesystem", - "version": "v2.7.1", + "version": "v2.7.4", "source": { "type": "git", "url": "https://github.com/symfony/Filesystem.git", - "reference": "a0d43eb3e17d4f4c6990289805a488a0482a07f3" + "reference": "f079e9933799929584200b9a926f72f29e291654" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Filesystem/zipball/a0d43eb3e17d4f4c6990289805a488a0482a07f3", - "reference": "a0d43eb3e17d4f4c6990289805a488a0482a07f3", + "url": "https://api.github.com/repos/symfony/Filesystem/zipball/f079e9933799929584200b9a926f72f29e291654", + "reference": "f079e9933799929584200b9a926f72f29e291654", "shasum": "" }, "require": { @@ -1487,20 +1158,20 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2015-06-08 09:37:21" + "time": "2015-08-27 07:03:44" }, { "name": "symfony/finder", - "version": "v2.7.1", + "version": "v2.7.4", "source": { "type": "git", "url": "https://github.com/symfony/Finder.git", - "reference": "c13a40d638aeede1e8400f8c956c7f9246c05f75" + "reference": "fff4b0c362640a0ab7355e2647b3d461608e9065" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Finder/zipball/c13a40d638aeede1e8400f8c956c7f9246c05f75", - "reference": "c13a40d638aeede1e8400f8c956c7f9246c05f75", + "url": "https://api.github.com/repos/symfony/Finder/zipball/fff4b0c362640a0ab7355e2647b3d461608e9065", + "reference": "fff4b0c362640a0ab7355e2647b3d461608e9065", "shasum": "" }, "require": { @@ -1536,20 +1207,20 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2015-06-04 20:11:48" + "time": "2015-08-26 17:56:37" }, { "name": "symfony/process", - "version": "v2.7.1", + "version": "v2.7.4", "source": { "type": "git", "url": "https://github.com/symfony/Process.git", - "reference": "552d8efdc80980cbcca50b28d626ac8e36e3cdd1" + "reference": "f7b3f73f70a7f8f49a1c838dc3debbf054732d8e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/552d8efdc80980cbcca50b28d626ac8e36e3cdd1", - "reference": "552d8efdc80980cbcca50b28d626ac8e36e3cdd1", + "url": "https://api.github.com/repos/symfony/Process/zipball/f7b3f73f70a7f8f49a1c838dc3debbf054732d8e", + "reference": "f7b3f73f70a7f8f49a1c838dc3debbf054732d8e", "shasum": "" }, "require": { @@ -1585,20 +1256,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2015-06-08 09:37:21" + "time": "2015-08-27 06:45:45" }, { "name": "symfony/stopwatch", - "version": "v2.7.1", + "version": "v2.7.4", "source": { "type": "git", "url": "https://github.com/symfony/Stopwatch.git", - "reference": "c653f1985f6c2b7dbffd04d48b9c0a96aaef814b" + "reference": "abc61bac76fb10ffa2c6373d7932bc35190dbf3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/c653f1985f6c2b7dbffd04d48b9c0a96aaef814b", - "reference": "c653f1985f6c2b7dbffd04d48b9c0a96aaef814b", + "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/abc61bac76fb10ffa2c6373d7932bc35190dbf3b", + "reference": "abc61bac76fb10ffa2c6373d7932bc35190dbf3b", "shasum": "" }, "require": { @@ -1634,20 +1305,20 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2015-06-04 20:11:48" + "time": "2015-08-24 07:13:45" }, { "name": "symfony/yaml", - "version": "v2.7.1", + "version": "v2.7.4", "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160" + "reference": "2dc7b06c065df96cc686c66da2705e5e18aef661" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/9808e75c609a14f6db02f70fccf4ca4aab53c160", - "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/2dc7b06c065df96cc686c66da2705e5e18aef661", + "reference": "2dc7b06c065df96cc686c66da2705e5e18aef661", "shasum": "" }, "require": { @@ -1683,29 +1354,33 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2015-06-10 15:30:22" + "time": "2015-08-24 07:13:45" }, { "name": "twig/twig", - "version": "v1.18.2", + "version": "v1.22.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "e8e6575abf6102af53ec283f7f14b89e304fa602" + "reference": "b7fc2469fa009897871fb95b68237286fc54a5ad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/e8e6575abf6102af53ec283f7f14b89e304fa602", - "reference": "e8e6575abf6102af53ec283f7f14b89e304fa602", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/b7fc2469fa009897871fb95b68237286fc54a5ad", + "reference": "b7fc2469fa009897871fb95b68237286fc54a5ad", "shasum": "" }, "require": { "php": ">=5.2.7" }, + "require-dev": { + "symfony/debug": "~2.7", + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-master": "1.22-dev" } }, "autoload": { @@ -1740,7 +1415,7 @@ "keywords": [ "templating" ], - "time": "2015-06-06 23:31:24" + "time": "2015-09-15 06:50:16" } ], "aliases": [ From 14f72a287c0d11e8c73033e115520870257b1ad8 Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 12:14:52 +1000 Subject: [PATCH 05/24] Rename WritableStream -> WritablePhpStream (#78) --- examples/channel-ipc | 2 +- src/Stream/{WritableStream.php => WritablePhpStream.php} | 2 +- test/suite/Channel/WritableStreamChannelTest.php | 4 ++-- .../{WritableStreamTest.php => WritablePhpStreamTest.php} | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename src/Stream/{WritableStream.php => WritablePhpStream.php} (98%) rename test/suite/Stream/{WritableStreamTest.php => WritablePhpStreamTest.php} (55%) diff --git a/examples/channel-ipc b/examples/channel-ipc index 5b7889b..e6e7f75 100755 --- a/examples/channel-ipc +++ b/examples/channel-ipc @@ -42,7 +42,7 @@ function childProcess() { // Create a channel for writing serialized values to STDOUT ... $channel = new \Recoil\Channel\WritableStreamChannel( - new \Recoil\Stream\WritableStream( + new \Recoil\Stream\WritablePhpStream( fopen('php://stdout', 'w') ) ); diff --git a/src/Stream/WritableStream.php b/src/Stream/WritablePhpStream.php similarity index 98% rename from src/Stream/WritableStream.php rename to src/Stream/WritablePhpStream.php index 8bcfe24..e2653ba 100644 --- a/src/Stream/WritableStream.php +++ b/src/Stream/WritablePhpStream.php @@ -10,7 +10,7 @@ /** * A writable stream that operates directly on a native PHP stream resource. */ -class WritableStream implements WritableStreamInterface +class WritablePhpStream implements WritableStreamInterface { /** * @param resource $stream The underlying PHP stream resource. diff --git a/test/suite/Channel/WritableStreamChannelTest.php b/test/suite/Channel/WritableStreamChannelTest.php index 8a42eef..2959129 100644 --- a/test/suite/Channel/WritableStreamChannelTest.php +++ b/test/suite/Channel/WritableStreamChannelTest.php @@ -4,7 +4,7 @@ use PHPUnit_Framework_TestCase; use Recoil\Channel\Serialization\PhpUnserializer; use Recoil\Recoil; -use Recoil\Stream\WritableStream; +use Recoil\Stream\WritablePhpStream; class WritableStreamChannelTest extends PHPUnit_Framework_TestCase { @@ -16,7 +16,7 @@ public function setUp() { $this->path = tempnam(sys_get_temp_dir(), 'recoil-'); $this->resource = fopen($this->path, 'w'); - $this->stream = new WritableStream($this->resource); + $this->stream = new WritablePhpStream($this->resource); $this->channel = new WritableStreamChannel($this->stream); $this->unserializer = new PhpUnserializer(); } diff --git a/test/suite/Stream/WritableStreamTest.php b/test/suite/Stream/WritablePhpStreamTest.php similarity index 55% rename from test/suite/Stream/WritableStreamTest.php rename to test/suite/Stream/WritablePhpStreamTest.php index 85d68b6..51ff1ca 100644 --- a/test/suite/Stream/WritableStreamTest.php +++ b/test/suite/Stream/WritablePhpStreamTest.php @@ -3,12 +3,12 @@ use PHPUnit_Framework_TestCase; -class WritableStreamTest extends PHPUnit_Framework_TestCase +class WritablePhpStreamTest extends PHPUnit_Framework_TestCase { use WritableStreamTestTrait; public function createStream() { - return new WritableStream($this->resource); + return new WritablePhpStream($this->resource); } } From c171e4949d53f085f3c3dc81cc2483ba80c7bc8f Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 12:19:36 +1000 Subject: [PATCH 06/24] Rename ReadableStream -> ReadablePhpStream (#78) --- examples/stream-file | 2 +- src/Stream/{ReadableStream.php => ReadablePhpStream.php} | 2 +- test/suite/Channel/ReadableStreamChannelTest.php | 4 ++-- .../{ReadableStreamTest.php => ReadablePhpStreamTest.php} | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename src/Stream/{ReadableStream.php => ReadablePhpStream.php} (98%) rename test/suite/Stream/{ReadableStreamTest.php => ReadablePhpStreamTest.php} (86%) diff --git a/examples/stream-file b/examples/stream-file index 5da0c4d..ebb58ea 100755 --- a/examples/stream-file +++ b/examples/stream-file @@ -12,7 +12,7 @@ use Recoil\Recoil; Recoil::run( function () { - $stream = new \Recoil\Stream\ReadableStream(fopen(__FILE__, 'r')); + $stream = new \Recoil\Stream\ReadablePhpStream(fopen(__FILE__, 'r')); while (!$stream->isClosed()) { echo (yield $stream->read(512)); diff --git a/src/Stream/ReadableStream.php b/src/Stream/ReadablePhpStream.php similarity index 98% rename from src/Stream/ReadableStream.php rename to src/Stream/ReadablePhpStream.php index e964adc..b3cab31 100644 --- a/src/Stream/ReadableStream.php +++ b/src/Stream/ReadablePhpStream.php @@ -10,7 +10,7 @@ /** * A readable stream that operates directly on a native PHP stream resource. */ -class ReadableStream implements ReadableStreamInterface +class ReadablePhpStream implements ReadableStreamInterface { /** * @param resource $stream The underlying PHP stream resource. diff --git a/test/suite/Channel/ReadableStreamChannelTest.php b/test/suite/Channel/ReadableStreamChannelTest.php index d532dd1..c4cb404 100644 --- a/test/suite/Channel/ReadableStreamChannelTest.php +++ b/test/suite/Channel/ReadableStreamChannelTest.php @@ -4,7 +4,7 @@ use PHPUnit_Framework_TestCase; use Recoil\Channel\Serialization\PhpSerializer; use Recoil\Recoil; -use Recoil\Stream\ReadableStream; +use Recoil\Stream\ReadablePhpStream; class ReadableStreamChannelTest extends PHPUnit_Framework_TestCase { @@ -16,7 +16,7 @@ public function setUp() { $this->path = tempnam(sys_get_temp_dir(), 'recoil-'); $this->resource = fopen($this->path, 'r+'); - $this->stream = new ReadableStream($this->resource); + $this->stream = new ReadablePhpStream($this->resource); $this->channel = new ReadableStreamChannel($this->stream); $this->serializer = new PhpSerializer(); } diff --git a/test/suite/Stream/ReadableStreamTest.php b/test/suite/Stream/ReadablePhpStreamTest.php similarity index 86% rename from test/suite/Stream/ReadableStreamTest.php rename to test/suite/Stream/ReadablePhpStreamTest.php index 9691e0a..c1c72e6 100644 --- a/test/suite/Stream/ReadableStreamTest.php +++ b/test/suite/Stream/ReadablePhpStreamTest.php @@ -6,13 +6,13 @@ use Recoil\Recoil; use Recoil\Stream\Exception\StreamReadException; -class ReadableStreamTest extends PHPUnit_Framework_TestCase +class ReadablePhpStreamTest extends PHPUnit_Framework_TestCase { use ReadableStreamTestTrait; public function createStream() { - return new ReadableStream($this->resource); + return new ReadablePhpStream($this->resource); } public function testReadFailure() From c81279e006104ba132811e5484cc4409336895f3 Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 12:27:04 +1000 Subject: [PATCH 07/24] Renamed Readable/WritableStreamInterface -> Readable/WritableStream (#78) --- README.md | 2 +- src/Channel/ReadableStreamChannel.php | 6 +++--- src/Channel/WritableStreamChannel.php | 6 +++--- src/Stream/BidirectionalStreamAdaptor.php | 4 ++-- src/Stream/BidirectionalStreamInterface.php | 4 +--- src/Stream/ReadablePhpStream.php | 2 +- src/Stream/ReadableReactStream.php | 8 ++++---- .../{ReadableStreamInterface.php => ReadableStream.php} | 2 +- src/Stream/WritablePhpStream.php | 2 +- src/Stream/WritableReactStream.php | 6 +++--- .../{WritableStreamInterface.php => WritableStream.php} | 2 +- test/suite/Stream/BidirectionalStreamAdaptorTest.php | 4 ++-- 12 files changed, 23 insertions(+), 25 deletions(-) rename src/Stream/{ReadableStreamInterface.php => ReadableStream.php} (98%) rename src/Stream/{WritableStreamInterface.php => WritableStream.php} (99%) diff --git a/README.md b/README.md index f3352f0..9a89e7a 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ is accessed via the [Recoil facade](src/Recoil.php). ### Streams -*Streams* provide a coroutine based abstraction for [readable](src/Stream/ReadableStreamInterface.php) and [writable](src/Stream/WritableStreamInterface.php) +*Streams* provide a coroutine based abstraction for [readable](src/Stream/ReadableStream.php) and [writable](src/Stream/WritableStream.php) data streams. The interfaces are somewhat similar to the built-in PHP stream API. Stream operations are cooperative, that is, when reading or writing to a stream, execution of the coroutine is suspended diff --git a/src/Channel/ReadableStreamChannel.php b/src/Channel/ReadableStreamChannel.php index 82f36d2..1d3b933 100644 --- a/src/Channel/ReadableStreamChannel.php +++ b/src/Channel/ReadableStreamChannel.php @@ -8,7 +8,7 @@ use Recoil\Recoil; use Recoil\Stream\Exception\StreamClosedException; use Recoil\Stream\Exception\StreamLockedException; -use Recoil\Stream\ReadableStreamInterface; +use Recoil\Stream\ReadableStream; /** * A readable channel that unserializes values from a stream. @@ -16,12 +16,12 @@ class ReadableStreamChannel implements ReadableChannelInterface { /** - * @param ReadableStreamInterface $stream The underlying stream. + * @param ReadableStream $stream The underlying stream. * @param UnserializerInterface|null $unserializer The unserializer to use to convert stream data into values. * @param integer $bufferSize The maximum number of bytes to read from the stream at a time. */ public function __construct( - ReadableStreamInterface $stream, + ReadableStream $stream, UnserializerInterface $unserializer = null, $bufferSize = 8192 ) { diff --git a/src/Channel/WritableStreamChannel.php b/src/Channel/WritableStreamChannel.php index 50d30ec..8643301 100644 --- a/src/Channel/WritableStreamChannel.php +++ b/src/Channel/WritableStreamChannel.php @@ -7,7 +7,7 @@ use Recoil\Channel\Serialization\SerializerInterface; use Recoil\Stream\Exception\StreamClosedException; use Recoil\Stream\Exception\StreamLockedException; -use Recoil\Stream\WritableStreamInterface; +use Recoil\Stream\WritableStream; /** * A writable channel that serializes values onto a stream. @@ -15,11 +15,11 @@ class WritableStreamChannel implements WritableChannelInterface { /** - * @param WritableStreamInterface $stream The underlying stream. + * @param WritableStream $stream The underlying stream. * @param SerializerInterface|null $serializer The serializer used to convert values into stream data. */ public function __construct( - WritableStreamInterface $stream, + WritableStream $stream, SerializerInterface $serializer = null ) { if (null === $serializer) { diff --git a/src/Stream/BidirectionalStreamAdaptor.php b/src/Stream/BidirectionalStreamAdaptor.php index cfd4736..4a2ba41 100644 --- a/src/Stream/BidirectionalStreamAdaptor.php +++ b/src/Stream/BidirectionalStreamAdaptor.php @@ -12,8 +12,8 @@ class BidirectionalStreamAdaptor implements BidirectionalStreamInterface { public function __construct( - ReadableStreamInterface $readStream, - WritableStreamInterface $writeStream + ReadableStream $readStream, + WritableStream $writeStream ) { $this->readStream = $readStream; $this->writeStream = $writeStream; diff --git a/src/Stream/BidirectionalStreamInterface.php b/src/Stream/BidirectionalStreamInterface.php index 8e4d5fc..e2342db 100644 --- a/src/Stream/BidirectionalStreamInterface.php +++ b/src/Stream/BidirectionalStreamInterface.php @@ -4,8 +4,6 @@ /** * A stream that supports bidirectional communication. */ -interface BidirectionalStreamInterface extends - ReadableStreamInterface, - WritableStreamInterface +interface BidirectionalStreamInterface extends ReadableStream, WritableStream { } diff --git a/src/Stream/ReadablePhpStream.php b/src/Stream/ReadablePhpStream.php index b3cab31..06b6b74 100644 --- a/src/Stream/ReadablePhpStream.php +++ b/src/Stream/ReadablePhpStream.php @@ -10,7 +10,7 @@ /** * A readable stream that operates directly on a native PHP stream resource. */ -class ReadablePhpStream implements ReadableStreamInterface +class ReadablePhpStream implements ReadableStream { /** * @param resource $stream The underlying PHP stream resource. diff --git a/src/Stream/ReadableReactStream.php b/src/Stream/ReadableReactStream.php index 57870c4..48df258 100644 --- a/src/Stream/ReadableReactStream.php +++ b/src/Stream/ReadableReactStream.php @@ -2,7 +2,7 @@ namespace Recoil\Stream; use Exception; -use React\Stream\ReadableStreamInterface as ReadableReactStreamInterface; +use React\Stream\ReadableStreamInterface; use Recoil\Recoil; use Recoil\Stream\Exception\StreamClosedException; use Recoil\Stream\Exception\StreamLockedException; @@ -11,12 +11,12 @@ /** * Exposes a React readable stream as a Recoil readable stream. */ -class ReadableReactStream implements ReadableStreamInterface +class ReadableReactStream implements ReadableStream { /** - * @param ReadableReactStreamInterface $stream The underlying React stream. + * @param ReadableStreamInterface $stream The underlying React stream. */ - public function __construct(ReadableReactStreamInterface $stream) + public function __construct(ReadableStreamInterface $stream) { $this->stream = $stream; $this->buffer = ''; diff --git a/src/Stream/ReadableStreamInterface.php b/src/Stream/ReadableStream.php similarity index 98% rename from src/Stream/ReadableStreamInterface.php rename to src/Stream/ReadableStream.php index 3b9045f..8186cd1 100644 --- a/src/Stream/ReadableStreamInterface.php +++ b/src/Stream/ReadableStream.php @@ -14,7 +14,7 @@ * * @link http://www.ietf.org/rfc/rfc2119.txt */ -interface ReadableStreamInterface +interface ReadableStream { /** * [COROUTINE] Read data from the stream. diff --git a/src/Stream/WritablePhpStream.php b/src/Stream/WritablePhpStream.php index e2653ba..9e2e067 100644 --- a/src/Stream/WritablePhpStream.php +++ b/src/Stream/WritablePhpStream.php @@ -10,7 +10,7 @@ /** * A writable stream that operates directly on a native PHP stream resource. */ -class WritablePhpStream implements WritableStreamInterface +class WritablePhpStream implements WritableStream { /** * @param resource $stream The underlying PHP stream resource. diff --git a/src/Stream/WritableReactStream.php b/src/Stream/WritableReactStream.php index 7413631..4f12b3e 100644 --- a/src/Stream/WritableReactStream.php +++ b/src/Stream/WritableReactStream.php @@ -2,7 +2,7 @@ namespace Recoil\Stream; use Exception; -use React\Stream\WritableStreamInterface as WritableReactStreamInterface; +use React\Stream\WritableStreamInterface; use Recoil\Recoil; use Recoil\Stream\Exception\StreamClosedException; use Recoil\Stream\Exception\StreamLockedException; @@ -11,12 +11,12 @@ /** * Exposes a React writable stream as a Recoil writable stream. */ -class WritableReactStream implements WritableStreamInterface +class WritableReactStream implements WritableStream { /** * @param WritableReactStreamInterface $stream The underlying React stream. */ - public function __construct(WritableReactStreamInterface $stream) + public function __construct(WritableStreamInterface $stream) { $this->stream = $stream; diff --git a/src/Stream/WritableStreamInterface.php b/src/Stream/WritableStream.php similarity index 99% rename from src/Stream/WritableStreamInterface.php rename to src/Stream/WritableStream.php index 931fb99..6e5d4e4 100644 --- a/src/Stream/WritableStreamInterface.php +++ b/src/Stream/WritableStream.php @@ -14,7 +14,7 @@ * * @link http://www.ietf.org/rfc/rfc2119.txt */ -interface WritableStreamInterface +interface WritableStream { /** * [COROUTINE] Write data to this stream. diff --git a/test/suite/Stream/BidirectionalStreamAdaptorTest.php b/test/suite/Stream/BidirectionalStreamAdaptorTest.php index 78dba7f..622441b 100644 --- a/test/suite/Stream/BidirectionalStreamAdaptorTest.php +++ b/test/suite/Stream/BidirectionalStreamAdaptorTest.php @@ -9,8 +9,8 @@ class BidirectionalStreamAdaptorTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->readStream = Phake::mock(ReadableStreamInterface::class); - $this->writeStream = Phake::mock(WritableStreamInterface::class); + $this->readStream = Phake::mock(ReadableStream::class); + $this->writeStream = Phake::mock(WritableStream::class); $this->adaptor = new BidirectionalStreamAdaptor( $this->readStream, $this->writeStream From 0e4b223444cd57da068e5126b08dd9464ad654d4 Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 12:29:12 +1000 Subject: [PATCH 08/24] CS [ci skip] --- .php_cs | 70 ++++++++++++++++--- src/Channel/BidirectionalChannelAdaptor.php | 1 + src/Channel/BidirectionalChannelInterface.php | 1 + src/Channel/Channel.php | 1 + .../Exception/ChannelClosedException.php | 1 + .../Exception/ChannelLockedException.php | 1 + src/Channel/ReadableChannelInterface.php | 1 + src/Channel/ReadableStreamChannel.php | 1 + src/Channel/Serialization/PhpSerializer.php | 1 + src/Channel/Serialization/PhpUnserializer.php | 1 + .../Serialization/SerializerInterface.php | 1 + .../Serialization/UnserializerInterface.php | 1 + src/Channel/WritableChannelInterface.php | 1 + src/Channel/WritableStreamChannel.php | 1 + src/Coroutine/CoroutineAdaptor.php | 1 + src/Coroutine/CoroutineAdaptorInterface.php | 1 + src/Coroutine/CoroutineInterface.php | 1 + src/Coroutine/CoroutineProviderInterface.php | 1 + src/Coroutine/CoroutineTrait.php | 1 + .../Exception/PromiseRejectedException.php | 1 + src/Coroutine/GeneratorCoroutine.php | 1 + src/Coroutine/PromiseCoroutine.php | 1 + src/Kernel/Api/KernelApi.php | 1 + src/Kernel/Api/KernelApiCall.php | 1 + src/Kernel/Api/KernelApiInterface.php | 1 + src/Kernel/Api/Select.php | 1 + src/Kernel/Api/Sleep.php | 1 + src/Kernel/Api/Timeout.php | 1 + src/Kernel/Api/WaitAll.php | 1 + .../Exception/StrandTerminatedException.php | 1 + src/Kernel/Exception/TimeoutException.php | 1 + src/Kernel/Kernel.php | 1 + src/Kernel/KernelInterface.php | 1 + src/Kernel/Strand/StackBase.php | 1 + src/Kernel/Strand/Strand.php | 1 + src/Kernel/Strand/StrandFactory.php | 1 + src/Kernel/Strand/StrandFactoryInterface.php | 1 + src/Kernel/Strand/StrandInterface.php | 1 + src/PackageInfo.php | 1 + src/Recoil.php | 1 + src/Stream/BidirectionalStreamAdaptor.php | 1 + src/Stream/BidirectionalStreamInterface.php | 1 + .../Exception/StreamClosedException.php | 1 + .../Exception/StreamLockedException.php | 1 + src/Stream/Exception/StreamReadException.php | 1 + src/Stream/Exception/StreamWriteException.php | 1 + src/Stream/ReadablePhpStream.php | 1 + src/Stream/ReadableReactStream.php | 1 + src/Stream/ReadableStream.php | 1 + src/Stream/WritablePhpStream.php | 1 + src/Stream/WritableReactStream.php | 1 + src/Stream/WritableStream.php | 1 + test/src/Recoil/Channel/ChannelTestTrait.php | 1 + .../ExclusiveReadableChannelTestTrait.php | 1 + .../ExclusiveWritableChannelTestTrait.php | 1 + .../Channel/LoopbackChannelTestTrait.php | 1 + .../Channel/ReadableChannelTestTrait.php | 1 + .../Channel/WritableChannelTestTrait.php | 1 + .../Recoil/Stream/ReadableStreamTestTrait.php | 1 + .../Recoil/Stream/WritableStreamTestTrait.php | 1 + .../BidirectionalChannelAdaptorTest.php | 3 +- test/suite/Channel/ChannelTest.php | 1 + .../Exception/ChannelClosedExceptionTest.php | 1 + .../Exception/ChannelLockedExceptionTest.php | 1 + .../Channel/ReadableStreamChannelTest.php | 1 + .../Serialization/PhpSerializerTest.php | 1 + .../Serialization/PhpUnserializerTest.php | 1 + .../Channel/WritableStreamChannelTest.php | 1 + test/suite/Coroutine/CoroutineAdaptorTest.php | 3 +- .../PromiseRejectedExceptionTest.php | 1 + .../Coroutine/GeneratorCoroutineTest.php | 1 + test/suite/Coroutine/PromiseCoroutineTest.php | 1 + test/suite/Kernel/Api/KernelApiCallTest.php | 3 +- test/suite/Kernel/Api/KernelApiTest.php | 1 + test/suite/Kernel/Api/SelectTest.php | 1 + test/suite/Kernel/Api/SleepTest.php | 1 + test/suite/Kernel/Api/TimeoutTest.php | 1 + test/suite/Kernel/Api/WaitAllTest.php | 1 + .../StrandTerminatedExceptionTest.php | 1 + .../Kernel/Exception/TimeoutExceptionTest.php | 1 + test/suite/Kernel/KernelFunctionalTest.php | 1 + test/suite/Kernel/KernelTest.php | 1 + .../Kernel/Strand/StrandFunctionalTest.php | 1 + test/suite/RecoilTest.php | 1 + .../Stream/BidirectionalStreamAdaptorTest.php | 3 +- .../Exception/StreamClosedExceptionTest.php | 1 + .../Exception/StreamLockedExceptionTest.php | 1 + .../Exception/StreamReadExceptionTest.php | 1 + .../Exception/StreamWriteExceptionTest.php | 1 + test/suite/Stream/ReadablePhpStreamTest.php | 3 +- test/suite/Stream/ReadableReactStreamTest.php | 3 +- test/suite/Stream/WritablePhpStreamTest.php | 1 + test/suite/Stream/WritableReactStreamTest.php | 1 + 93 files changed, 158 insertions(+), 16 deletions(-) diff --git a/.php_cs b/.php_cs index fe026e5..d6da9fb 100644 --- a/.php_cs +++ b/.php_cs @@ -1,16 +1,66 @@ in(__DIR__); + ->in(__DIR__) + ->exclude( + array( + 'artifacts', + 'assets', + 'bower_components', + 'build', + 'node_modules', + 'src-web', + 'src-generated', + 'vendor', + ) + ); return Symfony\CS\Config\Config::create() - ->fixers(array( - '-concat_without_spaces', - '-empty_return', - '-new_with_braces', - 'align_double_arrow', - 'align_equals', - 'ordered_use', - 'short_array_syntax', - )) + ->level(Symfony\CS\FixerInterface::PSR2_LEVEL) + ->fixers( + array( + // symfony + 'blankline_after_open_tag', + 'duplicate_semicolon', + 'extra_empty_lines', + 'include', + 'join_function', + 'list_commas', + 'multiline_array_trailing_comma', + 'namespace_no_leading_whitespace', + 'new_with_braces', + 'no_blank_lines_after_class_opening', + 'no_empty_lines_after_phpdocs', + 'object_operator', + 'operators_spaces', + 'phpdoc_indent', + 'phpdoc_params', + 'phpdoc_short_description', + 'phpdoc_to_comment', + 'phpdoc_trim', + 'phpdoc_type_to_var', + 'phpdoc_var_without_name', + 'pre_increment', + 'remove_leading_slash_use', + 'remove_lines_between_uses', + 'return', + 'self_accessor', + 'single_array_no_trailing_comma', + 'single_blank_line_before_namespace', + 'single_quote', + 'spaces_before_semicolon', + 'spaces_cast', + 'standardize_not_equal', + 'ternary_spaces', + 'trim_array_spaces', + 'unary_operators_spaces', + 'unused_use', + 'whitespacy_lines', + + // contrib + 'concat_with_spaces', + 'multiline_spaces_before_semicolon', + 'ordered_use', + ) + ) ->finder($finder); diff --git a/src/Channel/BidirectionalChannelAdaptor.php b/src/Channel/BidirectionalChannelAdaptor.php index 337ac35..8079db6 100644 --- a/src/Channel/BidirectionalChannelAdaptor.php +++ b/src/Channel/BidirectionalChannelAdaptor.php @@ -1,4 +1,5 @@ Date: Tue, 17 Nov 2015 12:29:55 +1000 Subject: [PATCH 09/24] Rename BidirectionalStreamInterface -> BidirectionalStream (#78) --- ...BidirectionalStreamInterface.php => BidirectionalStream.php} | 2 +- src/Stream/BidirectionalStreamAdaptor.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/Stream/{BidirectionalStreamInterface.php => BidirectionalStream.php} (56%) diff --git a/src/Stream/BidirectionalStreamInterface.php b/src/Stream/BidirectionalStream.php similarity index 56% rename from src/Stream/BidirectionalStreamInterface.php rename to src/Stream/BidirectionalStream.php index 19cc856..f02792d 100644 --- a/src/Stream/BidirectionalStreamInterface.php +++ b/src/Stream/BidirectionalStream.php @@ -5,6 +5,6 @@ /** * A stream that supports bidirectional communication. */ -interface BidirectionalStreamInterface extends ReadableStream, WritableStream +interface BidirectionalStream extends ReadableStream, WritableStream { } diff --git a/src/Stream/BidirectionalStreamAdaptor.php b/src/Stream/BidirectionalStreamAdaptor.php index f99418a..05d6042 100644 --- a/src/Stream/BidirectionalStreamAdaptor.php +++ b/src/Stream/BidirectionalStreamAdaptor.php @@ -10,7 +10,7 @@ /** * Adapts separate read/write streams into a bidirectional stream. */ -class BidirectionalStreamAdaptor implements BidirectionalStreamInterface +class BidirectionalStreamAdaptor implements BidirectionalStream { public function __construct( ReadableStream $readStream, From 899e700126bd68488e718558f86041016124fbf8 Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 12:32:49 +1000 Subject: [PATCH 10/24] Renamed Readable/Writable/BidirectionChannelInterface -> Readable/Writable/BidirectionChannel (#78) --- README.md | 2 +- ...ctionalChannelInterface.php => BidirectionalChannel.php} | 4 +--- src/Channel/BidirectionalChannelAdaptor.php | 6 +++--- src/Channel/Channel.php | 2 +- .../{ReadableChannelInterface.php => ReadableChannel.php} | 2 +- src/Channel/ReadableStreamChannel.php | 2 +- .../{WritableChannelInterface.php => WritableChannel.php} | 2 +- src/Channel/WritableStreamChannel.php | 2 +- test/suite/Channel/BidirectionalChannelAdaptorTest.php | 4 ++-- 9 files changed, 12 insertions(+), 14 deletions(-) rename src/Channel/{BidirectionalChannelInterface.php => BidirectionalChannel.php} (50%) rename src/Channel/{ReadableChannelInterface.php => ReadableChannel.php} (98%) rename src/Channel/{WritableChannelInterface.php => WritableChannel.php} (98%) diff --git a/README.md b/README.md index 9a89e7a..9becb65 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ The [stream-file example](examples/stream-file) demonstrates using a readable st *Channels* are stream-like objects that produce and consume PHP values rather than byte streams. Channels are intended as the primary method for communication between strands. -Like streams there are [readable](src/Channel/ReadableChannelInterface.php) and [writable](src/Channel/WritableChannelInterface.php) +Like streams there are [readable](src/Channel/ReadableChannel.php) and [writable](src/Channel/WritableChannel.php) variants. Some channel implementations allow for multiple concurrent read and write operations. Both in-memory and stream-based channels are provided. Stream-based channels use a serialization protocol to encode and diff --git a/src/Channel/BidirectionalChannelInterface.php b/src/Channel/BidirectionalChannel.php similarity index 50% rename from src/Channel/BidirectionalChannelInterface.php rename to src/Channel/BidirectionalChannel.php index 6d185de..4f0f591 100644 --- a/src/Channel/BidirectionalChannelInterface.php +++ b/src/Channel/BidirectionalChannel.php @@ -5,8 +5,6 @@ /** * A data-channel that supports bidirectional communication. */ -interface BidirectionalChannelInterface extends - ReadableChannelInterface, - WritableChannelInterface +interface BidirectionalChannel extends ReadableChannel, WritableChannel { } diff --git a/src/Channel/BidirectionalChannelAdaptor.php b/src/Channel/BidirectionalChannelAdaptor.php index 8079db6..d26cca7 100644 --- a/src/Channel/BidirectionalChannelAdaptor.php +++ b/src/Channel/BidirectionalChannelAdaptor.php @@ -8,11 +8,11 @@ /** * Adapts separate read/write channels into a bidirectional channel. */ -class BidirectionalChannelAdaptor implements BidirectionalChannelInterface +class BidirectionalChannelAdaptor implements BidirectionalChannel { public function __construct( - ReadableChannelInterface $readChannel, - WritableChannelInterface $writeChannel + ReadableChannel $readChannel, + WritableChannel $writeChannel ) { $this->readChannel = $readChannel; $this->writeChannel = $writeChannel; diff --git a/src/Channel/Channel.php b/src/Channel/Channel.php index 8216246..949b68f 100644 --- a/src/Channel/Channel.php +++ b/src/Channel/Channel.php @@ -10,7 +10,7 @@ * An unbuffered (synchronous) loop-back data channel that allows multiple * concurrent read/write operations. */ -class Channel implements ReadableChannelInterface, WritableChannelInterface +class Channel implements ReadableChannel, WritableChannel { public function __construct() { diff --git a/src/Channel/ReadableChannelInterface.php b/src/Channel/ReadableChannel.php similarity index 98% rename from src/Channel/ReadableChannelInterface.php rename to src/Channel/ReadableChannel.php index 207ec0a..481d62d 100644 --- a/src/Channel/ReadableChannelInterface.php +++ b/src/Channel/ReadableChannel.php @@ -17,7 +17,7 @@ * * @link http://www.ietf.org/rfc/rfc2119.txt */ -interface ReadableChannelInterface +interface ReadableChannel { /** * [COROUTINE] Read a value from this channel. diff --git a/src/Channel/ReadableStreamChannel.php b/src/Channel/ReadableStreamChannel.php index 31e7fed..b3dcd29 100644 --- a/src/Channel/ReadableStreamChannel.php +++ b/src/Channel/ReadableStreamChannel.php @@ -14,7 +14,7 @@ /** * A readable channel that unserializes values from a stream. */ -class ReadableStreamChannel implements ReadableChannelInterface +class ReadableStreamChannel implements ReadableChannel { /** * @param ReadableStream $stream The underlying stream. diff --git a/src/Channel/WritableChannelInterface.php b/src/Channel/WritableChannel.php similarity index 98% rename from src/Channel/WritableChannelInterface.php rename to src/Channel/WritableChannel.php index 4adecd4..5f8c08f 100644 --- a/src/Channel/WritableChannelInterface.php +++ b/src/Channel/WritableChannel.php @@ -18,7 +18,7 @@ * * @link http://www.ietf.org/rfc/rfc2119.txt */ -interface WritableChannelInterface +interface WritableChannel { /** * [COROUTINE] Write a value to this channel. diff --git a/src/Channel/WritableStreamChannel.php b/src/Channel/WritableStreamChannel.php index 76d1498..82651c2 100644 --- a/src/Channel/WritableStreamChannel.php +++ b/src/Channel/WritableStreamChannel.php @@ -13,7 +13,7 @@ /** * A writable channel that serializes values onto a stream. */ -class WritableStreamChannel implements WritableChannelInterface +class WritableStreamChannel implements WritableChannel { /** * @param WritableStream $stream The underlying stream. diff --git a/test/suite/Channel/BidirectionalChannelAdaptorTest.php b/test/suite/Channel/BidirectionalChannelAdaptorTest.php index 4427935..5506a3e 100644 --- a/test/suite/Channel/BidirectionalChannelAdaptorTest.php +++ b/test/suite/Channel/BidirectionalChannelAdaptorTest.php @@ -10,8 +10,8 @@ class BidirectionalChannelAdaptorTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->readChannel = Phake::mock(ReadableChannelInterface::class); - $this->writeChannel = Phake::mock(WritableChannelInterface::class); + $this->readChannel = Phake::mock(ReadableChannel::class); + $this->writeChannel = Phake::mock(WritableChannel::class); $this->adaptor = new BidirectionalChannelAdaptor( $this->readChannel, $this->writeChannel From a6e8474b580e08e577b40b45a995c5207c6489fb Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 12:35:39 +1000 Subject: [PATCH 11/24] Renamed [Un]serializerInterface -> [Un]serializer (#78) --- src/Channel/ReadableStreamChannel.php | 10 +++++----- src/Channel/Serialization/PhpSerializer.php | 2 +- src/Channel/Serialization/PhpUnserializer.php | 2 +- .../{SerializerInterface.php => Serializer.php} | 2 +- .../{UnserializerInterface.php => Unserializer.php} | 2 +- src/Channel/WritableStreamChannel.php | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) rename src/Channel/Serialization/{SerializerInterface.php => Serializer.php} (94%) rename src/Channel/Serialization/{UnserializerInterface.php => Unserializer.php} (97%) diff --git a/src/Channel/ReadableStreamChannel.php b/src/Channel/ReadableStreamChannel.php index b3dcd29..9296d32 100644 --- a/src/Channel/ReadableStreamChannel.php +++ b/src/Channel/ReadableStreamChannel.php @@ -5,7 +5,7 @@ use Recoil\Channel\Exception\ChannelClosedException; use Recoil\Channel\Exception\ChannelLockedException; use Recoil\Channel\Serialization\PhpUnserializer; -use Recoil\Channel\Serialization\UnserializerInterface; +use Recoil\Channel\Serialization\Unserializer; use Recoil\Recoil; use Recoil\Stream\Exception\StreamClosedException; use Recoil\Stream\Exception\StreamLockedException; @@ -17,13 +17,13 @@ class ReadableStreamChannel implements ReadableChannel { /** - * @param ReadableStream $stream The underlying stream. - * @param UnserializerInterface|null $unserializer The unserializer to use to convert stream data into values. - * @param integer $bufferSize The maximum number of bytes to read from the stream at a time. + * @param ReadableStream $stream The underlying stream. + * @param Unserializer|null $unserializer The unserializer to use to convert stream data into values. + * @param integer $bufferSize The maximum number of bytes to read from the stream at a time. */ public function __construct( ReadableStream $stream, - UnserializerInterface $unserializer = null, + Unserializer $unserializer = null, $bufferSize = 8192 ) { if (null === $unserializer) { diff --git a/src/Channel/Serialization/PhpSerializer.php b/src/Channel/Serialization/PhpSerializer.php index 59f8600..ee37384 100644 --- a/src/Channel/Serialization/PhpSerializer.php +++ b/src/Channel/Serialization/PhpSerializer.php @@ -7,7 +7,7 @@ /** * A serializer that uses the built-in PHP serialization protocol. */ -class PhpSerializer implements SerializerInterface +class PhpSerializer implements Serializer { /** * Serialize a value to a string. diff --git a/src/Channel/Serialization/PhpUnserializer.php b/src/Channel/Serialization/PhpUnserializer.php index 7f6fd0f..9d8d75a 100644 --- a/src/Channel/Serialization/PhpUnserializer.php +++ b/src/Channel/Serialization/PhpUnserializer.php @@ -9,7 +9,7 @@ /** * An unserializer that uses the built-in PHP serialization protocol. */ -class PhpUnserializer implements UnserializerInterface +class PhpUnserializer implements Unserializer { public function __construct() { diff --git a/src/Channel/Serialization/SerializerInterface.php b/src/Channel/Serialization/Serializer.php similarity index 94% rename from src/Channel/Serialization/SerializerInterface.php rename to src/Channel/Serialization/Serializer.php index e8faeb0..357913d 100644 --- a/src/Channel/Serialization/SerializerInterface.php +++ b/src/Channel/Serialization/Serializer.php @@ -7,7 +7,7 @@ /** * A mechanism for serializing PHP values on stream-based channels. */ -interface SerializerInterface +interface Serializer { /** * Serialize a value to a string. diff --git a/src/Channel/Serialization/UnserializerInterface.php b/src/Channel/Serialization/Unserializer.php similarity index 97% rename from src/Channel/Serialization/UnserializerInterface.php rename to src/Channel/Serialization/Unserializer.php index 803f3a7..ead39c1 100644 --- a/src/Channel/Serialization/UnserializerInterface.php +++ b/src/Channel/Serialization/Unserializer.php @@ -8,7 +8,7 @@ /** * A mechanism for unserializing PHP values from stream-based channels. */ -interface UnserializerInterface +interface Unserializer { /** * Parse data received from the stream. diff --git a/src/Channel/WritableStreamChannel.php b/src/Channel/WritableStreamChannel.php index 82651c2..da07eb2 100644 --- a/src/Channel/WritableStreamChannel.php +++ b/src/Channel/WritableStreamChannel.php @@ -5,7 +5,7 @@ use Recoil\Channel\Exception\ChannelClosedException; use Recoil\Channel\Exception\ChannelLockedException; use Recoil\Channel\Serialization\PhpSerializer; -use Recoil\Channel\Serialization\SerializerInterface; +use Recoil\Channel\Serialization\Serializer; use Recoil\Stream\Exception\StreamClosedException; use Recoil\Stream\Exception\StreamLockedException; use Recoil\Stream\WritableStream; @@ -16,12 +16,12 @@ class WritableStreamChannel implements WritableChannel { /** - * @param WritableStream $stream The underlying stream. - * @param SerializerInterface|null $serializer The serializer used to convert values into stream data. + * @param WritableStream $stream The underlying stream. + * @param Serializer|null $serializer The serializer used to convert values into stream data. */ public function __construct( WritableStream $stream, - SerializerInterface $serializer = null + Serializer $serializer = null ) { if (null === $serializer) { $serializer = new PhpSerializer(); From 6cfe3ef33f1b6a7156bb1bd4b013c95eec26b65c Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 12:39:22 +1000 Subject: [PATCH 12/24] Renamed corouting adaptor & interface (#78). --- src/Coroutine/CoroutineAdaptor.php | 31 ++---------- src/Coroutine/CoroutineAdaptorInterface.php | 23 --------- src/Coroutine/StandardCoroutineAdaptor.php | 48 +++++++++++++++++++ src/Kernel/Kernel.php | 10 ++-- src/Kernel/KernelInterface.php | 4 +- ...t.php => StandardCoroutineAdaptorTest.php} | 4 +- test/suite/Kernel/KernelTest.php | 4 +- 7 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 src/Coroutine/CoroutineAdaptorInterface.php create mode 100644 src/Coroutine/StandardCoroutineAdaptor.php rename test/suite/Coroutine/{CoroutineAdaptorTest.php => StandardCoroutineAdaptorTest.php} (95%) diff --git a/src/Coroutine/CoroutineAdaptor.php b/src/Coroutine/CoroutineAdaptor.php index edd98e6..5e28dcd 100644 --- a/src/Coroutine/CoroutineAdaptor.php +++ b/src/Coroutine/CoroutineAdaptor.php @@ -2,17 +2,13 @@ namespace Recoil\Coroutine; -use Generator; -use Icecave\Repr\Repr; use InvalidArgumentException; -use React\Promise\PromiseInterface; use Recoil\Kernel\Strand\StrandInterface; -use Recoil\Recoil; /** - * The default coroutine adaptor implementation. + * Adapts arbitrary values into coroutine objects. */ -class CoroutineAdaptor implements CoroutineAdaptorInterface +interface CoroutineAdaptor { /** * Adapt a value into a coroutine. @@ -23,26 +19,5 @@ class CoroutineAdaptor implements CoroutineAdaptorInterface * @return CoroutineInterface * @throws InvalidArgumentException if now valid adaptation can be made. */ - public function adapt(StrandInterface $strand, $value) - { - while ($value instanceof CoroutineProviderInterface) { - $value = $value->coroutine($strand); - } - - if ($value instanceof CoroutineInterface) { - return $value; - } elseif ($value instanceof Generator) { - return new GeneratorCoroutine($value); - } elseif ($value instanceof PromiseInterface) { - return new PromiseCoroutine($value); - } elseif (is_array($value)) { - return Recoil::all($value); - } elseif (null === $value) { - return Recoil::cooperate(); - } - - throw new InvalidArgumentException( - 'Unable to adapt ' . Repr::repr($value) . ' into a coroutine.' - ); - } + public function adapt(StrandInterface $strand, $value); } diff --git a/src/Coroutine/CoroutineAdaptorInterface.php b/src/Coroutine/CoroutineAdaptorInterface.php deleted file mode 100644 index 13f7dda..0000000 --- a/src/Coroutine/CoroutineAdaptorInterface.php +++ /dev/null @@ -1,23 +0,0 @@ -coroutine($strand); + } + + if ($value instanceof CoroutineInterface) { + return $value; + } elseif ($value instanceof Generator) { + return new GeneratorCoroutine($value); + } elseif ($value instanceof PromiseInterface) { + return new PromiseCoroutine($value); + } elseif (is_array($value)) { + return Recoil::all($value); + } elseif (null === $value) { + return Recoil::cooperate(); + } + + throw new InvalidArgumentException( + 'Unable to adapt ' . Repr::repr($value) . ' into a coroutine.' + ); + } +} diff --git a/src/Kernel/Kernel.php b/src/Kernel/Kernel.php index 49e7542..798c8f1 100644 --- a/src/Kernel/Kernel.php +++ b/src/Kernel/Kernel.php @@ -5,7 +5,7 @@ use React\EventLoop\Factory as EventLoopFactory; use React\EventLoop\LoopInterface; use Recoil\Coroutine\CoroutineAdaptor; -use Recoil\Coroutine\CoroutineAdaptorInterface; +use Recoil\Coroutine\StandardCoroutineAdaptor; use Recoil\Kernel\Api\KernelApi; use Recoil\Kernel\Api\KernelApiInterface; use Recoil\Kernel\Strand\StrandFactory; @@ -20,13 +20,13 @@ class Kernel implements KernelInterface /** * @param LoopInterface|null $eventLoop The React event-loop. * @param KernelApiInterface|null $api The kernel's API implementation. - * @param CoroutineAdaptorInterface|null $coroutineAdaptor The kernel's coroutine adaptor. + * @param CoroutineAdaptor|null $coroutineAdaptor The kernel's coroutine adaptor. * @param StrandFactoryInterface|null $strandFactory The kernel's strand factory. */ public function __construct( LoopInterface $eventLoop = null, KernelApiInterface $api = null, - CoroutineAdaptorInterface $coroutineAdaptor = null, + CoroutineAdaptor $coroutineAdaptor = null, StrandFactoryInterface $strandFactory = null ) { if (null === $eventLoop) { @@ -38,7 +38,7 @@ public function __construct( } if (null === $coroutineAdaptor) { - $coroutineAdaptor = new CoroutineAdaptor(); + $coroutineAdaptor = new StandardCoroutineAdaptor(); } if (null === $strandFactory) { @@ -112,7 +112,7 @@ public function api() /** * Fetch the object used to adapt values into coroutines. * - * @return CoroutineAdaptorInterface The kernel's coroutine adaptor. + * @return CoroutineAdaptor The kernel's coroutine adaptor. */ public function coroutineAdaptor() { diff --git a/src/Kernel/KernelInterface.php b/src/Kernel/KernelInterface.php index 7002877..772a0b2 100644 --- a/src/Kernel/KernelInterface.php +++ b/src/Kernel/KernelInterface.php @@ -3,7 +3,7 @@ namespace Recoil\Kernel; use React\EventLoop\LoopInterface; -use Recoil\Coroutine\CoroutineAdaptorInterface; +use Recoil\Coroutine\CoroutineAdaptor; use Recoil\Kernel\Strand\StrandFactoryInterface; use Recoil\Kernel\Strand\StrandInterface; @@ -48,7 +48,7 @@ public function api(); /** * Fetch the object used to adapt values into coroutines. * - * @return CoroutineAdaptorInterface The kernel's coroutine adaptor. + * @return CoroutineAdaptor The kernel's coroutine adaptor. */ public function coroutineAdaptor(); diff --git a/test/suite/Coroutine/CoroutineAdaptorTest.php b/test/suite/Coroutine/StandardCoroutineAdaptorTest.php similarity index 95% rename from test/suite/Coroutine/CoroutineAdaptorTest.php rename to test/suite/Coroutine/StandardCoroutineAdaptorTest.php index d419eb0..41cc067 100644 --- a/test/suite/Coroutine/CoroutineAdaptorTest.php +++ b/test/suite/Coroutine/StandardCoroutineAdaptorTest.php @@ -8,12 +8,12 @@ use Recoil\Kernel\Api\KernelApiCall; use Recoil\Kernel\Strand\StrandInterface; -class CoroutineAdaptorTest extends PHPUnit_Framework_TestCase +class StandardCoroutineAdaptorTest extends PHPUnit_Framework_TestCase { public function setUp() { $this->strand = Phake::mock(StrandInterface::class); - $this->adaptor = new CoroutineAdaptor(); + $this->adaptor = new StandardCoroutineAdaptor(); } public function testAdaptPassThru() diff --git a/test/suite/Kernel/KernelTest.php b/test/suite/Kernel/KernelTest.php index fab00d5..e465d21 100644 --- a/test/suite/Kernel/KernelTest.php +++ b/test/suite/Kernel/KernelTest.php @@ -4,7 +4,7 @@ use PHPUnit_Framework_TestCase; use React\EventLoop\LoopInterface; -use Recoil\Coroutine\CoroutineAdaptor; +use Recoil\Coroutine\StandardCoroutineAdaptor; use Recoil\Kernel\Api\KernelApi; use Recoil\Kernel\Strand\StrandFactory; use Recoil\Recoil; @@ -19,7 +19,7 @@ public function setUp() public function testConstructorDefaults() { $this->assertInstanceOf(KernelApi::class, $this->kernel->api()); - $this->assertInstanceOf(CoroutineAdaptor::class, $this->kernel->coroutineAdaptor()); + $this->assertInstanceOf(StandardCoroutineAdaptor::class, $this->kernel->coroutineAdaptor()); $this->assertInstanceOf(StrandFactory::class, $this->kernel->strandFactory()); $this->assertInstanceOf(LoopInterface::class, $this->kernel->eventLoop()); } From 3b35fd1e30eb00cdb134ecf768dbbf3d89773510 Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 12:44:05 +1000 Subject: [PATCH 13/24] Renamed coroutine/provider interfaces (#78) --- .../{CoroutineInterface.php => Coroutine.php} | 2 +- src/Coroutine/CoroutineAdaptor.php | 2 +- ...tineProviderInterface.php => CoroutineProvider.php} | 2 +- src/Coroutine/GeneratorCoroutine.php | 2 +- src/Coroutine/PromiseCoroutine.php | 2 +- src/Coroutine/StandardCoroutineAdaptor.php | 6 +++--- src/Kernel/Api/KernelApiCall.php | 4 ++-- src/Kernel/Api/Select.php | 4 ++-- src/Kernel/Api/Sleep.php | 4 ++-- src/Kernel/Api/Timeout.php | 4 ++-- src/Kernel/Api/WaitAll.php | 4 ++-- src/Kernel/Kernel.php | 8 ++++---- src/Kernel/Strand/StackBase.php | 4 ++-- src/Kernel/Strand/Strand.php | 10 +++++----- src/Kernel/Strand/StrandInterface.php | 10 +++++----- test/suite/Coroutine/StandardCoroutineAdaptorTest.php | 10 +++++----- 16 files changed, 39 insertions(+), 39 deletions(-) rename src/Coroutine/{CoroutineInterface.php => Coroutine.php} (98%) rename src/Coroutine/{CoroutineProviderInterface.php => CoroutineProvider.php} (92%) diff --git a/src/Coroutine/CoroutineInterface.php b/src/Coroutine/Coroutine.php similarity index 98% rename from src/Coroutine/CoroutineInterface.php rename to src/Coroutine/Coroutine.php index 822a1e9..5528e49 100644 --- a/src/Coroutine/CoroutineInterface.php +++ b/src/Coroutine/Coroutine.php @@ -8,7 +8,7 @@ /** * A coroutine represents a unit of work that can be suspended and resumed. */ -interface CoroutineInterface +interface Coroutine { /** * Start the coroutine. diff --git a/src/Coroutine/CoroutineAdaptor.php b/src/Coroutine/CoroutineAdaptor.php index 5e28dcd..eb7760c 100644 --- a/src/Coroutine/CoroutineAdaptor.php +++ b/src/Coroutine/CoroutineAdaptor.php @@ -16,7 +16,7 @@ interface CoroutineAdaptor * @param StrandInterface $strand The currently executing strand. * @param mixed $value The value to adapt. * - * @return CoroutineInterface + * @return Coroutine * @throws InvalidArgumentException if now valid adaptation can be made. */ public function adapt(StrandInterface $strand, $value); diff --git a/src/Coroutine/CoroutineProviderInterface.php b/src/Coroutine/CoroutineProvider.php similarity index 92% rename from src/Coroutine/CoroutineProviderInterface.php rename to src/Coroutine/CoroutineProvider.php index ed7f1bc..900642a 100644 --- a/src/Coroutine/CoroutineProviderInterface.php +++ b/src/Coroutine/CoroutineProvider.php @@ -8,7 +8,7 @@ * A coroutine provide is an object that can produce an object that can be * adapted into a coroutine using the kernel's coroutine adaptor. */ -interface CoroutineProviderInterface +interface CoroutineProvider { /** * Produce a coroutine. diff --git a/src/Coroutine/GeneratorCoroutine.php b/src/Coroutine/GeneratorCoroutine.php index 18cdb46..b49ac57 100644 --- a/src/Coroutine/GeneratorCoroutine.php +++ b/src/Coroutine/GeneratorCoroutine.php @@ -9,7 +9,7 @@ /** * A coroutine wrapper for PHP generators. */ -class GeneratorCoroutine implements CoroutineInterface +class GeneratorCoroutine implements Coroutine { use CoroutineTrait; diff --git a/src/Coroutine/PromiseCoroutine.php b/src/Coroutine/PromiseCoroutine.php index d191c38..a3a7b8f 100644 --- a/src/Coroutine/PromiseCoroutine.php +++ b/src/Coroutine/PromiseCoroutine.php @@ -11,7 +11,7 @@ /** * A coroutine that resumes when a promise is fulfilled or rejected. */ -class PromiseCoroutine implements CoroutineInterface +class PromiseCoroutine implements Coroutine { use CoroutineTrait; diff --git a/src/Coroutine/StandardCoroutineAdaptor.php b/src/Coroutine/StandardCoroutineAdaptor.php index c8bfa2f..81d9188 100644 --- a/src/Coroutine/StandardCoroutineAdaptor.php +++ b/src/Coroutine/StandardCoroutineAdaptor.php @@ -20,16 +20,16 @@ class StandardCoroutineAdaptor implements CoroutineAdaptor * @param StrandInterface $strand The currently executing strand. * @param mixed $value The value to adapt. * - * @return CoroutineInterface + * @return Coroutine * @throws InvalidArgumentException if now valid adaptation can be made. */ public function adapt(StrandInterface $strand, $value) { - while ($value instanceof CoroutineProviderInterface) { + while ($value instanceof CoroutineProvider) { $value = $value->coroutine($strand); } - if ($value instanceof CoroutineInterface) { + if ($value instanceof Coroutine) { return $value; } elseif ($value instanceof Generator) { return new GeneratorCoroutine($value); diff --git a/src/Kernel/Api/KernelApiCall.php b/src/Kernel/Api/KernelApiCall.php index b16d733..e3ab790 100644 --- a/src/Kernel/Api/KernelApiCall.php +++ b/src/Kernel/Api/KernelApiCall.php @@ -3,7 +3,7 @@ namespace Recoil\Kernel\Api; use BadMethodCallException; -use Recoil\Coroutine\CoroutineInterface; +use Recoil\Coroutine\Coroutine; use Recoil\Coroutine\CoroutineTrait; use Recoil\Kernel\Strand\StrandInterface; @@ -13,7 +13,7 @@ * @see Recoil\Kernel\KernelApiInterface * @see Recoil\Kernel\KernelInterface::api() */ -class KernelApiCall implements CoroutineInterface +class KernelApiCall implements Coroutine { use CoroutineTrait; diff --git a/src/Kernel/Api/Select.php b/src/Kernel/Api/Select.php index 2c560d5..e4f6fc5 100644 --- a/src/Kernel/Api/Select.php +++ b/src/Kernel/Api/Select.php @@ -2,7 +2,7 @@ namespace Recoil\Kernel\Api; -use Recoil\Coroutine\CoroutineInterface; +use Recoil\Coroutine\Coroutine; use Recoil\Coroutine\CoroutineTrait; use Recoil\Kernel\Strand\StrandInterface; use SplObjectStorage; @@ -12,7 +12,7 @@ * * @internal */ -class Select implements CoroutineInterface +class Select implements Coroutine { use CoroutineTrait; diff --git a/src/Kernel/Api/Sleep.php b/src/Kernel/Api/Sleep.php index 785b02f..0bd3b47 100644 --- a/src/Kernel/Api/Sleep.php +++ b/src/Kernel/Api/Sleep.php @@ -2,7 +2,7 @@ namespace Recoil\Kernel\Api; -use Recoil\Coroutine\CoroutineInterface; +use Recoil\Coroutine\Coroutine; use Recoil\Coroutine\CoroutineTrait; use Recoil\Kernel\Strand\StrandInterface; @@ -11,7 +11,7 @@ * * @internal */ -class Sleep implements CoroutineInterface +class Sleep implements Coroutine { use CoroutineTrait; diff --git a/src/Kernel/Api/Timeout.php b/src/Kernel/Api/Timeout.php index 740a656..3fc7d04 100644 --- a/src/Kernel/Api/Timeout.php +++ b/src/Kernel/Api/Timeout.php @@ -3,7 +3,7 @@ namespace Recoil\Kernel\Api; use Exception; -use Recoil\Coroutine\CoroutineInterface; +use Recoil\Coroutine\Coroutine; use Recoil\Coroutine\CoroutineTrait; use Recoil\Kernel\Exception\TimeoutException; use Recoil\Kernel\Strand\StrandInterface; @@ -13,7 +13,7 @@ * * @internal */ -class Timeout implements CoroutineInterface +class Timeout implements Coroutine { use CoroutineTrait; diff --git a/src/Kernel/Api/WaitAll.php b/src/Kernel/Api/WaitAll.php index 57ed7a8..5a8f93b 100644 --- a/src/Kernel/Api/WaitAll.php +++ b/src/Kernel/Api/WaitAll.php @@ -3,7 +3,7 @@ namespace Recoil\Kernel\Api; use Exception; -use Recoil\Coroutine\CoroutineInterface; +use Recoil\Coroutine\Coroutine; use Recoil\Coroutine\CoroutineTrait; use Recoil\Kernel\Exception\StrandTerminatedException; use Recoil\Kernel\Strand\StrandInterface; @@ -13,7 +13,7 @@ * * @internal */ -class WaitAll implements CoroutineInterface +class WaitAll implements Coroutine { use CoroutineTrait; diff --git a/src/Kernel/Kernel.php b/src/Kernel/Kernel.php index 798c8f1..8b9f40c 100644 --- a/src/Kernel/Kernel.php +++ b/src/Kernel/Kernel.php @@ -18,10 +18,10 @@ class Kernel implements KernelInterface { /** - * @param LoopInterface|null $eventLoop The React event-loop. - * @param KernelApiInterface|null $api The kernel's API implementation. - * @param CoroutineAdaptor|null $coroutineAdaptor The kernel's coroutine adaptor. - * @param StrandFactoryInterface|null $strandFactory The kernel's strand factory. + * @param LoopInterface|null $eventLoop The React event-loop. + * @param KernelApiInterface|null $api The kernel's API implementation. + * @param CoroutineAdaptor|null $coroutineAdaptor The kernel's coroutine adaptor. + * @param StrandFactoryInterface|null $strandFactory The kernel's strand factory. */ public function __construct( LoopInterface $eventLoop = null, diff --git a/src/Kernel/Strand/StackBase.php b/src/Kernel/Strand/StackBase.php index b845780..3b151db 100644 --- a/src/Kernel/Strand/StackBase.php +++ b/src/Kernel/Strand/StackBase.php @@ -4,7 +4,7 @@ use Exception; use LogicException; -use Recoil\Coroutine\CoroutineInterface; +use Recoil\Coroutine\Coroutine; use Recoil\Coroutine\CoroutineTrait; /** @@ -12,7 +12,7 @@ * * @internal */ -class StackBase implements CoroutineInterface +class StackBase implements Coroutine { use CoroutineTrait; diff --git a/src/Kernel/Strand/Strand.php b/src/Kernel/Strand/Strand.php index 8e3ac09..2d35dd3 100644 --- a/src/Kernel/Strand/Strand.php +++ b/src/Kernel/Strand/Strand.php @@ -5,7 +5,7 @@ use Evenement\EventEmitter; use Exception; use LogicException; -use Recoil\Coroutine\CoroutineInterface; +use Recoil\Coroutine\Coroutine; use Recoil\Kernel\KernelInterface; /** @@ -47,7 +47,7 @@ public function kernel() /** * Fetch the coroutine currently being executed. * - * @return CoroutineInterface The coroutine currently being executed. + * @return Coroutine The coroutine currently being executed. */ public function current() { @@ -61,7 +61,7 @@ public function current() * * @param mixed $coroutine The coroutine to call. * - * @return CoroutineInterface The adapted coroutine. + * @return Coroutine The adapted coroutine. */ public function push($coroutine) { @@ -79,7 +79,7 @@ public function push($coroutine) /** * Pop the current coroutine off the stack. * - * @return CoroutineInterface + * @return Coroutine */ public function pop() { @@ -98,7 +98,7 @@ public function pop() * * @param mixed $coroutine The coroutine to call. * - * @return CoroutineInterface|null The adapted coroutine, or null if no adaptation could be made. + * @return Coroutine|null The adapted coroutine, or null if no adaptation could be made. */ public function call($coroutine) { diff --git a/src/Kernel/Strand/StrandInterface.php b/src/Kernel/Strand/StrandInterface.php index 4e8d6ec..d0c4fe3 100644 --- a/src/Kernel/Strand/StrandInterface.php +++ b/src/Kernel/Strand/StrandInterface.php @@ -4,7 +4,7 @@ use Evenement\EventEmitterInterface; use Exception; -use Recoil\Coroutine\CoroutineInterface; +use Recoil\Coroutine\Coroutine; use Recoil\Kernel\KernelInterface; /** @@ -29,7 +29,7 @@ public function kernel(); /** * Fetch the coroutine this strand is currently executing. * - * @return CoroutineInterface The coroutine currently being executed. + * @return Coroutine The coroutine currently being executed. */ public function current(); @@ -40,14 +40,14 @@ public function current(); * * @param mixed $coroutine The coroutine to call. * - * @return CoroutineInterface The adapted coroutine. + * @return Coroutine The adapted coroutine. */ public function push($coroutine); /** * Pop the current coroutine off the stack. * - * @return CoroutineInterface + * @return Coroutine */ public function pop(); @@ -58,7 +58,7 @@ public function pop(); * * @param mixed $coroutine The coroutine to call. * - * @return CoroutineInterface|null The adapted coroutine, or null if no adaptation could be made. + * @return Coroutine|null The adapted coroutine, or null if no adaptation could be made. */ public function call($coroutine); diff --git a/test/suite/Coroutine/StandardCoroutineAdaptorTest.php b/test/suite/Coroutine/StandardCoroutineAdaptorTest.php index 41cc067..f732d91 100644 --- a/test/suite/Coroutine/StandardCoroutineAdaptorTest.php +++ b/test/suite/Coroutine/StandardCoroutineAdaptorTest.php @@ -18,7 +18,7 @@ public function setUp() public function testAdaptPassThru() { - $coroutine = Phake::mock(CoroutineInterface::class); + $coroutine = Phake::mock(Coroutine::class); $this->assertSame( $coroutine, @@ -79,8 +79,8 @@ public function testAdaptFailure() public function testAdaptProvider() { - $provider = Phake::mock(CoroutineProviderInterface::class); - $coroutine = Phake::mock(CoroutineInterface::class); + $provider = Phake::mock(CoroutineProvider::class); + $coroutine = Phake::mock(Coroutine::class); Phake::when($provider) ->coroutine($this->identicalTo($this->strand)) @@ -94,8 +94,8 @@ public function testAdaptProvider() public function testAdaptNestedProvider() { - $provider = Phake::mock(CoroutineProviderInterface::class); - $coroutine = Phake::mock(CoroutineInterface::class); + $provider = Phake::mock(CoroutineProvider::class); + $coroutine = Phake::mock(Coroutine::class); Phake::when($provider) ->coroutine($this->identicalTo($this->strand)) From 18fb531c92e483a7953f64b3bf8b918dee7e343f Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 12:55:21 +1000 Subject: [PATCH 14/24] Renamed kernel, api and interfaces (#78). --- README.md | 8 +- src/Coroutine/GeneratorCoroutine.php | 2 +- src/Kernel/Api/KernelApi.php | 114 +++-------- src/Kernel/Api/KernelApiCall.php | 4 +- src/Kernel/Api/Select.php | 4 +- src/Kernel/Api/Sleep.php | 4 +- ...ApiInterface.php => StandardKernelApi.php} | 114 ++++++++--- src/Kernel/Api/Timeout.php | 4 +- src/Kernel/Api/WaitAll.php | 4 +- src/Kernel/Kernel.php | 134 +----------- src/Kernel/KernelInterface.php | 78 ------- src/Kernel/StandardKernel.php | 190 ++++++++++++++++++ src/Kernel/Strand/StackBase.php | 2 +- src/Kernel/Strand/Strand.php | 8 +- src/Kernel/Strand/StrandFactory.php | 6 +- src/Kernel/Strand/StrandFactoryInterface.php | 6 +- src/Kernel/Strand/StrandInterface.php | 4 +- src/Recoil.php | 12 +- src/Stream/ReadableReactStream.php | 8 +- src/Stream/WritableReactStream.php | 4 +- .../Channel/LoopbackChannelTestTrait.php | 2 - test/suite/Channel/ChannelTest.php | 4 +- .../Coroutine/GeneratorCoroutineTest.php | 4 +- test/suite/Coroutine/PromiseCoroutineTest.php | 4 +- test/suite/Kernel/Api/KernelApiCallTest.php | 6 +- test/suite/Kernel/Api/SelectTest.php | 4 +- test/suite/Kernel/Api/SleepTest.php | 4 +- ...lApiTest.php => StandardKernelApiTest.php} | 8 +- test/suite/Kernel/Api/TimeoutTest.php | 4 +- ...t.php => StandardKernelFunctionalTest.php} | 4 +- ...{KernelTest.php => StandardKernelTest.php} | 8 +- .../Kernel/Strand/StrandFunctionalTest.php | 4 +- 32 files changed, 382 insertions(+), 384 deletions(-) rename src/Kernel/Api/{KernelApiInterface.php => StandardKernelApi.php} (68%) delete mode 100644 src/Kernel/KernelInterface.php create mode 100644 src/Kernel/StandardKernel.php rename test/suite/Kernel/Api/{KernelApiTest.php => StandardKernelApiTest.php} (98%) rename test/suite/Kernel/{KernelFunctionalTest.php => StandardKernelFunctionalTest.php} (97%) rename test/suite/Kernel/{KernelTest.php => StandardKernelTest.php} (82%) diff --git a/README.md b/README.md index 9becb65..e2abe15 100644 --- a/README.md +++ b/README.md @@ -96,9 +96,9 @@ Internally, the kernel uses a [React event-loop](https://github.com/reactphp/eve applications to execute coroutine based code alongside "conventional" React code by sharing an event-loop instance. Coroutine control flow, the current strand, and the kernel itself can be manipulated using the *kernel API*. The -supported operations are defined in [KernelApiInterface](src/Kernel/Api/KernelApiInterface.php) (though custom kernel -implementations may provide additional operations). Inside an executing coroutine, the kernel API for the current kernel -is accessed via the [Recoil facade](src/Recoil.php). +supported operations are defined in [KernelApi](src/Kernel/Api/KernelApi.php) (though custom kernel implementations may +provide additional operations). Inside an executing coroutine, the kernel API for the current kernel is accessed via the +[Recoil facade](src/Recoil.php). ### Streams @@ -299,7 +299,7 @@ manually. ```php $eventLoop = new React\EventLoop\StreamSelectLoop; -$kernel = new Recoil\Kernel\Kernel($eventLoop); +$kernel = new Recoil\Kernel\StandardKernel($eventLoop); $coroutine = function () { echo 'Hello, world!' . PHP_EOL; diff --git a/src/Coroutine/GeneratorCoroutine.php b/src/Coroutine/GeneratorCoroutine.php index b49ac57..cc5d653 100644 --- a/src/Coroutine/GeneratorCoroutine.php +++ b/src/Coroutine/GeneratorCoroutine.php @@ -129,7 +129,7 @@ public function finalize(StrandInterface $strand) /** * Register a callback to be invoked when the coroutine is finalized. * - * @internal + * @access private * * @param callable $callback The callback to invoke. */ diff --git a/src/Kernel/Api/KernelApi.php b/src/Kernel/Api/KernelApi.php index 14345f5..3922541 100644 --- a/src/Kernel/Api/KernelApi.php +++ b/src/Kernel/Api/KernelApi.php @@ -6,39 +6,30 @@ use Recoil\Kernel\Strand\StrandInterface; /** - * The default kernel API implementation. + * Public interface for manipulating the kernel and the current strand. */ -class KernelApi implements KernelApiInterface +interface KernelApi { /** * Get the strand the coroutine is executing on. * * @param StrandInterface $strand The currently executing strand. */ - public function strand(StrandInterface $strand) - { - $strand->resumeWithValue($strand); - } + public function strand(StrandInterface $strand); /** * Get the coroutine kernel that the current strand is executing on. * * @param StrandInterface $strand The currently executing strand. */ - public function kernel(StrandInterface $strand) - { - $strand->resumeWithValue($strand->kernel()); - } + public function kernel(StrandInterface $strand); /** * Get the React event-loop that the coroutine kernel is executing on. * * @param StrandInterface $strand The currently executing strand. */ - public function eventLoop(StrandInterface $strand) - { - $strand->resumeWithValue($strand->kernel()->eventLoop()); - } + public function eventLoop(StrandInterface $strand); /** * Return a value to the calling coroutine. @@ -46,10 +37,7 @@ public function eventLoop(StrandInterface $strand) * @param StrandInterface $strand The currently executing strand. * @param mixed $value The value to send to the calling coroutine. */ - public function return_(StrandInterface $strand, $value = null) - { - $strand->returnValue($value); - } + public function return_(StrandInterface $strand, $value = null); /** * Throw an exception to the calling coroutine. @@ -57,10 +45,7 @@ public function return_(StrandInterface $strand, $value = null) * @param StrandInterface $strand The currently executing strand. * @param Exception $exception The error to send to the calling coroutine. */ - public function throw_(StrandInterface $strand, Exception $exception) - { - $strand->throwException($exception); - } + public function throw_(StrandInterface $strand, Exception $exception); /** * Register a callback to be invoked when the current coroutine is popped @@ -72,22 +57,14 @@ public function throw_(StrandInterface $strand, Exception $exception) * @param StrandInterface $strand The currently executing strand. * @param callable $callback The callback to invoke. */ - public function finally_(StrandInterface $strand, callable $callback) - { - $strand->current()->registerFinalizeCallback($callback); - - $strand->resumeWithValue(null); - } + public function finally_(StrandInterface $strand, callable $callback); /** * Terminate execution of the strand. * * @param StrandInterface $strand The currently executing strand. */ - public function terminate(StrandInterface $strand) - { - $strand->terminate(); - } + public function terminate(StrandInterface $strand); /** * Suspend execution for a specified period of time. @@ -95,22 +72,15 @@ public function terminate(StrandInterface $strand) * @param StrandInterface $strand The currently executing strand. * @param number $timeout The number of seconds to wait before resuming. */ - public function sleep(StrandInterface $strand, $timeout) - { - return new Sleep($timeout); - } + public function sleep(StrandInterface $strand, $timeout); /** - * Suspend execution of the strand. + * Suspend execution of the strand until it is resumed manually. * - * @param StrandInterface $strand The currently executing strand. + * @param StrandInterface $strand The currently executing strand. + * @param callable $callback A callback which is passed the strand after it is suspended. */ - public function suspend(StrandInterface $strand, callable $callback) - { - $strand->suspend(); - - $callback($strand); - } + public function suspend(StrandInterface $strand, callable $callback); /** * Execute a coroutine with a time limit. @@ -122,10 +92,7 @@ public function suspend(StrandInterface $strand, callable $callback) * @param number $timeout The number of seconds to wait before cancelling. * @param mixed $coroutine The coroutine to execute. */ - public function timeout(StrandInterface $strand, $timeout, $coroutine) - { - return new Timeout($timeout, $coroutine); - } + public function timeout(StrandInterface $strand, $timeout, $coroutine); /** * Execute the given coroutines concurrently. @@ -137,39 +104,21 @@ public function timeout(StrandInterface $strand, $timeout, $coroutine) * @param StrandInterface $strand The currently executing strand. * @param array $coroutines The coroutines to execute. */ - public function all(StrandInterface $strand, array $coroutines) - { - return new WaitAll($coroutines); - } + public function all(StrandInterface $strand, array $coroutines); /** - * Suspend the strand until the next tick. + * Resume the strand immediately. * * @param StrandInterface $strand The currently executing strand. */ - public function cooperate(StrandInterface $strand) - { - $strand->suspend(); - - $strand - ->kernel() - ->eventLoop() - ->futureTick( - function () use ($strand) { - $strand->resumeWithValue(null); - } - ); - } + public function noop(StrandInterface $strand); /** - * Resume the strand immediately. + * Suspend the strand until the next tick. * * @param StrandInterface $strand The currently executing strand. */ - public function noop(StrandInterface $strand) - { - $strand->resumeWithValue(null); - } + public function cooperate(StrandInterface $strand); /** * Execute a coroutine on its own strand. @@ -177,14 +126,7 @@ public function noop(StrandInterface $strand) * @param StrandInterface $strand The currently executing strand. * @param mixed $coroutine The coroutine to execute. */ - public function execute(StrandInterface $strand, $coroutine) - { - $substrand = $strand - ->kernel() - ->execute($coroutine); - - $strand->resumeWithValue($substrand); - } + public function execute(StrandInterface $strand, $coroutine); /** * Wait for one or more of the given strands to exit. @@ -192,10 +134,7 @@ public function execute(StrandInterface $strand, $coroutine) * @param StrandInterface $strand The currently executing strand. * @param StrandInterface[] $strands The strands to wait for. */ - public function select(StrandInterface $strand, array $strands) - { - return new Select($strands); - } + public function select(StrandInterface $strand, array $strands); /** * Stop the coroutine kernel / event-loop. @@ -206,12 +145,5 @@ public function select(StrandInterface $strand, array $strands) * @param StrandInterface $strand The currently executing strand. * @param boolean $stopEventLoop Indicates whether or not the React event-loop should also be stopped. */ - public function stop(StrandInterface $strand, $stopEventLoop = true) - { - $strand->terminate(); - - $strand - ->kernel() - ->stop($stopEventLoop); - } + public function stop(StrandInterface $strand, $stopEventLoop = true); } diff --git a/src/Kernel/Api/KernelApiCall.php b/src/Kernel/Api/KernelApiCall.php index e3ab790..2c15a61 100644 --- a/src/Kernel/Api/KernelApiCall.php +++ b/src/Kernel/Api/KernelApiCall.php @@ -10,8 +10,8 @@ /** * Represents a call to a feature provided by the Kernel API. * - * @see Recoil\Kernel\KernelApiInterface - * @see Recoil\Kernel\KernelInterface::api() + * @see Recoil\Kernel\KernelApi + * @see Recoil\Kernel\Kernel::api() */ class KernelApiCall implements Coroutine { diff --git a/src/Kernel/Api/Select.php b/src/Kernel/Api/Select.php index e4f6fc5..f0318a1 100644 --- a/src/Kernel/Api/Select.php +++ b/src/Kernel/Api/Select.php @@ -8,9 +8,9 @@ use SplObjectStorage; /** - * Internal implementation of KernelApiInterface::select(). + * Internal implementation of KernelApi::select(). * - * @internal + * @access private */ class Select implements Coroutine { diff --git a/src/Kernel/Api/Sleep.php b/src/Kernel/Api/Sleep.php index 0bd3b47..76a6b5f 100644 --- a/src/Kernel/Api/Sleep.php +++ b/src/Kernel/Api/Sleep.php @@ -7,9 +7,9 @@ use Recoil\Kernel\Strand\StrandInterface; /** - * Internal implementation of KernelApiInterface::sleep(). + * Internal implementation of KernelApi::sleep(). * - * @internal + * @access private */ class Sleep implements Coroutine { diff --git a/src/Kernel/Api/KernelApiInterface.php b/src/Kernel/Api/StandardKernelApi.php similarity index 68% rename from src/Kernel/Api/KernelApiInterface.php rename to src/Kernel/Api/StandardKernelApi.php index d51b675..d0c388b 100644 --- a/src/Kernel/Api/KernelApiInterface.php +++ b/src/Kernel/Api/StandardKernelApi.php @@ -6,30 +6,39 @@ use Recoil\Kernel\Strand\StrandInterface; /** - * Public interface for manipulating the kernel and the current strand. + * The default kernel API implementation. */ -interface KernelApiInterface +class StandardKernelApi implements KernelApi { /** * Get the strand the coroutine is executing on. * * @param StrandInterface $strand The currently executing strand. */ - public function strand(StrandInterface $strand); + public function strand(StrandInterface $strand) + { + $strand->resumeWithValue($strand); + } /** * Get the coroutine kernel that the current strand is executing on. * * @param StrandInterface $strand The currently executing strand. */ - public function kernel(StrandInterface $strand); + public function kernel(StrandInterface $strand) + { + $strand->resumeWithValue($strand->kernel()); + } /** * Get the React event-loop that the coroutine kernel is executing on. * * @param StrandInterface $strand The currently executing strand. */ - public function eventLoop(StrandInterface $strand); + public function eventLoop(StrandInterface $strand) + { + $strand->resumeWithValue($strand->kernel()->eventLoop()); + } /** * Return a value to the calling coroutine. @@ -37,7 +46,10 @@ public function eventLoop(StrandInterface $strand); * @param StrandInterface $strand The currently executing strand. * @param mixed $value The value to send to the calling coroutine. */ - public function return_(StrandInterface $strand, $value = null); + public function return_(StrandInterface $strand, $value = null) + { + $strand->returnValue($value); + } /** * Throw an exception to the calling coroutine. @@ -45,7 +57,10 @@ public function return_(StrandInterface $strand, $value = null); * @param StrandInterface $strand The currently executing strand. * @param Exception $exception The error to send to the calling coroutine. */ - public function throw_(StrandInterface $strand, Exception $exception); + public function throw_(StrandInterface $strand, Exception $exception) + { + $strand->throwException($exception); + } /** * Register a callback to be invoked when the current coroutine is popped @@ -57,14 +72,22 @@ public function throw_(StrandInterface $strand, Exception $exception); * @param StrandInterface $strand The currently executing strand. * @param callable $callback The callback to invoke. */ - public function finally_(StrandInterface $strand, callable $callback); + public function finally_(StrandInterface $strand, callable $callback) + { + $strand->current()->registerFinalizeCallback($callback); + + $strand->resumeWithValue(null); + } /** * Terminate execution of the strand. * * @param StrandInterface $strand The currently executing strand. */ - public function terminate(StrandInterface $strand); + public function terminate(StrandInterface $strand) + { + $strand->terminate(); + } /** * Suspend execution for a specified period of time. @@ -72,15 +95,22 @@ public function terminate(StrandInterface $strand); * @param StrandInterface $strand The currently executing strand. * @param number $timeout The number of seconds to wait before resuming. */ - public function sleep(StrandInterface $strand, $timeout); + public function sleep(StrandInterface $strand, $timeout) + { + return new Sleep($timeout); + } /** - * Suspend execution of the strand until it is resumed manually. + * Suspend execution of the strand. * - * @param StrandInterface $strand The currently executing strand. - * @param callable $callback A callback which is passed the strand after it is suspended. + * @param StrandInterface $strand The currently executing strand. */ - public function suspend(StrandInterface $strand, callable $callback); + public function suspend(StrandInterface $strand, callable $callback) + { + $strand->suspend(); + + $callback($strand); + } /** * Execute a coroutine with a time limit. @@ -92,7 +122,10 @@ public function suspend(StrandInterface $strand, callable $callback); * @param number $timeout The number of seconds to wait before cancelling. * @param mixed $coroutine The coroutine to execute. */ - public function timeout(StrandInterface $strand, $timeout, $coroutine); + public function timeout(StrandInterface $strand, $timeout, $coroutine) + { + return new Timeout($timeout, $coroutine); + } /** * Execute the given coroutines concurrently. @@ -104,21 +137,39 @@ public function timeout(StrandInterface $strand, $timeout, $coroutine); * @param StrandInterface $strand The currently executing strand. * @param array $coroutines The coroutines to execute. */ - public function all(StrandInterface $strand, array $coroutines); + public function all(StrandInterface $strand, array $coroutines) + { + return new WaitAll($coroutines); + } /** - * Resume the strand immediately. + * Suspend the strand until the next tick. * * @param StrandInterface $strand The currently executing strand. */ - public function noop(StrandInterface $strand); + public function cooperate(StrandInterface $strand) + { + $strand->suspend(); + + $strand + ->kernel() + ->eventLoop() + ->futureTick( + function () use ($strand) { + $strand->resumeWithValue(null); + } + ); + } /** - * Suspend the strand until the next tick. + * Resume the strand immediately. * * @param StrandInterface $strand The currently executing strand. */ - public function cooperate(StrandInterface $strand); + public function noop(StrandInterface $strand) + { + $strand->resumeWithValue(null); + } /** * Execute a coroutine on its own strand. @@ -126,7 +177,14 @@ public function cooperate(StrandInterface $strand); * @param StrandInterface $strand The currently executing strand. * @param mixed $coroutine The coroutine to execute. */ - public function execute(StrandInterface $strand, $coroutine); + public function execute(StrandInterface $strand, $coroutine) + { + $substrand = $strand + ->kernel() + ->execute($coroutine); + + $strand->resumeWithValue($substrand); + } /** * Wait for one or more of the given strands to exit. @@ -134,7 +192,10 @@ public function execute(StrandInterface $strand, $coroutine); * @param StrandInterface $strand The currently executing strand. * @param StrandInterface[] $strands The strands to wait for. */ - public function select(StrandInterface $strand, array $strands); + public function select(StrandInterface $strand, array $strands) + { + return new Select($strands); + } /** * Stop the coroutine kernel / event-loop. @@ -145,5 +206,12 @@ public function select(StrandInterface $strand, array $strands); * @param StrandInterface $strand The currently executing strand. * @param boolean $stopEventLoop Indicates whether or not the React event-loop should also be stopped. */ - public function stop(StrandInterface $strand, $stopEventLoop = true); + public function stop(StrandInterface $strand, $stopEventLoop = true) + { + $strand->terminate(); + + $strand + ->kernel() + ->stop($stopEventLoop); + } } diff --git a/src/Kernel/Api/Timeout.php b/src/Kernel/Api/Timeout.php index 3fc7d04..87d9729 100644 --- a/src/Kernel/Api/Timeout.php +++ b/src/Kernel/Api/Timeout.php @@ -9,9 +9,9 @@ use Recoil\Kernel\Strand\StrandInterface; /** - * Internal implementation of KernelApiInterface::timeout(). + * Internal implementation of KernelApi::timeout(). * - * @internal + * @access private */ class Timeout implements Coroutine { diff --git a/src/Kernel/Api/WaitAll.php b/src/Kernel/Api/WaitAll.php index 5a8f93b..e7b9d29 100644 --- a/src/Kernel/Api/WaitAll.php +++ b/src/Kernel/Api/WaitAll.php @@ -9,9 +9,9 @@ use Recoil\Kernel\Strand\StrandInterface; /** - * Internal implementation of KernelApiInterface::all(). + * Internal implementation of KernelApi::all(). * - * @internal + * @access private */ class WaitAll implements Coroutine { diff --git a/src/Kernel/Kernel.php b/src/Kernel/Kernel.php index 8b9f40c..150c7d9 100644 --- a/src/Kernel/Kernel.php +++ b/src/Kernel/Kernel.php @@ -2,57 +2,16 @@ namespace Recoil\Kernel; -use React\EventLoop\Factory as EventLoopFactory; use React\EventLoop\LoopInterface; use Recoil\Coroutine\CoroutineAdaptor; -use Recoil\Coroutine\StandardCoroutineAdaptor; -use Recoil\Kernel\Api\KernelApi; -use Recoil\Kernel\Api\KernelApiInterface; -use Recoil\Kernel\Strand\StrandFactory; use Recoil\Kernel\Strand\StrandFactoryInterface; use Recoil\Kernel\Strand\StrandInterface; /** - * The default kernel implementation. + * A coroutine kernel. */ -class Kernel implements KernelInterface +interface Kernel { - /** - * @param LoopInterface|null $eventLoop The React event-loop. - * @param KernelApiInterface|null $api The kernel's API implementation. - * @param CoroutineAdaptor|null $coroutineAdaptor The kernel's coroutine adaptor. - * @param StrandFactoryInterface|null $strandFactory The kernel's strand factory. - */ - public function __construct( - LoopInterface $eventLoop = null, - KernelApiInterface $api = null, - CoroutineAdaptor $coroutineAdaptor = null, - StrandFactoryInterface $strandFactory = null - ) { - if (null === $eventLoop) { - $eventLoop = EventLoopFactory::create(); - } - - if (null === $api) { - $api = new KernelApi(); - } - - if (null === $coroutineAdaptor) { - $coroutineAdaptor = new StandardCoroutineAdaptor(); - } - - if (null === $strandFactory) { - $strandFactory = new StrandFactory(); - } - - $this->eventLoop = $eventLoop; - $this->api = $api; - $this->coroutineAdaptor = $coroutineAdaptor; - $this->strandFactory = $strandFactory; - $this->strands = []; - $this->terminateStrands = false; - } - /** * Execute a coroutine in a new strand of execution. * @@ -63,81 +22,49 @@ public function __construct( * * @return StrandInterface The strand on which the coroutine will execute. */ - public function execute($coroutine) - { - $strand = $this->strandFactory()->createStrand($this); - $strand->call($coroutine); - - return $strand; - } + public function execute($coroutine); /** * Attach an existing strand to this kernel. * * @param StrandInterface The strand to attach. */ - public function attachStrand(StrandInterface $strand) - { - if (!$this->strands) { - $this->eventLoop->futureTick([$this, 'onTick']); - } - - $this->strands[] = $strand; - } + public function attachStrand(StrandInterface $strand); /** * Detach an existing strand from this kernel. * * @param StrandInterface The strand to detach. */ - public function detachStrand(StrandInterface $strand) - { - $index = array_search($strand, $this->strands, true); - - if (false !== $index) { - unset($this->strands[$index]); - } - } + public function detachStrand(StrandInterface $strand); /** * Fetch the object that implements the kernel API. * - * @return KernelApiInterface The kernel's API implementation. + * @return KernelApi The kernel's API implementation. */ - public function api() - { - return $this->api; - } + public function api(); /** * Fetch the object used to adapt values into coroutines. * * @return CoroutineAdaptor The kernel's coroutine adaptor. */ - public function coroutineAdaptor() - { - return $this->coroutineAdaptor; - } + public function coroutineAdaptor(); /** * Fetch the factory used to create new strands. * * @return StrandFactoryInterface The kernel's strand factory. */ - public function strandFactory() - { - return $this->strandFactory; - } + public function strandFactory(); /** * Fetch the React event-loop. * * @return LoopInterface The React event-loop. */ - public function eventLoop() - { - return $this->eventLoop; - } + public function eventLoop(); /** * Terminate all strands and stop execution. @@ -147,44 +74,5 @@ public function eventLoop() * * @param boolean $stopEventLoop Indicates whether or not the React event-loop should also be stopped. */ - public function stop($stopEventLoop = true) - { - $this->terminateStrands = true; - $this->stopEventLoop = $stopEventLoop; - } - - /** - * Step each of the strands attached to this kernel. - * - * @internal - */ - public function onTick() - { - $strands = $this->strands; - - foreach ($strands as $strand) { - if ($this->terminateStrands) { - $strand->terminate(); - } - - $strand->tick(); - } - - if ($this->strands) { - $this->eventLoop->futureTick([$this, 'onTick']); - } elseif ($this->stopEventLoop) { - $this->eventLoop->stop(); - } - - $this->terminateStrands = false; - $this->stopEventLoop = false; - } - - private $eventLoop; - private $api; - private $coroutineAdaptor; - private $strandFactory; - private $strands; - private $terminateStrands; - private $stopEventLoop; + public function stop($stopEventLoop = true); } diff --git a/src/Kernel/KernelInterface.php b/src/Kernel/KernelInterface.php deleted file mode 100644 index 772a0b2..0000000 --- a/src/Kernel/KernelInterface.php +++ /dev/null @@ -1,78 +0,0 @@ -eventLoop = $eventLoop; + $this->api = $api; + $this->coroutineAdaptor = $coroutineAdaptor; + $this->strandFactory = $strandFactory; + $this->strands = []; + $this->terminateStrands = false; + } + + /** + * Execute a coroutine in a new strand of execution. + * + * The parameter may be any value that can be adapted into a coroutine by + * the kernel's coroutine adaptor. + * + * @param mixed $coroutine The coroutine to execute. + * + * @return StrandInterface The strand on which the coroutine will execute. + */ + public function execute($coroutine) + { + $strand = $this->strandFactory()->createStrand($this); + $strand->call($coroutine); + + return $strand; + } + + /** + * Attach an existing strand to this kernel. + * + * @param StrandInterface The strand to attach. + */ + public function attachStrand(StrandInterface $strand) + { + if (!$this->strands) { + $this->eventLoop->futureTick([$this, 'onTick']); + } + + $this->strands[] = $strand; + } + + /** + * Detach an existing strand from this kernel. + * + * @param StrandInterface The strand to detach. + */ + public function detachStrand(StrandInterface $strand) + { + $index = array_search($strand, $this->strands, true); + + if (false !== $index) { + unset($this->strands[$index]); + } + } + + /** + * Fetch the object that implements the kernel API. + * + * @return KernelApi The kernel's API implementation. + */ + public function api() + { + return $this->api; + } + + /** + * Fetch the object used to adapt values into coroutines. + * + * @return CoroutineAdaptor The kernel's coroutine adaptor. + */ + public function coroutineAdaptor() + { + return $this->coroutineAdaptor; + } + + /** + * Fetch the factory used to create new strands. + * + * @return StrandFactoryInterface The kernel's strand factory. + */ + public function strandFactory() + { + return $this->strandFactory; + } + + /** + * Fetch the React event-loop. + * + * @return LoopInterface The React event-loop. + */ + public function eventLoop() + { + return $this->eventLoop; + } + + /** + * Terminate all strands and stop execution. + * + * The React event-loop can optionally be stopped when all strands have been + * terminated. + * + * @param boolean $stopEventLoop Indicates whether or not the React event-loop should also be stopped. + */ + public function stop($stopEventLoop = true) + { + $this->terminateStrands = true; + $this->stopEventLoop = $stopEventLoop; + } + + /** + * Step each of the strands attached to this kernel. + * + * @access private + */ + public function onTick() + { + $strands = $this->strands; + + foreach ($strands as $strand) { + if ($this->terminateStrands) { + $strand->terminate(); + } + + $strand->tick(); + } + + if ($this->strands) { + $this->eventLoop->futureTick([$this, 'onTick']); + } elseif ($this->stopEventLoop) { + $this->eventLoop->stop(); + } + + $this->terminateStrands = false; + $this->stopEventLoop = false; + } + + private $eventLoop; + private $api; + private $coroutineAdaptor; + private $strandFactory; + private $strands; + private $terminateStrands; + private $stopEventLoop; +} diff --git a/src/Kernel/Strand/StackBase.php b/src/Kernel/Strand/StackBase.php index 3b151db..d95e5cb 100644 --- a/src/Kernel/Strand/StackBase.php +++ b/src/Kernel/Strand/StackBase.php @@ -10,7 +10,7 @@ /** * The base coroutine in a strand's call-stack. * - * @internal + * @access private */ class StackBase implements Coroutine { diff --git a/src/Kernel/Strand/Strand.php b/src/Kernel/Strand/Strand.php index 2d35dd3..fcb67a3 100644 --- a/src/Kernel/Strand/Strand.php +++ b/src/Kernel/Strand/Strand.php @@ -6,7 +6,7 @@ use Exception; use LogicException; use Recoil\Coroutine\Coroutine; -use Recoil\Kernel\KernelInterface; +use Recoil\Kernel\Kernel; /** * A strand represents a user-space "thread" of execution. @@ -21,9 +21,9 @@ class Strand extends EventEmitter implements StrandInterface { /** - * @param KernelInterface The coroutine kernel. + * @param Kernel The coroutine kernel. */ - public function __construct(KernelInterface $kernel) + public function __construct(Kernel $kernel) { $this->kernel = $kernel; $this->suspended = false; @@ -37,7 +37,7 @@ public function __construct(KernelInterface $kernel) /** * Fetch the kernel on which this strand is executing. * - * @return KernelInterface The coroutine kernel. + * @return Kernel The coroutine kernel. */ public function kernel() { diff --git a/src/Kernel/Strand/StrandFactory.php b/src/Kernel/Strand/StrandFactory.php index 84c1d37..e7cbca3 100644 --- a/src/Kernel/Strand/StrandFactory.php +++ b/src/Kernel/Strand/StrandFactory.php @@ -2,7 +2,7 @@ namespace Recoil\Kernel\Strand; -use Recoil\Kernel\KernelInterface; +use Recoil\Kernel\Kernel; /** * The default strand factory. @@ -12,11 +12,11 @@ class StrandFactory implements StrandFactoryInterface /** * Create a strand. * - * @param KernelInterface The kernel on which the strand will execute. + * @param Kernel The kernel on which the strand will execute. * * @return StrandInterface */ - public function createStrand(KernelInterface $kernel) + public function createStrand(Kernel $kernel) { return new Strand($kernel); } diff --git a/src/Kernel/Strand/StrandFactoryInterface.php b/src/Kernel/Strand/StrandFactoryInterface.php index 7b84897..5bc9cd4 100644 --- a/src/Kernel/Strand/StrandFactoryInterface.php +++ b/src/Kernel/Strand/StrandFactoryInterface.php @@ -2,7 +2,7 @@ namespace Recoil\Kernel\Strand; -use Recoil\Kernel\KernelInterface; +use Recoil\Kernel\Kernel; /** * A factory for strands. @@ -12,9 +12,9 @@ interface StrandFactoryInterface /** * Create a strand. * - * @param KernelInterface $kernel The kernel on which the strand will execute. + * @param Kernel $kernel The kernel on which the strand will execute. * * @return StrandInterface */ - public function createStrand(KernelInterface $kernel); + public function createStrand(Kernel $kernel); } diff --git a/src/Kernel/Strand/StrandInterface.php b/src/Kernel/Strand/StrandInterface.php index d0c4fe3..35ea4f3 100644 --- a/src/Kernel/Strand/StrandInterface.php +++ b/src/Kernel/Strand/StrandInterface.php @@ -5,7 +5,7 @@ use Evenement\EventEmitterInterface; use Exception; use Recoil\Coroutine\Coroutine; -use Recoil\Kernel\KernelInterface; +use Recoil\Kernel\Kernel; /** * A strand represents a user-space "thread" of execution. @@ -22,7 +22,7 @@ interface StrandInterface extends EventEmitterInterface /** * Fetch the kernel on which this strand is executing. * - * @return KernelInterface The coroutine kernel. + * @return Kernel The coroutine kernel. */ public function kernel(); diff --git a/src/Recoil.php b/src/Recoil.php index 4c74af7..4f003a7 100644 --- a/src/Recoil.php +++ b/src/Recoil.php @@ -4,7 +4,7 @@ use React\EventLoop\LoopInterface; use Recoil\Kernel\Api\KernelApiCall; -use Recoil\Kernel\Kernel; +use Recoil\Kernel\StandardKernel; use Recoil\Kernel\Strand\StrandInterface; /** @@ -14,8 +14,8 @@ * implementation provided by whichever coroutine kernel is currently being * used for execution. * - * The interface {@link Recoil\Kernel\KernelApiInterface} defines the - * operations that are available; some kernels may provide additional features. + * The interface {@link Recoil\Kernel\KernelApi} defines the operations that are + * available; some kernels may provide additional features. * * @method static strand() [COROUTINE] Get the strand the coroutine is executing on. * @method static kernel() [COROUTINE] Get the coroutine kernel that the current strand is executing on. @@ -39,8 +39,8 @@ abstract class Recoil /** * [COROUTINE] Invoke a kernel API function. * - * @see Recoil\Kernel\KernelApiInterface - * @see Recoil\Kernel\KernelInterface::api() + * @see Recoil\Kernel\KernelApi + * @see Recoil\Kernel\Kernel::api() * * @param string $name The name of the kernel API function to invoke. * @param array $arguments The arguments to the kernel API function. @@ -61,7 +61,7 @@ public static function __callStatic($name, array $arguments) */ public static function run(callable $entryPoint, LoopInterface $eventLoop = null) { - $kernel = new Kernel($eventLoop); + $kernel = new StandardKernel($eventLoop); $kernel->execute($entryPoint()); $kernel->eventLoop()->run(); } diff --git a/src/Stream/ReadableReactStream.php b/src/Stream/ReadableReactStream.php index a8107b2..fe00106 100644 --- a/src/Stream/ReadableReactStream.php +++ b/src/Stream/ReadableReactStream.php @@ -109,7 +109,7 @@ public function isClosed() } /** - * @internal + * @access private */ public function onStreamData($data) { @@ -125,7 +125,7 @@ public function onStreamData($data) } /** - * @internal + * @access private */ public function onStreamEnd() { @@ -140,7 +140,7 @@ public function onStreamEnd() } /** - * @internal + * @access private */ public function onStreamClose() { @@ -156,7 +156,7 @@ public function onStreamClose() } /** - * @internal + * @access private */ public function onStreamError(Exception $exception) { diff --git a/src/Stream/WritableReactStream.php b/src/Stream/WritableReactStream.php index 0991d75..8a3b59c 100644 --- a/src/Stream/WritableReactStream.php +++ b/src/Stream/WritableReactStream.php @@ -130,7 +130,7 @@ public function isClosed() } /** - * @internal + * @access private */ public function onStreamDrain() { @@ -140,7 +140,7 @@ public function onStreamDrain() } /** - * @internal + * @access private */ public function onStreamError(Exception $exception) { diff --git a/test/src/Recoil/Channel/LoopbackChannelTestTrait.php b/test/src/Recoil/Channel/LoopbackChannelTestTrait.php index 60618b8..71a416f 100644 --- a/test/src/Recoil/Channel/LoopbackChannelTestTrait.php +++ b/test/src/Recoil/Channel/LoopbackChannelTestTrait.php @@ -2,8 +2,6 @@ namespace Recoil\Channel; -use Recoil\Kernel\Kernel; - trait LoopbackChannelTestTrait { public function testReadThenWrite() diff --git a/test/suite/Channel/ChannelTest.php b/test/suite/Channel/ChannelTest.php index 6f00729..5497720 100644 --- a/test/suite/Channel/ChannelTest.php +++ b/test/suite/Channel/ChannelTest.php @@ -4,7 +4,7 @@ use PHPUnit_Framework_TestCase; use Recoil\Channel\Exception\ChannelClosedException; -use Recoil\Kernel\Kernel; +use Recoil\Kernel\StandardKernel; class ChannelTest extends PHPUnit_Framework_TestCase { @@ -15,7 +15,7 @@ class ChannelTest extends PHPUnit_Framework_TestCase public function setUp() { - $this->kernel = new Kernel(); + $this->kernel = new StandardKernel(); $this->channel = new Channel(); } diff --git a/test/suite/Coroutine/GeneratorCoroutineTest.php b/test/suite/Coroutine/GeneratorCoroutineTest.php index a42f2ce..6039fbe 100644 --- a/test/suite/Coroutine/GeneratorCoroutineTest.php +++ b/test/suite/Coroutine/GeneratorCoroutineTest.php @@ -4,7 +4,7 @@ use Exception; use PHPUnit_Framework_TestCase; -use Recoil\Kernel\Kernel; +use Recoil\Kernel\StandardKernel; use Recoil\Recoil; /** @@ -15,7 +15,7 @@ class GeneratorCoroutineTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->kernel = new Kernel(); + $this->kernel = new StandardKernel(); } public function testCall() diff --git a/test/suite/Coroutine/PromiseCoroutineTest.php b/test/suite/Coroutine/PromiseCoroutineTest.php index 91dc269..63e0fb6 100644 --- a/test/suite/Coroutine/PromiseCoroutineTest.php +++ b/test/suite/Coroutine/PromiseCoroutineTest.php @@ -9,7 +9,7 @@ use React\Promise\Promise; use React\Promise\RejectedPromise; use Recoil\Coroutine\Exception\PromiseRejectedException; -use Recoil\Kernel\Kernel; +use Recoil\Kernel\StandardKernel; use Recoil\Recoil; /** @@ -20,7 +20,7 @@ class PromiseCoroutineTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->kernel = new Kernel(); + $this->kernel = new StandardKernel(); } public function testFulfilledPromise() diff --git a/test/suite/Kernel/Api/KernelApiCallTest.php b/test/suite/Kernel/Api/KernelApiCallTest.php index 8b9207b..bceb397 100644 --- a/test/suite/Kernel/Api/KernelApiCallTest.php +++ b/test/suite/Kernel/Api/KernelApiCallTest.php @@ -6,15 +6,15 @@ use Exception; use Phake; use PHPUnit_Framework_TestCase; -use Recoil\Kernel\Kernel; +use Recoil\Kernel\StandardKernel; use Recoil\Recoil; class KernelApiCallTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->api = Phake::partialMock(KernelApi::class); - $this->kernel = new Kernel(null, $this->api); + $this->api = Phake::partialMock(StandardKernelApi::class); + $this->kernel = new StandardKernel(null, $this->api); } public function testTick() diff --git a/test/suite/Kernel/Api/SelectTest.php b/test/suite/Kernel/Api/SelectTest.php index ed0c549..4acb5ec 100644 --- a/test/suite/Kernel/Api/SelectTest.php +++ b/test/suite/Kernel/Api/SelectTest.php @@ -3,14 +3,14 @@ namespace Recoil\Kernel\Api; use PHPUnit_Framework_TestCase; -use Recoil\Kernel\Kernel; +use Recoil\Kernel\StandardKernel; use Recoil\Recoil; class SelectTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->kernel = new Kernel(); + $this->kernel = new StandardKernel(); } public function testSelect() diff --git a/test/suite/Kernel/Api/SleepTest.php b/test/suite/Kernel/Api/SleepTest.php index 9554add..8ad25c9 100644 --- a/test/suite/Kernel/Api/SleepTest.php +++ b/test/suite/Kernel/Api/SleepTest.php @@ -4,13 +4,13 @@ use Exception; use PHPUnit_Framework_TestCase; -use Recoil\Kernel\Kernel; +use Recoil\Kernel\StandardKernel; class SleepTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->kernel = new Kernel(); + $this->kernel = new StandardKernel(); $this->tolerance = 0.02; } diff --git a/test/suite/Kernel/Api/KernelApiTest.php b/test/suite/Kernel/Api/StandardKernelApiTest.php similarity index 98% rename from test/suite/Kernel/Api/KernelApiTest.php rename to test/suite/Kernel/Api/StandardKernelApiTest.php index 2450949..aa3c6b3 100644 --- a/test/suite/Kernel/Api/KernelApiTest.php +++ b/test/suite/Kernel/Api/StandardKernelApiTest.php @@ -5,19 +5,19 @@ use Exception; use PHPUnit_Framework_TestCase; use Recoil\Kernel\Exception\TimeoutException; -use Recoil\Kernel\Kernel; +use Recoil\Kernel\StandardKernel; use Recoil\Kernel\Strand\StrandInterface; use Recoil\Recoil; /** - * @covers Recoil\Kernel\Api\KernelApi + * @covers Recoil\Kernel\Api\StandardKernelApi * @covers Recoil\Kernel\Api\KernelApiCall */ -class KernelApiTest extends PHPUnit_Framework_TestCase +class StandardKernelApiTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->kernel = new Kernel(); + $this->kernel = new StandardKernel(); $this->tolerance = 0.02; } diff --git a/test/suite/Kernel/Api/TimeoutTest.php b/test/suite/Kernel/Api/TimeoutTest.php index 31a9282..0152c11 100644 --- a/test/suite/Kernel/Api/TimeoutTest.php +++ b/test/suite/Kernel/Api/TimeoutTest.php @@ -5,14 +5,14 @@ use Exception; use PHPUnit_Framework_TestCase; use Recoil\Kernel\Exception\TimeoutException; -use Recoil\Kernel\Kernel; +use Recoil\Kernel\StandardKernel; use Recoil\Recoil; class TimeoutTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->kernel = new Kernel(); + $this->kernel = new StandardKernel(); } public function testTimeout() diff --git a/test/suite/Kernel/KernelFunctionalTest.php b/test/suite/Kernel/StandardKernelFunctionalTest.php similarity index 97% rename from test/suite/Kernel/KernelFunctionalTest.php rename to test/suite/Kernel/StandardKernelFunctionalTest.php index f2449bf..6b258fb 100644 --- a/test/suite/Kernel/KernelFunctionalTest.php +++ b/test/suite/Kernel/StandardKernelFunctionalTest.php @@ -10,11 +10,11 @@ /** * @group functional */ -class KernelFunctionalTest extends PHPUnit_Framework_TestCase +class StandardKernelFunctionalTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->kernel = new Kernel(); + $this->kernel = new StandardKernel(); } /** diff --git a/test/suite/Kernel/KernelTest.php b/test/suite/Kernel/StandardKernelTest.php similarity index 82% rename from test/suite/Kernel/KernelTest.php rename to test/suite/Kernel/StandardKernelTest.php index e465d21..4afb808 100644 --- a/test/suite/Kernel/KernelTest.php +++ b/test/suite/Kernel/StandardKernelTest.php @@ -5,20 +5,20 @@ use PHPUnit_Framework_TestCase; use React\EventLoop\LoopInterface; use Recoil\Coroutine\StandardCoroutineAdaptor; -use Recoil\Kernel\Api\KernelApi; +use Recoil\Kernel\Api\StandardKernelApi; use Recoil\Kernel\Strand\StrandFactory; use Recoil\Recoil; -class KernelTest extends PHPUnit_Framework_TestCase +class StandardKernelTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->kernel = new Kernel(); + $this->kernel = new StandardKernel(); } public function testConstructorDefaults() { - $this->assertInstanceOf(KernelApi::class, $this->kernel->api()); + $this->assertInstanceOf(StandardKernelApi::class, $this->kernel->api()); $this->assertInstanceOf(StandardCoroutineAdaptor::class, $this->kernel->coroutineAdaptor()); $this->assertInstanceOf(StrandFactory::class, $this->kernel->strandFactory()); $this->assertInstanceOf(LoopInterface::class, $this->kernel->eventLoop()); diff --git a/test/suite/Kernel/Strand/StrandFunctionalTest.php b/test/suite/Kernel/Strand/StrandFunctionalTest.php index 4a68113..9265821 100644 --- a/test/suite/Kernel/Strand/StrandFunctionalTest.php +++ b/test/suite/Kernel/Strand/StrandFunctionalTest.php @@ -4,7 +4,7 @@ use Exception; use PHPUnit_Framework_TestCase; -use Recoil\Kernel\Kernel; +use Recoil\Kernel\StandardKernel; use Recoil\Recoil; /** @@ -14,7 +14,7 @@ class StrandFunctionalTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->kernel = new Kernel(); + $this->kernel = new StandardKernel(); } /** From 35ae1d1f576650d8fd2337c9688f9799a2f44f6e Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 12:58:57 +1000 Subject: [PATCH 15/24] Renamed stand and factory (#78). --- src/Kernel/StandardKernel.php | 4 ++-- src/Kernel/Strand/{Strand.php => StandardStrand.php} | 2 +- .../Strand/{StrandFactory.php => StandardStrandFactory.php} | 4 ++-- test/suite/Kernel/StandardKernelTest.php | 4 ++-- ...andFunctionalTest.php => StandardStrandFunctionalTest.php} | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) rename src/Kernel/Strand/{Strand.php => StandardStrand.php} (98%) rename src/Kernel/Strand/{StrandFactory.php => StandardStrandFactory.php} (75%) rename test/suite/Kernel/Strand/{StrandFunctionalTest.php => StandardStrandFunctionalTest.php} (98%) diff --git a/src/Kernel/StandardKernel.php b/src/Kernel/StandardKernel.php index 2cad523..46b600e 100644 --- a/src/Kernel/StandardKernel.php +++ b/src/Kernel/StandardKernel.php @@ -8,7 +8,7 @@ use Recoil\Coroutine\StandardCoroutineAdaptor; use Recoil\Kernel\Api\KernelApi; use Recoil\Kernel\Api\StandardKernelApi; -use Recoil\Kernel\Strand\StrandFactory; +use Recoil\Kernel\Strand\StandardStrandFactory; use Recoil\Kernel\Strand\StrandFactoryInterface; use Recoil\Kernel\Strand\StrandInterface; @@ -42,7 +42,7 @@ public function __construct( } if (null === $strandFactory) { - $strandFactory = new StrandFactory(); + $strandFactory = new StandardStrandFactory(); } $this->eventLoop = $eventLoop; diff --git a/src/Kernel/Strand/Strand.php b/src/Kernel/Strand/StandardStrand.php similarity index 98% rename from src/Kernel/Strand/Strand.php rename to src/Kernel/Strand/StandardStrand.php index fcb67a3..223f559 100644 --- a/src/Kernel/Strand/Strand.php +++ b/src/Kernel/Strand/StandardStrand.php @@ -18,7 +18,7 @@ * @event suspend Execution of the strand has been suspended. * @event resumed Execution of the strand has been resumed. */ -class Strand extends EventEmitter implements StrandInterface +class StandardStrand extends EventEmitter implements StrandInterface { /** * @param Kernel The coroutine kernel. diff --git a/src/Kernel/Strand/StrandFactory.php b/src/Kernel/Strand/StandardStrandFactory.php similarity index 75% rename from src/Kernel/Strand/StrandFactory.php rename to src/Kernel/Strand/StandardStrandFactory.php index e7cbca3..92e50bf 100644 --- a/src/Kernel/Strand/StrandFactory.php +++ b/src/Kernel/Strand/StandardStrandFactory.php @@ -7,7 +7,7 @@ /** * The default strand factory. */ -class StrandFactory implements StrandFactoryInterface +class StandardStrandFactory implements StrandFactoryInterface { /** * Create a strand. @@ -18,6 +18,6 @@ class StrandFactory implements StrandFactoryInterface */ public function createStrand(Kernel $kernel) { - return new Strand($kernel); + return new StandardStrand($kernel); } } diff --git a/test/suite/Kernel/StandardKernelTest.php b/test/suite/Kernel/StandardKernelTest.php index 4afb808..c6dc47b 100644 --- a/test/suite/Kernel/StandardKernelTest.php +++ b/test/suite/Kernel/StandardKernelTest.php @@ -6,7 +6,7 @@ use React\EventLoop\LoopInterface; use Recoil\Coroutine\StandardCoroutineAdaptor; use Recoil\Kernel\Api\StandardKernelApi; -use Recoil\Kernel\Strand\StrandFactory; +use Recoil\Kernel\Strand\StandardStrandFactory; use Recoil\Recoil; class StandardKernelTest extends PHPUnit_Framework_TestCase @@ -20,7 +20,7 @@ public function testConstructorDefaults() { $this->assertInstanceOf(StandardKernelApi::class, $this->kernel->api()); $this->assertInstanceOf(StandardCoroutineAdaptor::class, $this->kernel->coroutineAdaptor()); - $this->assertInstanceOf(StrandFactory::class, $this->kernel->strandFactory()); + $this->assertInstanceOf(StandardStrandFactory::class, $this->kernel->strandFactory()); $this->assertInstanceOf(LoopInterface::class, $this->kernel->eventLoop()); } diff --git a/test/suite/Kernel/Strand/StrandFunctionalTest.php b/test/suite/Kernel/Strand/StandardStrandFunctionalTest.php similarity index 98% rename from test/suite/Kernel/Strand/StrandFunctionalTest.php rename to test/suite/Kernel/Strand/StandardStrandFunctionalTest.php index 9265821..6048b4c 100644 --- a/test/suite/Kernel/Strand/StrandFunctionalTest.php +++ b/test/suite/Kernel/Strand/StandardStrandFunctionalTest.php @@ -10,7 +10,7 @@ /** * @group functional */ -class StrandFunctionalTest extends PHPUnit_Framework_TestCase +class StandardStrandFunctionalTest extends PHPUnit_Framework_TestCase { public function setUp() { @@ -330,7 +330,7 @@ public function testTerminateEvent() public function testTickWithoutAction() { - $strand = new Strand($this->kernel); + $strand = new StandardStrand($this->kernel); $this->setExpectedException( 'LogicException', From e045cb05d24f449e36c9776ea06e7fad071b3c2e Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 13:00:20 +1000 Subject: [PATCH 16/24] Renamed StrandFactoryInterface (#78). --- src/Kernel/Kernel.php | 4 ++-- src/Kernel/StandardKernel.php | 8 ++++---- src/Kernel/Strand/StandardStrandFactory.php | 2 +- .../{StrandFactoryInterface.php => StrandFactory.php} | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) rename src/Kernel/Strand/{StrandFactoryInterface.php => StrandFactory.php} (90%) diff --git a/src/Kernel/Kernel.php b/src/Kernel/Kernel.php index 150c7d9..0c02cb0 100644 --- a/src/Kernel/Kernel.php +++ b/src/Kernel/Kernel.php @@ -4,7 +4,7 @@ use React\EventLoop\LoopInterface; use Recoil\Coroutine\CoroutineAdaptor; -use Recoil\Kernel\Strand\StrandFactoryInterface; +use Recoil\Kernel\Strand\StrandFactory; use Recoil\Kernel\Strand\StrandInterface; /** @@ -55,7 +55,7 @@ public function coroutineAdaptor(); /** * Fetch the factory used to create new strands. * - * @return StrandFactoryInterface The kernel's strand factory. + * @return StrandFactory The kernel's strand factory. */ public function strandFactory(); diff --git a/src/Kernel/StandardKernel.php b/src/Kernel/StandardKernel.php index 46b600e..d77b982 100644 --- a/src/Kernel/StandardKernel.php +++ b/src/Kernel/StandardKernel.php @@ -9,7 +9,7 @@ use Recoil\Kernel\Api\KernelApi; use Recoil\Kernel\Api\StandardKernelApi; use Recoil\Kernel\Strand\StandardStrandFactory; -use Recoil\Kernel\Strand\StrandFactoryInterface; +use Recoil\Kernel\Strand\StrandFactory; use Recoil\Kernel\Strand\StrandInterface; /** @@ -21,13 +21,13 @@ class StandardKernel implements Kernel * @param LoopInterface|null $eventLoop The React event-loop. * @param KernelApi|null $api The kernel's API implementation. * @param CoroutineAdaptor|null $coroutineAdaptor The kernel's coroutine adaptor. - * @param StrandFactoryInterface|null $strandFactory The kernel's strand factory. + * @param StrandFactory|null $strandFactory The kernel's strand factory. */ public function __construct( LoopInterface $eventLoop = null, KernelApi $api = null, CoroutineAdaptor $coroutineAdaptor = null, - StrandFactoryInterface $strandFactory = null + StrandFactory $strandFactory = null ) { if (null === $eventLoop) { $eventLoop = EventLoopFactory::create(); @@ -122,7 +122,7 @@ public function coroutineAdaptor() /** * Fetch the factory used to create new strands. * - * @return StrandFactoryInterface The kernel's strand factory. + * @return StrandFactory The kernel's strand factory. */ public function strandFactory() { diff --git a/src/Kernel/Strand/StandardStrandFactory.php b/src/Kernel/Strand/StandardStrandFactory.php index 92e50bf..fa0bf79 100644 --- a/src/Kernel/Strand/StandardStrandFactory.php +++ b/src/Kernel/Strand/StandardStrandFactory.php @@ -7,7 +7,7 @@ /** * The default strand factory. */ -class StandardStrandFactory implements StrandFactoryInterface +class StandardStrandFactory implements StrandFactory { /** * Create a strand. diff --git a/src/Kernel/Strand/StrandFactoryInterface.php b/src/Kernel/Strand/StrandFactory.php similarity index 90% rename from src/Kernel/Strand/StrandFactoryInterface.php rename to src/Kernel/Strand/StrandFactory.php index 5bc9cd4..879ce0a 100644 --- a/src/Kernel/Strand/StrandFactoryInterface.php +++ b/src/Kernel/Strand/StrandFactory.php @@ -7,7 +7,7 @@ /** * A factory for strands. */ -interface StrandFactoryInterface +interface StrandFactory { /** * Create a strand. From e700216d35b8605438576c061ab8037017d28a29 Mon Sep 17 00:00:00 2001 From: James Harris Date: Tue, 17 Nov 2015 13:04:25 +1000 Subject: [PATCH 17/24] Rename StrandInterface -> Strand (#78). --- CHANGELOG.md | 2 +- examples/strand-suspend-resume | 4 +- src/Coroutine/Coroutine.php | 26 +++--- src/Coroutine/CoroutineAdaptor.php | 8 +- src/Coroutine/CoroutineProvider.php | 6 +- src/Coroutine/CoroutineTrait.php | 26 +++--- src/Coroutine/GeneratorCoroutine.php | 22 ++--- src/Coroutine/PromiseCoroutine.php | 14 +-- src/Coroutine/StandardCoroutineAdaptor.php | 8 +- src/Kernel/Api/KernelApi.php | 88 +++++++++---------- src/Kernel/Api/KernelApiCall.php | 6 +- src/Kernel/Api/Select.php | 12 +-- src/Kernel/Api/Sleep.php | 10 +-- src/Kernel/Api/StandardKernelApi.php | 86 +++++++++--------- src/Kernel/Api/Timeout.php | 14 +-- src/Kernel/Api/WaitAll.php | 10 +-- src/Kernel/Kernel.php | 12 +-- src/Kernel/StandardKernel.php | 20 ++--- src/Kernel/Strand/StackBase.php | 20 ++--- src/Kernel/Strand/StandardStrand.php | 2 +- src/Kernel/Strand/StandardStrandFactory.php | 2 +- .../{StrandInterface.php => Strand.php} | 2 +- src/Kernel/Strand/StrandFactory.php | 2 +- src/Recoil.php | 4 +- .../StandardCoroutineAdaptorTest.php | 4 +- .../Kernel/Api/StandardKernelApiTest.php | 4 +- 26 files changed, 207 insertions(+), 207 deletions(-) rename src/Kernel/Strand/{StrandInterface.php => Strand.php} (98%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d41aa7..2018fc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ To faciliate several performance improvements the following backwards compatibility breaking changes have been introduced: * **[BC]** `CoroutineInterface` no longer implements `EventEmitterInterface` - several unused events were fired every time a coroutine was called -* **[BC]** `Recoil::finalize()` now only works with generated based coroutines - this was previously implemented using the aforementioned events +* **[BC]** `Recoil::finalize()` now only works with generator based coroutines - this was previously implemented using the aforementioned events ### 0.1.0 (2014-02-04) diff --git a/examples/strand-suspend-resume b/examples/strand-suspend-resume index f420488..1c3d292 100755 --- a/examples/strand-suspend-resume +++ b/examples/strand-suspend-resume @@ -9,7 +9,7 @@ require dirname(__DIR__) . '/vendor/autoload.php'; * coroutine based. */ -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; use Recoil\Recoil; Recoil::run( @@ -20,7 +20,7 @@ Recoil::run( // manually resumed. It accepts a callback that is passed the suspended // strand object. $value = (yield Recoil::suspend( - function (StrandInterface $strand) { + function (Strand $strand) { // Add a timer that resumes the strand after one second. // // A value can be returned to the suspended strand using diff --git a/src/Coroutine/Coroutine.php b/src/Coroutine/Coroutine.php index 5528e49..ec1a0d5 100644 --- a/src/Coroutine/Coroutine.php +++ b/src/Coroutine/Coroutine.php @@ -3,7 +3,7 @@ namespace Recoil\Coroutine; use Exception; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * A coroutine represents a unit of work that can be suspended and resumed. @@ -13,39 +13,39 @@ interface Coroutine /** * Start the coroutine. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function call(StrandInterface $strand); + public function call(Strand $strand); /** * Resume execution of a suspended coroutine by passing it a value. * - * @param StrandInterface $strand The strand that is executing the coroutine. - * @param mixed $value The value to send to the coroutine. + * @param Strand $strand The strand that is executing the coroutine. + * @param mixed $value The value to send to the coroutine. */ - public function resumeWithValue(StrandInterface $strand, $value); + public function resumeWithValue(Strand $strand, $value); /** * Resume execution of a suspended coroutine by passing it an exception. * - * @param StrandInterface $strand The strand that is executing the coroutine. - * @param Exception $exception The exception to send to the coroutine. + * @param Strand $strand The strand that is executing the coroutine. + * @param Exception $exception The exception to send to the coroutine. */ - public function resumeWithException(StrandInterface $strand, Exception $exception); + public function resumeWithException(Strand $strand, Exception $exception); /** * Inform the coroutine that the executing strand is being terminated. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function terminate(StrandInterface $strand); + public function terminate(Strand $strand); /** * Finalize the coroutine. * * This method is invoked after the coroutine is popped from the call stack. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function finalize(StrandInterface $strand); + public function finalize(Strand $strand); } diff --git a/src/Coroutine/CoroutineAdaptor.php b/src/Coroutine/CoroutineAdaptor.php index eb7760c..97f0aa0 100644 --- a/src/Coroutine/CoroutineAdaptor.php +++ b/src/Coroutine/CoroutineAdaptor.php @@ -3,7 +3,7 @@ namespace Recoil\Coroutine; use InvalidArgumentException; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * Adapts arbitrary values into coroutine objects. @@ -13,11 +13,11 @@ interface CoroutineAdaptor /** * Adapt a value into a coroutine. * - * @param StrandInterface $strand The currently executing strand. - * @param mixed $value The value to adapt. + * @param Strand $strand The currently executing strand. + * @param mixed $value The value to adapt. * * @return Coroutine * @throws InvalidArgumentException if now valid adaptation can be made. */ - public function adapt(StrandInterface $strand, $value); + public function adapt(Strand $strand, $value); } diff --git a/src/Coroutine/CoroutineProvider.php b/src/Coroutine/CoroutineProvider.php index 900642a..48919ee 100644 --- a/src/Coroutine/CoroutineProvider.php +++ b/src/Coroutine/CoroutineProvider.php @@ -2,7 +2,7 @@ namespace Recoil\Coroutine; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * A coroutine provide is an object that can produce an object that can be @@ -13,9 +13,9 @@ interface CoroutineProvider /** * Produce a coroutine. * - * @param StrandInterface $strand The strand that will execute the coroutine. + * @param Strand $strand The strand that will execute the coroutine. * * @return mixed */ - public function coroutine(StrandInterface $strand); + public function coroutine(Strand $strand); } diff --git a/src/Coroutine/CoroutineTrait.php b/src/Coroutine/CoroutineTrait.php index 13fceea..3751f02 100644 --- a/src/Coroutine/CoroutineTrait.php +++ b/src/Coroutine/CoroutineTrait.php @@ -3,7 +3,7 @@ namespace Recoil\Coroutine; use Exception; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * A trait for coroutines that provides basic default implementations. @@ -13,17 +13,17 @@ trait CoroutineTrait /** * Start the coroutine. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - abstract public function call(StrandInterface $strand); + abstract public function call(Strand $strand); /** * Resume execution of a suspended coroutine by passing it a value. * - * @param StrandInterface $strand The strand that is executing the coroutine. - * @param mixed $value The value to send to the coroutine. + * @param Strand $strand The strand that is executing the coroutine. + * @param mixed $value The value to send to the coroutine. */ - public function resumeWithValue(StrandInterface $strand, $value) + public function resumeWithValue(Strand $strand, $value) { $strand->returnValue($value); } @@ -31,10 +31,10 @@ public function resumeWithValue(StrandInterface $strand, $value) /** * Resume execution of a suspended coroutine by passing it an exception. * - * @param StrandInterface $strand The strand that is executing the coroutine. - * @param Exception $exception The exception to send to the coroutine. + * @param Strand $strand The strand that is executing the coroutine. + * @param Exception $exception The exception to send to the coroutine. */ - public function resumeWithException(StrandInterface $strand, Exception $exception) + public function resumeWithException(Strand $strand, Exception $exception) { $strand->throwException($exception); } @@ -42,9 +42,9 @@ public function resumeWithException(StrandInterface $strand, Exception $exceptio /** * Inform the coroutine that the executing strand is being terminated. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function terminate(StrandInterface $strand) + public function terminate(Strand $strand) { } @@ -53,9 +53,9 @@ public function terminate(StrandInterface $strand) * * This method is invoked after the coroutine is popped from the call stack. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function finalize(StrandInterface $strand) + public function finalize(Strand $strand) { } } diff --git a/src/Coroutine/GeneratorCoroutine.php b/src/Coroutine/GeneratorCoroutine.php index cc5d653..b7860d3 100644 --- a/src/Coroutine/GeneratorCoroutine.php +++ b/src/Coroutine/GeneratorCoroutine.php @@ -4,7 +4,7 @@ use Exception; use Generator; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * A coroutine wrapper for PHP generators. @@ -29,9 +29,9 @@ public function __construct(Generator $generator) /** * Invoked when tick() is called for the first time. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function call(StrandInterface $strand) + public function call(Strand $strand) { try { $valid = $this->generator->valid(); @@ -55,10 +55,10 @@ public function call(StrandInterface $strand) /** * Invoked when tick() is called after sendOnNextTick(). * - * @param StrandInterface $strand The strand that is executing the coroutine. - * @param mixed $value The value passed to sendOnNextTick(). + * @param Strand $strand The strand that is executing the coroutine. + * @param mixed $value The value passed to sendOnNextTick(). */ - public function resumeWithValue(StrandInterface $strand, $value) + public function resumeWithValue(Strand $strand, $value) { try { $this->generator->send($value); @@ -83,10 +83,10 @@ public function resumeWithValue(StrandInterface $strand, $value) /** * Resume execution of a suspended coroutine by passing it an exception. * - * @param StrandInterface $strand The strand that is executing the coroutine. - * @param Exception $exception The exception to send to the coroutine. + * @param Strand $strand The strand that is executing the coroutine. + * @param Exception $exception The exception to send to the coroutine. */ - public function resumeWithException(StrandInterface $strand, Exception $exception) + public function resumeWithException(Strand $strand, Exception $exception) { try { $this->generator->throw($exception); @@ -113,9 +113,9 @@ public function resumeWithException(StrandInterface $strand, Exception $exceptio * * This method is invoked after the coroutine is popped from the call stack. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function finalize(StrandInterface $strand) + public function finalize(Strand $strand) { $this->generator = null; diff --git a/src/Coroutine/PromiseCoroutine.php b/src/Coroutine/PromiseCoroutine.php index a3a7b8f..5166b10 100644 --- a/src/Coroutine/PromiseCoroutine.php +++ b/src/Coroutine/PromiseCoroutine.php @@ -6,7 +6,7 @@ use React\Promise\CancellablePromiseInterface; use React\Promise\PromiseInterface; use Recoil\Coroutine\Exception\PromiseRejectedException; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * A coroutine that resumes when a promise is fulfilled or rejected. @@ -26,9 +26,9 @@ public function __construct(PromiseInterface $promise) /** * Start the coroutine. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function call(StrandInterface $strand) + public function call(Strand $strand) { $strand->suspend(); @@ -51,9 +51,9 @@ function ($reason) use ($strand) { /** * Inform the coroutine that the executing strand is being terminated. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function terminate(StrandInterface $strand) + public function terminate(Strand $strand) { if ($this->promise instanceof CancellablePromiseInterface) { $this->promise->cancel(); @@ -65,9 +65,9 @@ public function terminate(StrandInterface $strand) * * This method is invoked after the coroutine is popped from the call stack. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function finalize(StrandInterface $strand) + public function finalize(Strand $strand) { $this->promise = null; } diff --git a/src/Coroutine/StandardCoroutineAdaptor.php b/src/Coroutine/StandardCoroutineAdaptor.php index 81d9188..14633c6 100644 --- a/src/Coroutine/StandardCoroutineAdaptor.php +++ b/src/Coroutine/StandardCoroutineAdaptor.php @@ -6,7 +6,7 @@ use Icecave\Repr\Repr; use InvalidArgumentException; use React\Promise\PromiseInterface; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; use Recoil\Recoil; /** @@ -17,13 +17,13 @@ class StandardCoroutineAdaptor implements CoroutineAdaptor /** * Adapt a value into a coroutine. * - * @param StrandInterface $strand The currently executing strand. - * @param mixed $value The value to adapt. + * @param Strand $strand The currently executing strand. + * @param mixed $value The value to adapt. * * @return Coroutine * @throws InvalidArgumentException if now valid adaptation can be made. */ - public function adapt(StrandInterface $strand, $value) + public function adapt(Strand $strand, $value) { while ($value instanceof CoroutineProvider) { $value = $value->coroutine($strand); diff --git a/src/Kernel/Api/KernelApi.php b/src/Kernel/Api/KernelApi.php index 3922541..c8ffb61 100644 --- a/src/Kernel/Api/KernelApi.php +++ b/src/Kernel/Api/KernelApi.php @@ -3,7 +3,7 @@ namespace Recoil\Kernel\Api; use Exception; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * Public interface for manipulating the kernel and the current strand. @@ -13,39 +13,39 @@ interface KernelApi /** * Get the strand the coroutine is executing on. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function strand(StrandInterface $strand); + public function strand(Strand $strand); /** * Get the coroutine kernel that the current strand is executing on. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function kernel(StrandInterface $strand); + public function kernel(Strand $strand); /** * Get the React event-loop that the coroutine kernel is executing on. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function eventLoop(StrandInterface $strand); + public function eventLoop(Strand $strand); /** * Return a value to the calling coroutine. * - * @param StrandInterface $strand The currently executing strand. - * @param mixed $value The value to send to the calling coroutine. + * @param Strand $strand The currently executing strand. + * @param mixed $value The value to send to the calling coroutine. */ - public function return_(StrandInterface $strand, $value = null); + public function return_(Strand $strand, $value = null); /** * Throw an exception to the calling coroutine. * - * @param StrandInterface $strand The currently executing strand. - * @param Exception $exception The error to send to the calling coroutine. + * @param Strand $strand The currently executing strand. + * @param Exception $exception The error to send to the calling coroutine. */ - public function throw_(StrandInterface $strand, Exception $exception); + public function throw_(Strand $strand, Exception $exception); /** * Register a callback to be invoked when the current coroutine is popped @@ -54,33 +54,33 @@ public function throw_(StrandInterface $strand, Exception $exception); * The callback is guaranteed to be called even if a reference to the * coroutine is held elsewhere (unlike a PHP finally block in a generator). * - * @param StrandInterface $strand The currently executing strand. - * @param callable $callback The callback to invoke. + * @param Strand $strand The currently executing strand. + * @param callable $callback The callback to invoke. */ - public function finally_(StrandInterface $strand, callable $callback); + public function finally_(Strand $strand, callable $callback); /** * Terminate execution of the strand. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function terminate(StrandInterface $strand); + public function terminate(Strand $strand); /** * Suspend execution for a specified period of time. * - * @param StrandInterface $strand The currently executing strand. - * @param number $timeout The number of seconds to wait before resuming. + * @param Strand $strand The currently executing strand. + * @param number $timeout The number of seconds to wait before resuming. */ - public function sleep(StrandInterface $strand, $timeout); + public function sleep(Strand $strand, $timeout); /** * Suspend execution of the strand until it is resumed manually. * - * @param StrandInterface $strand The currently executing strand. - * @param callable $callback A callback which is passed the strand after it is suspended. + * @param Strand $strand The currently executing strand. + * @param callable $callback A callback which is passed the strand after it is suspended. */ - public function suspend(StrandInterface $strand, callable $callback); + public function suspend(Strand $strand, callable $callback); /** * Execute a coroutine with a time limit. @@ -88,11 +88,11 @@ public function suspend(StrandInterface $strand, callable $callback); * If the coroutine does not complete within the specified time it is * cancelled. * - * @param StrandInterface $strand The currently executing strand. - * @param number $timeout The number of seconds to wait before cancelling. - * @param mixed $coroutine The coroutine to execute. + * @param Strand $strand The currently executing strand. + * @param number $timeout The number of seconds to wait before cancelling. + * @param mixed $coroutine The coroutine to execute. */ - public function timeout(StrandInterface $strand, $timeout, $coroutine); + public function timeout(Strand $strand, $timeout, $coroutine); /** * Execute the given coroutines concurrently. @@ -101,40 +101,40 @@ public function timeout(StrandInterface $strand, $timeout, $coroutine); * are completed. If any of the coroutines fails, the remaining coroutines * are terminated. * - * @param StrandInterface $strand The currently executing strand. - * @param array $coroutines The coroutines to execute. + * @param Strand $strand The currently executing strand. + * @param array $coroutines The coroutines to execute. */ - public function all(StrandInterface $strand, array $coroutines); + public function all(Strand $strand, array $coroutines); /** * Resume the strand immediately. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function noop(StrandInterface $strand); + public function noop(Strand $strand); /** * Suspend the strand until the next tick. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function cooperate(StrandInterface $strand); + public function cooperate(Strand $strand); /** * Execute a coroutine on its own strand. * - * @param StrandInterface $strand The currently executing strand. - * @param mixed $coroutine The coroutine to execute. + * @param Strand $strand The currently executing strand. + * @param mixed $coroutine The coroutine to execute. */ - public function execute(StrandInterface $strand, $coroutine); + public function execute(Strand $strand, $coroutine); /** * Wait for one or more of the given strands to exit. * - * @param StrandInterface $strand The currently executing strand. - * @param StrandInterface[] $strands The strands to wait for. + * @param Strand $strand The currently executing strand. + * @param Strand[] $strands The strands to wait for. */ - public function select(StrandInterface $strand, array $strands); + public function select(Strand $strand, array $strands); /** * Stop the coroutine kernel / event-loop. @@ -142,8 +142,8 @@ public function select(StrandInterface $strand, array $strands); * The React event-loop can optionally be stopped when all strands have been * terminated. * - * @param StrandInterface $strand The currently executing strand. - * @param boolean $stopEventLoop Indicates whether or not the React event-loop should also be stopped. + * @param Strand $strand The currently executing strand. + * @param boolean $stopEventLoop Indicates whether or not the React event-loop should also be stopped. */ - public function stop(StrandInterface $strand, $stopEventLoop = true); + public function stop(Strand $strand, $stopEventLoop = true); } diff --git a/src/Kernel/Api/KernelApiCall.php b/src/Kernel/Api/KernelApiCall.php index 2c15a61..d02c9c1 100644 --- a/src/Kernel/Api/KernelApiCall.php +++ b/src/Kernel/Api/KernelApiCall.php @@ -5,7 +5,7 @@ use BadMethodCallException; use Recoil\Coroutine\Coroutine; use Recoil\Coroutine\CoroutineTrait; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * Represents a call to a feature provided by the Kernel API. @@ -50,9 +50,9 @@ public function arguments() /** * Start the coroutine. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function call(StrandInterface $strand) + public function call(Strand $strand) { $method = [$strand->kernel()->api(), $this->name]; diff --git a/src/Kernel/Api/Select.php b/src/Kernel/Api/Select.php index f0318a1..90ba07e 100644 --- a/src/Kernel/Api/Select.php +++ b/src/Kernel/Api/Select.php @@ -4,7 +4,7 @@ use Recoil\Coroutine\Coroutine; use Recoil\Coroutine\CoroutineTrait; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; use SplObjectStorage; /** @@ -33,9 +33,9 @@ public function __construct(array $strands) /** * Start the coroutine. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function call(StrandInterface $strand) + public function call(Strand $strand) { // If some of the strands have exited already, resume immediately ... if ($this->exited) { @@ -61,9 +61,9 @@ public function call(StrandInterface $strand) * * This method is invoked after the coroutine is popped from the call stack. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function finalize(StrandInterface $strand) + public function finalize(Strand $strand) { foreach ($this->substrands as $strand) { $strand->removeListener( @@ -73,7 +73,7 @@ public function finalize(StrandInterface $strand) } } - public function onStrandExit(StrandInterface $strand) + public function onStrandExit(Strand $strand) { $index = $this->substrands[$strand]; diff --git a/src/Kernel/Api/Sleep.php b/src/Kernel/Api/Sleep.php index 76a6b5f..7aad333 100644 --- a/src/Kernel/Api/Sleep.php +++ b/src/Kernel/Api/Sleep.php @@ -4,7 +4,7 @@ use Recoil\Coroutine\Coroutine; use Recoil\Coroutine\CoroutineTrait; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * Internal implementation of KernelApi::sleep(). @@ -23,9 +23,9 @@ public function __construct($timeout) /** * Invoked when tick() is called for the first time. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function call(StrandInterface $strand) + public function call(Strand $strand) { $strand->suspend(); @@ -45,9 +45,9 @@ function () use ($strand) { * * This method is invoked after the coroutine is popped from the call stack. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function finalize(StrandInterface $strand) + public function finalize(Strand $strand) { if ($this->timer) { $this->timer->cancel(); diff --git a/src/Kernel/Api/StandardKernelApi.php b/src/Kernel/Api/StandardKernelApi.php index d0c388b..7573112 100644 --- a/src/Kernel/Api/StandardKernelApi.php +++ b/src/Kernel/Api/StandardKernelApi.php @@ -3,7 +3,7 @@ namespace Recoil\Kernel\Api; use Exception; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * The default kernel API implementation. @@ -13,9 +13,9 @@ class StandardKernelApi implements KernelApi /** * Get the strand the coroutine is executing on. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function strand(StrandInterface $strand) + public function strand(Strand $strand) { $strand->resumeWithValue($strand); } @@ -23,9 +23,9 @@ public function strand(StrandInterface $strand) /** * Get the coroutine kernel that the current strand is executing on. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function kernel(StrandInterface $strand) + public function kernel(Strand $strand) { $strand->resumeWithValue($strand->kernel()); } @@ -33,9 +33,9 @@ public function kernel(StrandInterface $strand) /** * Get the React event-loop that the coroutine kernel is executing on. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function eventLoop(StrandInterface $strand) + public function eventLoop(Strand $strand) { $strand->resumeWithValue($strand->kernel()->eventLoop()); } @@ -43,10 +43,10 @@ public function eventLoop(StrandInterface $strand) /** * Return a value to the calling coroutine. * - * @param StrandInterface $strand The currently executing strand. - * @param mixed $value The value to send to the calling coroutine. + * @param Strand $strand The currently executing strand. + * @param mixed $value The value to send to the calling coroutine. */ - public function return_(StrandInterface $strand, $value = null) + public function return_(Strand $strand, $value = null) { $strand->returnValue($value); } @@ -54,10 +54,10 @@ public function return_(StrandInterface $strand, $value = null) /** * Throw an exception to the calling coroutine. * - * @param StrandInterface $strand The currently executing strand. - * @param Exception $exception The error to send to the calling coroutine. + * @param Strand $strand The currently executing strand. + * @param Exception $exception The error to send to the calling coroutine. */ - public function throw_(StrandInterface $strand, Exception $exception) + public function throw_(Strand $strand, Exception $exception) { $strand->throwException($exception); } @@ -69,10 +69,10 @@ public function throw_(StrandInterface $strand, Exception $exception) * The callback is guaranteed to be called even if a reference to the * coroutine is held elsewhere (unlike a PHP finally block in a generator). * - * @param StrandInterface $strand The currently executing strand. - * @param callable $callback The callback to invoke. + * @param Strand $strand The currently executing strand. + * @param callable $callback The callback to invoke. */ - public function finally_(StrandInterface $strand, callable $callback) + public function finally_(Strand $strand, callable $callback) { $strand->current()->registerFinalizeCallback($callback); @@ -82,9 +82,9 @@ public function finally_(StrandInterface $strand, callable $callback) /** * Terminate execution of the strand. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function terminate(StrandInterface $strand) + public function terminate(Strand $strand) { $strand->terminate(); } @@ -92,10 +92,10 @@ public function terminate(StrandInterface $strand) /** * Suspend execution for a specified period of time. * - * @param StrandInterface $strand The currently executing strand. - * @param number $timeout The number of seconds to wait before resuming. + * @param Strand $strand The currently executing strand. + * @param number $timeout The number of seconds to wait before resuming. */ - public function sleep(StrandInterface $strand, $timeout) + public function sleep(Strand $strand, $timeout) { return new Sleep($timeout); } @@ -103,9 +103,9 @@ public function sleep(StrandInterface $strand, $timeout) /** * Suspend execution of the strand. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function suspend(StrandInterface $strand, callable $callback) + public function suspend(Strand $strand, callable $callback) { $strand->suspend(); @@ -118,11 +118,11 @@ public function suspend(StrandInterface $strand, callable $callback) * If the coroutine does not complete within the specified time it is * cancelled. * - * @param StrandInterface $strand The currently executing strand. - * @param number $timeout The number of seconds to wait before cancelling. - * @param mixed $coroutine The coroutine to execute. + * @param Strand $strand The currently executing strand. + * @param number $timeout The number of seconds to wait before cancelling. + * @param mixed $coroutine The coroutine to execute. */ - public function timeout(StrandInterface $strand, $timeout, $coroutine) + public function timeout(Strand $strand, $timeout, $coroutine) { return new Timeout($timeout, $coroutine); } @@ -134,10 +134,10 @@ public function timeout(StrandInterface $strand, $timeout, $coroutine) * are completed. If any of the coroutines fails, the remaining coroutines * are terminated. * - * @param StrandInterface $strand The currently executing strand. - * @param array $coroutines The coroutines to execute. + * @param Strand $strand The currently executing strand. + * @param array $coroutines The coroutines to execute. */ - public function all(StrandInterface $strand, array $coroutines) + public function all(Strand $strand, array $coroutines) { return new WaitAll($coroutines); } @@ -145,9 +145,9 @@ public function all(StrandInterface $strand, array $coroutines) /** * Suspend the strand until the next tick. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function cooperate(StrandInterface $strand) + public function cooperate(Strand $strand) { $strand->suspend(); @@ -164,9 +164,9 @@ function () use ($strand) { /** * Resume the strand immediately. * - * @param StrandInterface $strand The currently executing strand. + * @param Strand $strand The currently executing strand. */ - public function noop(StrandInterface $strand) + public function noop(Strand $strand) { $strand->resumeWithValue(null); } @@ -174,10 +174,10 @@ public function noop(StrandInterface $strand) /** * Execute a coroutine on its own strand. * - * @param StrandInterface $strand The currently executing strand. - * @param mixed $coroutine The coroutine to execute. + * @param Strand $strand The currently executing strand. + * @param mixed $coroutine The coroutine to execute. */ - public function execute(StrandInterface $strand, $coroutine) + public function execute(Strand $strand, $coroutine) { $substrand = $strand ->kernel() @@ -189,10 +189,10 @@ public function execute(StrandInterface $strand, $coroutine) /** * Wait for one or more of the given strands to exit. * - * @param StrandInterface $strand The currently executing strand. - * @param StrandInterface[] $strands The strands to wait for. + * @param Strand $strand The currently executing strand. + * @param Strand[] $strands The strands to wait for. */ - public function select(StrandInterface $strand, array $strands) + public function select(Strand $strand, array $strands) { return new Select($strands); } @@ -203,10 +203,10 @@ public function select(StrandInterface $strand, array $strands) * The React event-loop can optionally be stopped when all strands have been * terminated. * - * @param StrandInterface $strand The currently executing strand. - * @param boolean $stopEventLoop Indicates whether or not the React event-loop should also be stopped. + * @param Strand $strand The currently executing strand. + * @param boolean $stopEventLoop Indicates whether or not the React event-loop should also be stopped. */ - public function stop(StrandInterface $strand, $stopEventLoop = true) + public function stop(Strand $strand, $stopEventLoop = true) { $strand->terminate(); diff --git a/src/Kernel/Api/Timeout.php b/src/Kernel/Api/Timeout.php index 87d9729..994fa2d 100644 --- a/src/Kernel/Api/Timeout.php +++ b/src/Kernel/Api/Timeout.php @@ -6,7 +6,7 @@ use Recoil\Coroutine\Coroutine; use Recoil\Coroutine\CoroutineTrait; use Recoil\Kernel\Exception\TimeoutException; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * Internal implementation of KernelApi::timeout(). @@ -26,9 +26,9 @@ public function __construct($timeout, $coroutine) /** * Invoked when tick() is called for the first time. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function call(StrandInterface $strand) + public function call(Strand $strand) { $this->timer = $strand ->kernel() @@ -47,9 +47,9 @@ function () use ($strand) { /** * Inform the coroutine that the executing strand is being terminated. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function terminate(StrandInterface $strand) + public function terminate(Strand $strand) { if (!$this->timer) { // Stop termination of the strand and instead propagate a timeout exception. @@ -61,9 +61,9 @@ public function terminate(StrandInterface $strand) * * This method is invoked after the coroutine is popped from the call stack. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function finalize(StrandInterface $strand) + public function finalize(Strand $strand) { if ($this->timer) { $this->timer->cancel(); diff --git a/src/Kernel/Api/WaitAll.php b/src/Kernel/Api/WaitAll.php index e7b9d29..ec02b52 100644 --- a/src/Kernel/Api/WaitAll.php +++ b/src/Kernel/Api/WaitAll.php @@ -6,7 +6,7 @@ use Recoil\Coroutine\Coroutine; use Recoil\Coroutine\CoroutineTrait; use Recoil\Kernel\Exception\StrandTerminatedException; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * Internal implementation of KernelApi::all(). @@ -27,9 +27,9 @@ public function __construct(array $coroutines) /** * Start the coroutine. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function call(StrandInterface $strand) + public function call(Strand $strand) { $this->strand = $strand; $this->strand->suspend(); @@ -87,9 +87,9 @@ function () use ($index) { * * This method is invoked after the coroutine is popped from the call stack. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function finalize(StrandInterface $strand) + public function finalize(Strand $strand) { $this->strand = null; diff --git a/src/Kernel/Kernel.php b/src/Kernel/Kernel.php index 0c02cb0..475e337 100644 --- a/src/Kernel/Kernel.php +++ b/src/Kernel/Kernel.php @@ -4,8 +4,8 @@ use React\EventLoop\LoopInterface; use Recoil\Coroutine\CoroutineAdaptor; +use Recoil\Kernel\Strand\Strand; use Recoil\Kernel\Strand\StrandFactory; -use Recoil\Kernel\Strand\StrandInterface; /** * A coroutine kernel. @@ -20,23 +20,23 @@ interface Kernel * * @param mixed $coroutine The coroutine to execute. * - * @return StrandInterface The strand on which the coroutine will execute. + * @return Strand The strand on which the coroutine will execute. */ public function execute($coroutine); /** * Attach an existing strand to this kernel. * - * @param StrandInterface The strand to attach. + * @param Strand The strand to attach. */ - public function attachStrand(StrandInterface $strand); + public function attachStrand(Strand $strand); /** * Detach an existing strand from this kernel. * - * @param StrandInterface The strand to detach. + * @param Strand The strand to detach. */ - public function detachStrand(StrandInterface $strand); + public function detachStrand(Strand $strand); /** * Fetch the object that implements the kernel API. diff --git a/src/Kernel/StandardKernel.php b/src/Kernel/StandardKernel.php index d77b982..bc55eaf 100644 --- a/src/Kernel/StandardKernel.php +++ b/src/Kernel/StandardKernel.php @@ -9,8 +9,8 @@ use Recoil\Kernel\Api\KernelApi; use Recoil\Kernel\Api\StandardKernelApi; use Recoil\Kernel\Strand\StandardStrandFactory; +use Recoil\Kernel\Strand\Strand; use Recoil\Kernel\Strand\StrandFactory; -use Recoil\Kernel\Strand\StrandInterface; /** * The default kernel implementation. @@ -18,10 +18,10 @@ class StandardKernel implements Kernel { /** - * @param LoopInterface|null $eventLoop The React event-loop. - * @param KernelApi|null $api The kernel's API implementation. - * @param CoroutineAdaptor|null $coroutineAdaptor The kernel's coroutine adaptor. - * @param StrandFactory|null $strandFactory The kernel's strand factory. + * @param LoopInterface|null $eventLoop The React event-loop. + * @param KernelApi|null $api The kernel's API implementation. + * @param CoroutineAdaptor|null $coroutineAdaptor The kernel's coroutine adaptor. + * @param StrandFactory|null $strandFactory The kernel's strand factory. */ public function __construct( LoopInterface $eventLoop = null, @@ -61,7 +61,7 @@ public function __construct( * * @param mixed $coroutine The coroutine to execute. * - * @return StrandInterface The strand on which the coroutine will execute. + * @return Strand The strand on which the coroutine will execute. */ public function execute($coroutine) { @@ -74,9 +74,9 @@ public function execute($coroutine) /** * Attach an existing strand to this kernel. * - * @param StrandInterface The strand to attach. + * @param Strand The strand to attach. */ - public function attachStrand(StrandInterface $strand) + public function attachStrand(Strand $strand) { if (!$this->strands) { $this->eventLoop->futureTick([$this, 'onTick']); @@ -88,9 +88,9 @@ public function attachStrand(StrandInterface $strand) /** * Detach an existing strand from this kernel. * - * @param StrandInterface The strand to detach. + * @param Strand The strand to detach. */ - public function detachStrand(StrandInterface $strand) + public function detachStrand(Strand $strand) { $index = array_search($strand, $this->strands, true); diff --git a/src/Kernel/Strand/StackBase.php b/src/Kernel/Strand/StackBase.php index d95e5cb..d0f336f 100644 --- a/src/Kernel/Strand/StackBase.php +++ b/src/Kernel/Strand/StackBase.php @@ -21,9 +21,9 @@ class StackBase implements Coroutine * * @codeCoverageIgnore * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function call(StrandInterface $strand) + public function call(Strand $strand) { throw new LogicException('Not supported.'); } @@ -31,10 +31,10 @@ public function call(StrandInterface $strand) /** * Resume execution of a suspended coroutine by passing it a value. * - * @param StrandInterface $strand The strand that is executing the coroutine. - * @param mixed $value The value to send to the coroutine. + * @param Strand $strand The strand that is executing the coroutine. + * @param mixed $value The value to send to the coroutine. */ - public function resumeWithValue(StrandInterface $strand, $value) + public function resumeWithValue(Strand $strand, $value) { $strand->emit('success', [$strand, $value]); $strand->emit('exit', [$strand]); @@ -47,10 +47,10 @@ public function resumeWithValue(StrandInterface $strand, $value) /** * Resume execution of a suspended coroutine by passing it an exception. * - * @param StrandInterface $strand The strand that is executing the coroutine. - * @param Exception $exception The exception to send to the coroutine. + * @param Strand $strand The strand that is executing the coroutine. + * @param Exception $exception The exception to send to the coroutine. */ - public function resumeWithException(StrandInterface $strand, Exception $exception) + public function resumeWithException(Strand $strand, Exception $exception) { $throwException = true; @@ -73,9 +73,9 @@ public function resumeWithException(StrandInterface $strand, Exception $exceptio /** * Inform the coroutine that the executing strand is being terminated. * - * @param StrandInterface $strand The strand that is executing the coroutine. + * @param Strand $strand The strand that is executing the coroutine. */ - public function terminate(StrandInterface $strand) + public function terminate(Strand $strand) { $strand->emit('terminate', [$strand]); $strand->emit('exit', [$strand]); diff --git a/src/Kernel/Strand/StandardStrand.php b/src/Kernel/Strand/StandardStrand.php index 223f559..b50cf8d 100644 --- a/src/Kernel/Strand/StandardStrand.php +++ b/src/Kernel/Strand/StandardStrand.php @@ -18,7 +18,7 @@ * @event suspend Execution of the strand has been suspended. * @event resumed Execution of the strand has been resumed. */ -class StandardStrand extends EventEmitter implements StrandInterface +class StandardStrand extends EventEmitter implements Strand { /** * @param Kernel The coroutine kernel. diff --git a/src/Kernel/Strand/StandardStrandFactory.php b/src/Kernel/Strand/StandardStrandFactory.php index fa0bf79..e8921bf 100644 --- a/src/Kernel/Strand/StandardStrandFactory.php +++ b/src/Kernel/Strand/StandardStrandFactory.php @@ -14,7 +14,7 @@ class StandardStrandFactory implements StrandFactory * * @param Kernel The kernel on which the strand will execute. * - * @return StrandInterface + * @return Strand */ public function createStrand(Kernel $kernel) { diff --git a/src/Kernel/Strand/StrandInterface.php b/src/Kernel/Strand/Strand.php similarity index 98% rename from src/Kernel/Strand/StrandInterface.php rename to src/Kernel/Strand/Strand.php index 35ea4f3..680ffdd 100644 --- a/src/Kernel/Strand/StrandInterface.php +++ b/src/Kernel/Strand/Strand.php @@ -17,7 +17,7 @@ * @event suspend Execution of the strand has been suspended. * @event resumed Execution of the strand has been resumed. */ -interface StrandInterface extends EventEmitterInterface +interface Strand extends EventEmitterInterface { /** * Fetch the kernel on which this strand is executing. diff --git a/src/Kernel/Strand/StrandFactory.php b/src/Kernel/Strand/StrandFactory.php index 879ce0a..08e6624 100644 --- a/src/Kernel/Strand/StrandFactory.php +++ b/src/Kernel/Strand/StrandFactory.php @@ -14,7 +14,7 @@ interface StrandFactory * * @param Kernel $kernel The kernel on which the strand will execute. * - * @return StrandInterface + * @return Strand */ public function createStrand(Kernel $kernel); } diff --git a/src/Recoil.php b/src/Recoil.php index 4f003a7..ee0fd43 100644 --- a/src/Recoil.php +++ b/src/Recoil.php @@ -5,7 +5,7 @@ use React\EventLoop\LoopInterface; use Recoil\Kernel\Api\KernelApiCall; use Recoil\Kernel\StandardKernel; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; /** * Public facade for Kernel API calls. @@ -31,7 +31,7 @@ * @method static noop() [COROUTINE] Resume the strand immediately. * @method static cooperate() [COROUTINE] Suspend the strand until the next tick. * @method static execute($coroutine) [COROUTINE] Execute a coroutine on its own strand. - * @method static select(StrandInterface $strand, array $strands) [COROUTINE] Wait for one or more of the given strands to exit. + * @method static select(Strand $strand, array $strands) [COROUTINE] Wait for one or more of the given strands to exit. * @method static stop(bool $stopEventLoop = true) [COROUTINE] Stop the coroutine kernel / event-loop. */ abstract class Recoil diff --git a/test/suite/Coroutine/StandardCoroutineAdaptorTest.php b/test/suite/Coroutine/StandardCoroutineAdaptorTest.php index f732d91..b5268de 100644 --- a/test/suite/Coroutine/StandardCoroutineAdaptorTest.php +++ b/test/suite/Coroutine/StandardCoroutineAdaptorTest.php @@ -6,13 +6,13 @@ use PHPUnit_Framework_TestCase; use React\Promise\PromiseInterface; use Recoil\Kernel\Api\KernelApiCall; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; class StandardCoroutineAdaptorTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->strand = Phake::mock(StrandInterface::class); + $this->strand = Phake::mock(Strand::class); $this->adaptor = new StandardCoroutineAdaptor(); } diff --git a/test/suite/Kernel/Api/StandardKernelApiTest.php b/test/suite/Kernel/Api/StandardKernelApiTest.php index aa3c6b3..3dd98d5 100644 --- a/test/suite/Kernel/Api/StandardKernelApiTest.php +++ b/test/suite/Kernel/Api/StandardKernelApiTest.php @@ -6,7 +6,7 @@ use PHPUnit_Framework_TestCase; use Recoil\Kernel\Exception\TimeoutException; use Recoil\Kernel\StandardKernel; -use Recoil\Kernel\Strand\StrandInterface; +use Recoil\Kernel\Strand\Strand; use Recoil\Recoil; /** @@ -349,7 +349,7 @@ public function testExecute() $this->kernel->eventLoop()->run(); - $this->assertInstanceOf(StrandInterface::class, $strand); + $this->assertInstanceOf(Strand::class, $strand); } public function testStop() From 6afd9ba4c17bcb09216b82c6cc7968ae22dc5c4a Mon Sep 17 00:00:00 2001 From: James Harris Date: Fri, 20 Nov 2015 12:45:59 +1000 Subject: [PATCH 18/24] Implemented Recoil::callback() (fixes #36). --- README.md | 24 +++++++++++ src/Kernel/Api/KernelApi.php | 10 +++++ src/Kernel/Api/StandardKernelApi.php | 30 +++++++++++++ .../Kernel/Api/StandardKernelApiTest.php | 42 +++++++++++++++++++ 4 files changed, 106 insertions(+) diff --git a/README.md b/README.md index e2abe15..6d69c8d 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,30 @@ The [promise-dns example](examples/promise-dns) demonstrates using the [React DN a promised-based API, to resolve several domain names concurrently. [This example](examples/promise-dns-react) shows the same functionality implemented without **Recoil**. +### Callback and Events + +Conventional asynchronous code uses callback functions to inform a caller when a result is available or an event occurs. +The kernel API provides `Recoil::callback()` to create a callback that executes a coroutine on its own strand. + +```php +use Evenement\EventEmitter; + +Recoil::run( + function () { + $eventEmitter = new EventEmitter(); + $eventEmitter->on( + 'hello' + (yield Recoil::callback( + function ($name) { + echo 'Hello, ' . $name . '!' . PHP_EOL; + yield Recoil::noop(); + } + )) + ); + } +); +``` + ### Using an existing event-loop In all of the examples above, the `Recoil::run()` convenience function is used to start the kernel. Internally this diff --git a/src/Kernel/Api/KernelApi.php b/src/Kernel/Api/KernelApi.php index c8ffb61..f54fa00 100644 --- a/src/Kernel/Api/KernelApi.php +++ b/src/Kernel/Api/KernelApi.php @@ -128,6 +128,16 @@ public function cooperate(Strand $strand); */ public function execute(Strand $strand, $coroutine); + /** + * Create a function that executes a coroutine in its own strand. + * + * If $coroutine is callable, it is expected to return a coroutine. + * + * @param Strand $strand The currently executing strand. + * @param mixed $coroutine The coroutine to execute. + */ + public function callback(Strand $stand, $coroutine); + /** * Wait for one or more of the given strands to exit. * diff --git a/src/Kernel/Api/StandardKernelApi.php b/src/Kernel/Api/StandardKernelApi.php index 7573112..619321b 100644 --- a/src/Kernel/Api/StandardKernelApi.php +++ b/src/Kernel/Api/StandardKernelApi.php @@ -186,6 +186,36 @@ public function execute(Strand $strand, $coroutine) $strand->resumeWithValue($substrand); } + /** + * Create a function that executes a coroutine in its own strand. + * + * If $coroutine is callable, it is expected to return a coroutine. + * + * @param Strand $strand The currently executing strand. + * @param mixed $coroutine The coroutine to execute. + */ + public function callback(Strand $strand, $coroutine) + { + $kernel = $strand->kernel(); + + if (is_callable($coroutine)) { + $callback = function () use ($kernel, $coroutine) { + $kernel->execute( + call_user_func_array( + $coroutine, + func_get_args() + ) + ); + }; + } else { + $callback = function () use ($kernel, $coroutine) { + $kernel->execute($coroutine); + }; + } + + $strand->resumeWithValue($callback); + } + /** * Wait for one or more of the given strands to exit. * diff --git a/test/suite/Kernel/Api/StandardKernelApiTest.php b/test/suite/Kernel/Api/StandardKernelApiTest.php index 3dd98d5..39f5652 100644 --- a/test/suite/Kernel/Api/StandardKernelApiTest.php +++ b/test/suite/Kernel/Api/StandardKernelApiTest.php @@ -352,6 +352,48 @@ public function testExecute() $this->assertInstanceOf(Strand::class, $strand); } + public function testCallback() + { + $this->expectOutputString('123'); + + $coroutine = function () { + $f = function () { + echo 3; + yield Recoil::noop(); + }; + + echo 1; + $callback = (yield Recoil::callback($f())); + $callback(); + echo 2; + }; + + $this->kernel->execute($coroutine()); + + $this->kernel->eventLoop()->run(); + } + + public function testCallbackWithCallable() + { + $this->expectOutputString('123'); + + $coroutine = function () { + $f = function ($value) { + echo $value; + yield Recoil::noop(); + }; + + echo 1; + $callback = (yield Recoil::callback($f)); + $callback(3); + echo 2; + }; + + $this->kernel->execute($coroutine()); + + $this->kernel->eventLoop()->run(); + } + public function testStop() { $this->expectOutputString('1'); From 28d79be72d72c72164d93665f23e5091ed771c23 Mon Sep 17 00:00:00 2001 From: James Harris Date: Fri, 20 Nov 2015 12:51:57 +1000 Subject: [PATCH 19/24] Changelog [ci skip] --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2018fc1..8cd5866 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Recoil Changelog +### Next Version (predicted 0.4.0) + +* **[BC]** Dropped `Interface` suffix from interfaces +* **[BC]** Renamed `ReadableStream` to `ReadablePhpStream` +* **[BC]** Renamed `WritableStream` to `WritablePhpStream` +* **[BC]** Renamed `CoroutineAdaptor` to `StandardCoroutineAdaptor` +* **[BC]** Renamed `KernelApi` to `StandardKernelApi` +* **[BC]** Renamed `Strand` to `StandardStrand` +* **[BC]** Renamed `StrandFactory` to `StandardStrandFactory` + ### 0.3.0 (2015-06-26) * **[BC]** Removed `StrandInterface::resume()` From 267b4d7084919a71ec0617b16d3da933e585141a Mon Sep 17 00:00:00 2001 From: James Harris Date: Fri, 20 Nov 2015 12:55:12 +1000 Subject: [PATCH 20/24] Updated GH token. --- .travis.env | 2 +- .travis.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.env b/.travis.env index c55602f..9d6d70a 100644 --- a/.travis.env +++ b/.travis.env @@ -1 +1 @@ -eNkdkCDTTQDrKETgHn9u2Kbx1vvZFDkMxFgmwl6keoe9X4XtEsw/LSgHlE4dEscGVwEidzMJuH2ZapgB9KbqSJImKmtvJYjF1700zrWdXSqy5NeLiexwBwoQbkrnO27AwqpRnEFwJrBlEggsBcUYj8s9hRYlDKb3juEEKgdafxc= \ No newline at end of file +g0uexghpfxjO1pVYCBqj/P957zCZQT1v5naWgzDtu5n2Sh1WoW00K4+jOYJ4bbIm+1O8wbzzlyOuYZMMz0xXLVzuOdoMwMhfcnI+pE/dpa4J/vs1RFqoLh4HuNx9oPErNODdmWIkeC1SpcuBeYZfYxEL6UJIWbZZq3a9BIslx88= \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index d984493..abe6853 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ matrix: env: global: - ARCHER_PUBLISH_VERSION=5.6 - - secure: "eNkdkCDTTQDrKETgHn9u2Kbx1vvZFDkMxFgmwl6keoe9X4XtEsw/LSgHlE4dEscGVwEidzMJuH2ZapgB9KbqSJImKmtvJYjF1700zrWdXSqy5NeLiexwBwoQbkrnO27AwqpRnEFwJrBlEggsBcUYj8s9hRYlDKb3juEEKgdafxc=" + - secure: "g0uexghpfxjO1pVYCBqj/P957zCZQT1v5naWgzDtu5n2Sh1WoW00K4+jOYJ4bbIm+1O8wbzzlyOuYZMMz0xXLVzuOdoMwMhfcnI+pE/dpa4J/vs1RFqoLh4HuNx9oPErNODdmWIkeC1SpcuBeYZfYxEL6UJIWbZZq3a9BIslx88=" install: - ./.travis.install From 257dc4bdfe1fe59314eaa511e263eaf2b0d707a3 Mon Sep 17 00:00:00 2001 From: James Harris Date: Mon, 30 Nov 2015 08:04:25 +1000 Subject: [PATCH 21/24] Made callback argument to Recoil::suspend() optional. --- src/Kernel/Api/KernelApi.php | 6 +++--- src/Kernel/Api/StandardKernelApi.php | 6 ++++-- test/suite/Kernel/Api/StandardKernelApiTest.php | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Kernel/Api/KernelApi.php b/src/Kernel/Api/KernelApi.php index f54fa00..5cb38a3 100644 --- a/src/Kernel/Api/KernelApi.php +++ b/src/Kernel/Api/KernelApi.php @@ -77,10 +77,10 @@ public function sleep(Strand $strand, $timeout); /** * Suspend execution of the strand until it is resumed manually. * - * @param Strand $strand The currently executing strand. - * @param callable $callback A callback which is passed the strand after it is suspended. + * @param Strand $strand The currently executing strand. + * @param callable|null $callback A callback which is passed the strand after it is suspended. */ - public function suspend(Strand $strand, callable $callback); + public function suspend(Strand $strand, callable $callback = null); /** * Execute a coroutine with a time limit. diff --git a/src/Kernel/Api/StandardKernelApi.php b/src/Kernel/Api/StandardKernelApi.php index 619321b..912abc3 100644 --- a/src/Kernel/Api/StandardKernelApi.php +++ b/src/Kernel/Api/StandardKernelApi.php @@ -105,11 +105,13 @@ public function sleep(Strand $strand, $timeout) * * @param Strand $strand The currently executing strand. */ - public function suspend(Strand $strand, callable $callback) + public function suspend(Strand $strand, callable $callback = null) { $strand->suspend(); - $callback($strand); + if ($callback) { + $callback($strand); + } } /** diff --git a/test/suite/Kernel/Api/StandardKernelApiTest.php b/test/suite/Kernel/Api/StandardKernelApiTest.php index 39f5652..dcd4ec6 100644 --- a/test/suite/Kernel/Api/StandardKernelApiTest.php +++ b/test/suite/Kernel/Api/StandardKernelApiTest.php @@ -212,6 +212,20 @@ public function testSuspend() { $this->expectOutputString(''); + $coroutine = function () { + yield Recoil::suspend(); + echo 'X'; + }; + + $expectedStrand = $this->kernel->execute($coroutine()); + + $this->kernel->eventLoop()->run(); + } + + public function testSuspendWithCallback() + { + $this->expectOutputString(''); + $strand = null; $coroutine = function () use (&$strand) { From 1cf70f4fc4d3d435e61fab711a7a01d2b2d93ffc Mon Sep 17 00:00:00 2001 From: Erin Millard Date: Fri, 4 Dec 2015 10:18:42 +1000 Subject: [PATCH 22/24] Support for Guzzle promises. --- src/Coroutine/PromiseCoroutine.php | 11 +++++++---- src/Coroutine/StandardCoroutineAdaptor.php | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Coroutine/PromiseCoroutine.php b/src/Coroutine/PromiseCoroutine.php index 5166b10..3afcc50 100644 --- a/src/Coroutine/PromiseCoroutine.php +++ b/src/Coroutine/PromiseCoroutine.php @@ -3,8 +3,8 @@ namespace Recoil\Coroutine; use Exception; +use GuzzleHttp\Promise\PromiseInterface as GuzzlePromise; use React\Promise\CancellablePromiseInterface; -use React\Promise\PromiseInterface; use Recoil\Coroutine\Exception\PromiseRejectedException; use Recoil\Kernel\Strand\Strand; @@ -16,9 +16,9 @@ class PromiseCoroutine implements Coroutine use CoroutineTrait; /** - * @param PromiseInterface $promise The wrapped promise object. + * @param object $promise The wrapped promise object. */ - public function __construct(PromiseInterface $promise) + public function __construct($promise) { $this->promise = $promise; } @@ -55,7 +55,10 @@ function ($reason) use ($strand) { */ public function terminate(Strand $strand) { - if ($this->promise instanceof CancellablePromiseInterface) { + if ( + $this->promise instanceof CancellablePromiseInterface || + $this->promise instanceof GuzzlePromise + ) { $this->promise->cancel(); } } diff --git a/src/Coroutine/StandardCoroutineAdaptor.php b/src/Coroutine/StandardCoroutineAdaptor.php index 14633c6..76eaf29 100644 --- a/src/Coroutine/StandardCoroutineAdaptor.php +++ b/src/Coroutine/StandardCoroutineAdaptor.php @@ -3,9 +3,10 @@ namespace Recoil\Coroutine; use Generator; +use GuzzleHttp\Promise\PromiseInterface as GuzzlePromise; use Icecave\Repr\Repr; use InvalidArgumentException; -use React\Promise\PromiseInterface; +use React\Promise\PromiseInterface as ReactPromise; use Recoil\Kernel\Strand\Strand; use Recoil\Recoil; @@ -33,7 +34,10 @@ public function adapt(Strand $strand, $value) return $value; } elseif ($value instanceof Generator) { return new GeneratorCoroutine($value); - } elseif ($value instanceof PromiseInterface) { + } elseif ( + $value instanceof ReactPromise || + $value instanceof GuzzlePromise + ) { return new PromiseCoroutine($value); } elseif (is_array($value)) { return Recoil::all($value); From 98380e5089f34e9616c6ac731bef48c735429c3b Mon Sep 17 00:00:00 2001 From: James Harris Date: Fri, 4 Dec 2015 10:35:33 +1000 Subject: [PATCH 23/24] Added tests for Guzzle promises. --- composer.json | 1 + composer.lock | 347 ++++++++++++------ src/Coroutine/PromiseCoroutine.php | 13 +- src/Coroutine/StandardCoroutineAdaptor.php | 16 +- test/suite/Coroutine/PromiseCoroutineTest.php | 13 +- .../StandardCoroutineAdaptorTest.php | 29 +- 6 files changed, 281 insertions(+), 138 deletions(-) diff --git a/composer.json b/composer.json index 51c89ea..30b55dc 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ }, "require-dev": { "icecave/archer": "^1", + "guzzlehttp/promises": "^1", "phake/phake": "2.0.0-alpha4 as v1.0.3", "react/dns": "^0.4", "react/promise": "^2", diff --git a/composer.lock b/composer.lock index 6a0828f..c569455 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "e62d6e776262d6f066f312892afa3857", + "hash": "a5f1d709bed00602f6ca357f84dee616", + "content-hash": "9dc9274e2f97339ecf3dbbfde09a0710", "packages": [ { "name": "evenement/evenement", @@ -243,6 +244,57 @@ ], "time": "2015-03-18 18:23:50" }, + { + "name": "guzzlehttp/promises", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/b1e1c0d55f8083c71eda2c28c12a228d708294ea", + "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2015-10-15 22:28:00" + }, { "name": "icecave/archer", "version": "1.3.2", @@ -774,29 +826,29 @@ }, { "name": "react/stream", - "version": "v0.4.2", + "version": "v0.4.3", "source": { "type": "git", "url": "https://github.com/reactphp/stream.git", - "reference": "acc7a5fec02e0aea674560e1d13c40ed0c8c5465" + "reference": "305b2328d2a2e157bc13b61a0f5c6e41b666b188" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/stream/zipball/acc7a5fec02e0aea674560e1d13c40ed0c8c5465", - "reference": "acc7a5fec02e0aea674560e1d13c40ed0c8c5465", + "url": "https://api.github.com/repos/reactphp/stream/zipball/305b2328d2a2e157bc13b61a0f5c6e41b666b188", + "reference": "305b2328d2a2e157bc13b61a0f5c6e41b666b188", "shasum": "" }, "require": { - "evenement/evenement": "~2.0", - "php": ">=5.4.0" + "evenement/evenement": "^2.0|^1.0", + "php": ">=5.3.8" }, "require-dev": { - "react/event-loop": "0.4.*", - "react/promise": "~2.0" + "react/event-loop": "^0.4|^0.3", + "react/promise": "^2.0|^1.0" }, "suggest": { - "react/event-loop": "0.4.*", - "react/promise": "~2.0" + "react/event-loop": "^0.4", + "react/promise": "^2.0" }, "type": "library", "extra": { @@ -818,20 +870,20 @@ "pipe", "stream" ], - "time": "2014-09-10 03:32:31" + "time": "2015-10-07 18:32:58" }, { "name": "sami/sami", - "version": "v3.0.8", + "version": "v3.1.0", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/Sami.git", - "reference": "c7f82710279c9aaa673b1ad27148749e9bf7223c" + "reference": "504f99a1783e2e0e8817a57be946f7c699b83163" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/Sami/zipball/c7f82710279c9aaa673b1ad27148749e9bf7223c", - "reference": "c7f82710279c9aaa673b1ad27148749e9bf7223c", + "url": "https://api.github.com/repos/FriendsOfPHP/Sami/zipball/504f99a1783e2e0e8817a57be946f7c699b83163", + "reference": "504f99a1783e2e0e8817a57be946f7c699b83163", "shasum": "" }, "require": { @@ -876,7 +928,7 @@ "keywords": [ "phpdoc" ], - "time": "2015-08-13 07:35:12" + "time": "2015-08-30 14:15:00" }, { "name": "satooshi/php-coveralls", @@ -948,35 +1000,35 @@ }, { "name": "symfony/config", - "version": "v2.7.4", + "version": "v3.0.0", "source": { "type": "git", - "url": "https://github.com/symfony/Config.git", - "reference": "5ab9ff48b3cb5b40951a607f77fc1cbfd29edba8" + "url": "https://github.com/symfony/config.git", + "reference": "40bae8658dbbb500ebc19aa9fde22dc4295fc290" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Config/zipball/5ab9ff48b3cb5b40951a607f77fc1cbfd29edba8", - "reference": "5ab9ff48b3cb5b40951a607f77fc1cbfd29edba8", + "url": "https://api.github.com/repos/symfony/config/zipball/40bae8658dbbb500ebc19aa9fde22dc4295fc290", + "reference": "40bae8658dbbb500ebc19aa9fde22dc4295fc290", "shasum": "" }, "require": { - "php": ">=5.3.9", - "symfony/filesystem": "~2.3" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" + "php": ">=5.5.9", + "symfony/filesystem": "~2.8|~3.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "3.0-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\Config\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -994,30 +1046,30 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2015-08-27 06:45:45" + "time": "2015-11-02 20:34:04" }, { "name": "symfony/console", - "version": "v2.7.4", + "version": "v2.8.0", "source": { "type": "git", - "url": "https://github.com/symfony/Console.git", - "reference": "9ff9032151186bd66ecee727d728f1319f52d1d8" + "url": "https://github.com/symfony/console.git", + "reference": "d232bfc100dfd32b18ccbcab4bcc8f28697b7e41" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/9ff9032151186bd66ecee727d728f1319f52d1d8", - "reference": "9ff9032151186bd66ecee727d728f1319f52d1d8", + "url": "https://api.github.com/repos/symfony/console/zipball/d232bfc100dfd32b18ccbcab4bcc8f28697b7e41", + "reference": "d232bfc100dfd32b18ccbcab4bcc8f28697b7e41", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { "psr/log": "~1.0", - "symfony/event-dispatcher": "~2.1", - "symfony/phpunit-bridge": "~2.7", - "symfony/process": "~2.1" + "symfony/event-dispatcher": "~2.1|~3.0.0", + "symfony/process": "~2.1|~3.0.0" }, "suggest": { "psr/log": "For using the console logger", @@ -1027,13 +1079,16 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "2.8-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\Console\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1051,20 +1106,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2015-09-03 11:40:38" + "time": "2015-11-30 12:35:10" }, { "name": "symfony/event-dispatcher", - "version": "v2.7.4", + "version": "v2.8.0", "source": { "type": "git", - "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "b58c916f1db03a611b72dd702564f30ad8fe83fa" + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "a5eb815363c0388e83247e7e9853e5dbc14999cc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/b58c916f1db03a611b72dd702564f30ad8fe83fa", - "reference": "b58c916f1db03a611b72dd702564f30ad8fe83fa", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/a5eb815363c0388e83247e7e9853e5dbc14999cc", + "reference": "a5eb815363c0388e83247e7e9853e5dbc14999cc", "shasum": "" }, "require": { @@ -1072,11 +1127,10 @@ }, "require-dev": { "psr/log": "~1.0", - "symfony/config": "~2.0,>=2.0.5", - "symfony/dependency-injection": "~2.6", - "symfony/expression-language": "~2.6", - "symfony/phpunit-bridge": "~2.7", - "symfony/stopwatch": "~2.3" + "symfony/config": "~2.0,>=2.0.5|~3.0.0", + "symfony/dependency-injection": "~2.6|~3.0.0", + "symfony/expression-language": "~2.6|~3.0.0", + "symfony/stopwatch": "~2.3|~3.0.0" }, "suggest": { "symfony/dependency-injection": "", @@ -1085,13 +1139,16 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "2.8-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\EventDispatcher\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1109,38 +1166,38 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2015-08-24 07:13:45" + "time": "2015-10-30 20:15:42" }, { "name": "symfony/filesystem", - "version": "v2.7.4", + "version": "v2.8.0", "source": { "type": "git", - "url": "https://github.com/symfony/Filesystem.git", - "reference": "f079e9933799929584200b9a926f72f29e291654" + "url": "https://github.com/symfony/filesystem.git", + "reference": "3e661a0d521ac67496515fa6e6704bd61bcfff60" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Filesystem/zipball/f079e9933799929584200b9a926f72f29e291654", - "reference": "f079e9933799929584200b9a926f72f29e291654", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/3e661a0d521ac67496515fa6e6704bd61bcfff60", + "reference": "3e661a0d521ac67496515fa6e6704bd61bcfff60", "shasum": "" }, "require": { "php": ">=5.3.9" }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "2.8-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\Filesystem\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1158,38 +1215,38 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2015-08-27 07:03:44" + "time": "2015-11-23 10:19:46" }, { "name": "symfony/finder", - "version": "v2.7.4", + "version": "v2.8.0", "source": { "type": "git", - "url": "https://github.com/symfony/Finder.git", - "reference": "fff4b0c362640a0ab7355e2647b3d461608e9065" + "url": "https://github.com/symfony/finder.git", + "reference": "ead9b07af4ba77b6507bee697396a5c79e633f08" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Finder/zipball/fff4b0c362640a0ab7355e2647b3d461608e9065", - "reference": "fff4b0c362640a0ab7355e2647b3d461608e9065", + "url": "https://api.github.com/repos/symfony/finder/zipball/ead9b07af4ba77b6507bee697396a5c79e633f08", + "reference": "ead9b07af4ba77b6507bee697396a5c79e633f08", "shasum": "" }, "require": { "php": ">=5.3.9" }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "2.8-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\Finder\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1207,38 +1264,94 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2015-08-26 17:56:37" + "time": "2015-10-30 20:15:42" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "0b6a8940385311a24e060ec1fe35680e17c74497" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0b6a8940385311a24e060ec1fe35680e17c74497", + "reference": "0b6a8940385311a24e060ec1fe35680e17c74497", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2015-11-04 20:28:58" }, { "name": "symfony/process", - "version": "v2.7.4", + "version": "v2.8.0", "source": { "type": "git", - "url": "https://github.com/symfony/Process.git", - "reference": "f7b3f73f70a7f8f49a1c838dc3debbf054732d8e" + "url": "https://github.com/symfony/process.git", + "reference": "1b988a88e3551102f3c2d9e1d47a18c3a78d6312" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/f7b3f73f70a7f8f49a1c838dc3debbf054732d8e", - "reference": "f7b3f73f70a7f8f49a1c838dc3debbf054732d8e", + "url": "https://api.github.com/repos/symfony/process/zipball/1b988a88e3551102f3c2d9e1d47a18c3a78d6312", + "reference": "1b988a88e3551102f3c2d9e1d47a18c3a78d6312", "shasum": "" }, "require": { "php": ">=5.3.9" }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "2.8-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\Process\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1256,38 +1369,38 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2015-08-27 06:45:45" + "time": "2015-11-30 12:35:10" }, { "name": "symfony/stopwatch", - "version": "v2.7.4", + "version": "v3.0.0", "source": { "type": "git", - "url": "https://github.com/symfony/Stopwatch.git", - "reference": "abc61bac76fb10ffa2c6373d7932bc35190dbf3b" + "url": "https://github.com/symfony/stopwatch.git", + "reference": "6aeac8907e3e1340a0033b0a9ec075f8e6524800" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/abc61bac76fb10ffa2c6373d7932bc35190dbf3b", - "reference": "abc61bac76fb10ffa2c6373d7932bc35190dbf3b", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/6aeac8907e3e1340a0033b0a9ec075f8e6524800", + "reference": "6aeac8907e3e1340a0033b0a9ec075f8e6524800", "shasum": "" }, "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" + "php": ">=5.5.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "3.0-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\Stopwatch\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1305,38 +1418,38 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2015-08-24 07:13:45" + "time": "2015-10-30 23:35:59" }, { "name": "symfony/yaml", - "version": "v2.7.4", + "version": "v2.8.0", "source": { "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "2dc7b06c065df96cc686c66da2705e5e18aef661" + "url": "https://github.com/symfony/yaml.git", + "reference": "f79824187de95064a2f5038904c4d7f0227fedb5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/2dc7b06c065df96cc686c66da2705e5e18aef661", - "reference": "2dc7b06c065df96cc686c66da2705e5e18aef661", + "url": "https://api.github.com/repos/symfony/yaml/zipball/f79824187de95064a2f5038904c4d7f0227fedb5", + "reference": "f79824187de95064a2f5038904c4d7f0227fedb5", "shasum": "" }, "require": { "php": ">=5.3.9" }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "2.8-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\Yaml\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1354,20 +1467,20 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2015-08-24 07:13:45" + "time": "2015-11-30 12:35:10" }, { "name": "twig/twig", - "version": "v1.22.1", + "version": "v1.23.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "b7fc2469fa009897871fb95b68237286fc54a5ad" + "reference": "d9b6333ae8dd2c8e3fd256e127548def0bc614c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/b7fc2469fa009897871fb95b68237286fc54a5ad", - "reference": "b7fc2469fa009897871fb95b68237286fc54a5ad", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/d9b6333ae8dd2c8e3fd256e127548def0bc614c6", + "reference": "d9b6333ae8dd2c8e3fd256e127548def0bc614c6", "shasum": "" }, "require": { @@ -1380,7 +1493,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.22-dev" + "dev-master": "1.23-dev" } }, "autoload": { @@ -1415,7 +1528,7 @@ "keywords": [ "templating" ], - "time": "2015-09-15 06:50:16" + "time": "2015-11-05 12:49:06" } ], "aliases": [ diff --git a/src/Coroutine/PromiseCoroutine.php b/src/Coroutine/PromiseCoroutine.php index 3afcc50..06ff6d8 100644 --- a/src/Coroutine/PromiseCoroutine.php +++ b/src/Coroutine/PromiseCoroutine.php @@ -3,8 +3,6 @@ namespace Recoil\Coroutine; use Exception; -use GuzzleHttp\Promise\PromiseInterface as GuzzlePromise; -use React\Promise\CancellablePromiseInterface; use Recoil\Coroutine\Exception\PromiseRejectedException; use Recoil\Kernel\Strand\Strand; @@ -16,11 +14,13 @@ class PromiseCoroutine implements Coroutine use CoroutineTrait; /** - * @param object $promise The wrapped promise object. + * @param object $promise The wrapped promise object. + * @param boolean $cancellable True if the promise has a cancel() method. */ - public function __construct($promise) + public function __construct($promise, $cancellable) { $this->promise = $promise; + $this->cancellable = $cancellable; } /** @@ -55,10 +55,7 @@ function ($reason) use ($strand) { */ public function terminate(Strand $strand) { - if ( - $this->promise instanceof CancellablePromiseInterface || - $this->promise instanceof GuzzlePromise - ) { + if ($this->cancellable) { $this->promise->cancel(); } } diff --git a/src/Coroutine/StandardCoroutineAdaptor.php b/src/Coroutine/StandardCoroutineAdaptor.php index 76eaf29..e600732 100644 --- a/src/Coroutine/StandardCoroutineAdaptor.php +++ b/src/Coroutine/StandardCoroutineAdaptor.php @@ -3,10 +3,11 @@ namespace Recoil\Coroutine; use Generator; -use GuzzleHttp\Promise\PromiseInterface as GuzzlePromise; +use GuzzleHttp\Promise\PromiseInterface as GuzzlePromiseInterface; use Icecave\Repr\Repr; use InvalidArgumentException; -use React\Promise\PromiseInterface as ReactPromise; +use React\Promise\CancellablePromiseInterface; +use React\Promise\PromiseInterface; use Recoil\Kernel\Strand\Strand; use Recoil\Recoil; @@ -34,11 +35,12 @@ public function adapt(Strand $strand, $value) return $value; } elseif ($value instanceof Generator) { return new GeneratorCoroutine($value); - } elseif ( - $value instanceof ReactPromise || - $value instanceof GuzzlePromise - ) { - return new PromiseCoroutine($value); + } elseif ($value instanceof CancellablePromiseInterface) { + return new PromiseCoroutine($value, true); + } elseif ($value instanceof PromiseInterface) { + return new PromiseCoroutine($value, false); + } elseif ($value instanceof GuzzlePromiseInterface) { + return new PromiseCoroutine($value, true); } elseif (is_array($value)) { return Recoil::all($value); } elseif (null === $value) { diff --git a/test/suite/Coroutine/PromiseCoroutineTest.php b/test/suite/Coroutine/PromiseCoroutineTest.php index 63e0fb6..eeb42d9 100644 --- a/test/suite/Coroutine/PromiseCoroutineTest.php +++ b/test/suite/Coroutine/PromiseCoroutineTest.php @@ -28,7 +28,8 @@ public function testFulfilledPromise() $value = null; $coroutine = function () use (&$value) { $value = (yield new PromiseCoroutine( - new FulfilledPromise(123) + new FulfilledPromise(123), + false )); }; @@ -45,7 +46,8 @@ public function testRejectedPromise() $coroutine = function () use (&$exception) { try { yield new PromiseCoroutine( - new RejectedPromise(new Exception('This is the exception.')) + new RejectedPromise(new Exception('This is the exception.')), + false ); } catch (Exception $e) { $exception = $e; @@ -66,7 +68,8 @@ public function testRejectedPromiseWithNonExceptionReason() $coroutine = function () use (&$exception) { try { yield new PromiseCoroutine( - new RejectedPromise('This is the exception.') + new RejectedPromise('This is the exception.'), + false ); } catch (PromiseRejectedException $e) { $exception = $e; @@ -85,7 +88,7 @@ public function testTerminateThenFulfill() { $deferred = new Deferred(); $promise = $deferred->promise(); - $promiseCoroutine = new PromiseCoroutine($promise); + $promiseCoroutine = new PromiseCoroutine($promise, false); $resumed = null; $coroutine = function () use (&$resumed, $promiseCoroutine) { @@ -117,7 +120,7 @@ public function testTerminateThenReject() }; $promise = new Promise(function () {}, $promiseCanceller); - $promiseCoroutine = new PromiseCoroutine($promise); + $promiseCoroutine = new PromiseCoroutine($promise, true); $coroutine = function () use ($promiseCoroutine) { yield $promiseCoroutine; diff --git a/test/suite/Coroutine/StandardCoroutineAdaptorTest.php b/test/suite/Coroutine/StandardCoroutineAdaptorTest.php index b5268de..6da0299 100644 --- a/test/suite/Coroutine/StandardCoroutineAdaptorTest.php +++ b/test/suite/Coroutine/StandardCoroutineAdaptorTest.php @@ -2,8 +2,10 @@ namespace Recoil\Coroutine; +use GuzzleHttp\Promise\PromiseInterface as GuzzlePromiseInterface; use Phake; use PHPUnit_Framework_TestCase; +use React\Promise\CancellablePromiseInterface; use React\Promise\PromiseInterface; use Recoil\Kernel\Api\KernelApiCall; use Recoil\Kernel\Strand\Strand; @@ -47,7 +49,32 @@ public function testAdaptWithPromise() $promise = Phake::mock(PromiseInterface::class); $coroutine = $this->adaptor->adapt($this->strand, $promise); - $this->assertInstanceOf(PromiseCoroutine::class, $coroutine); + $this->assertEquals( + new PromiseCoroutine($promise, false), + $coroutine + ); + } + + public function testAdaptWithCancellablePromise() + { + $promise = Phake::mock(CancellablePromiseInterface::class); + $coroutine = $this->adaptor->adapt($this->strand, $promise); + + $this->assertEquals( + new PromiseCoroutine($promise, true), + $coroutine + ); + } + + public function testAdaptWithGuzzlePromise() + { + $promise = Phake::mock(GuzzlePromiseInterface::class); + $coroutine = $this->adaptor->adapt($this->strand, $promise); + + $this->assertEquals( + new PromiseCoroutine($promise, true), + $coroutine + ); } public function testAdaptWithArray() From ec7b8f768731881fe99b1f0ccf23b33d209b4ba2 Mon Sep 17 00:00:00 2001 From: James Harris Date: Sun, 6 Mar 2016 16:46:46 +1000 Subject: [PATCH 24/24] Bumped version, updated changelog. --- CHANGELOG.md | 43 ++++++++++++++++++++++++------------------- README.md | 2 +- src/PackageInfo.php | 2 +- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cd5866..f81b360 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,32 +1,37 @@ # Recoil Changelog -### Next Version (predicted 0.4.0) +## 0.4.0 (2016-03-06) -* **[BC]** Dropped `Interface` suffix from interfaces -* **[BC]** Renamed `ReadableStream` to `ReadablePhpStream` -* **[BC]** Renamed `WritableStream` to `WritablePhpStream` -* **[BC]** Renamed `CoroutineAdaptor` to `StandardCoroutineAdaptor` -* **[BC]** Renamed `KernelApi` to `StandardKernelApi` -* **[BC]** Renamed `Strand` to `StandardStrand` -* **[BC]** Renamed `StrandFactory` to `StandardStrandFactory` +This is the final release that will operate with PHP 5. In an effort to work +towards a production ready 1.0 release, future releases will require PHP 7. -### 0.3.0 (2015-06-26) +- **[BC]** Dropped `Interface` suffix from interfaces +- **[BC]** Renamed `ReadableStream` to `ReadablePhpStream` +- **[BC]** Renamed `WritableStream` to `WritablePhpStream` +- **[BC]** Renamed `CoroutineAdaptor` to `StandardCoroutineAdaptor` +- **[BC]** Renamed `KernelApi` to `StandardKernelApi` +- **[BC]** Renamed `Strand` to `StandardStrand` +- **[BC]** Renamed `StrandFactory` to `StandardStrandFactory` +- **[NEW]** Added support for Guzzle promises +- **[IMPROVED]** The callback given to `Recoil::suspend` is now optional -* **[BC]** Removed `StrandInterface::resume()` -* **[NEW]** `return` statement can be used to return a value inside a coroutine (requires PHP 7) -* **[IMPROVED]** Improved method documentation on `Recoil` facade (thanks @rjkip) +## 0.3.0 (2015-06-26) -### 0.2.1 (2014-10-16) +- **[BC]** Removed `StrandInterface::resume()` +- **[NEW]** `return` statement can be used to return a value inside a coroutine (requires PHP 7) +- **[IMPROVED]** Improved method documentation on `Recoil` facade (thanks @rjkip) -* **[IMPROVED]** Added support for cancellable promises +## 0.2.1 (2014-10-16) -### 0.2.0 (2014-09-23) +- **[IMPROVED]** Added support for cancellable promises + +## 0.2.0 (2014-09-23) To faciliate several performance improvements the following backwards compatibility breaking changes have been introduced: -* **[BC]** `CoroutineInterface` no longer implements `EventEmitterInterface` - several unused events were fired every time a coroutine was called -* **[BC]** `Recoil::finalize()` now only works with generator based coroutines - this was previously implemented using the aforementioned events +- **[BC]** `CoroutineInterface` no longer implements `EventEmitterInterface` - several unused events were fired every time a coroutine was called +- **[BC]** `Recoil::finalize()` now only works with generator based coroutines - this was previously implemented using the aforementioned events -### 0.1.0 (2014-02-04) +## 0.1.0 (2014-02-04) -* Initial release +- Initial release diff --git a/README.md b/README.md index 6d69c8d..0491849 100644 --- a/README.md +++ b/README.md @@ -344,4 +344,4 @@ $eventLoop->run(); [Build Status]: http://img.shields.io/travis/recoilphp/recoil/develop.svg?style=flat-square [Test Coverage]: http://img.shields.io/coveralls/recoilphp/recoil/develop.svg?style=flat-square -[SemVer]: http://img.shields.io/:semver-0.3.0-yellow.svg?style=flat-square +[SemVer]: http://img.shields.io/:semver-0.4.0-yellow.svg?style=flat-square diff --git a/src/PackageInfo.php b/src/PackageInfo.php index 0e64140..7c7806b 100644 --- a/src/PackageInfo.php +++ b/src/PackageInfo.php @@ -5,5 +5,5 @@ class PackageInfo { const NAME = 'Recoil'; - const VERSION = '0.3.0'; + const VERSION = '0.4.0'; }