Title: [RFC] Consider adding functional API · Issue #330 · reactphp/reactphp · GitHub
Open Graph Title: [RFC] Consider adding functional API · Issue #330 · reactphp/reactphp
X Title: [RFC] Consider adding functional API · Issue #330 · reactphp/reactphp
Description: Our OOP API has a pretty good, SOLID design – but let's face it, this often makes it hard to work with. For example, take a look at the following code required to connect to a remote host: $loop = React\EventLoop\Factory::create(); $reso...
Open Graph Description: Our OOP API has a pretty good, SOLID design – but let's face it, this often makes it hard to work with. For example, take a look at the following code required to connect to a remote host: $loop = ...
X Description: Our OOP API has a pretty good, SOLID design – but let's face it, this often makes it hard to work with. For example, take a look at the following code required to connect to a remote host: $loo...
Mail addresses
notifications@github.com
Opengraph URL: https://github.com/reactphp/reactphp/issues/330
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[RFC] Consider adding functional API","articleBody":"Our OOP API has a pretty good, SOLID design – but let's face it, this often makes it hard to work with. For example, take a look at the following code required to connect to a remote host:\n\n```\n$loop = React\\EventLoop\\Factory::create();\n$resolverFactory = new React\\Dns\\Resolver\\Factory();\n$resolver = $resolverFactory->create('8.8.8.8', $loop);\n$connector = new Connector($loop, $resolver);\n$secure = new SecureConnector($connector, $loop);\n\n$secure->create('www.google.com', 443);\n```\n\nOur current OOP API suffers from the fact that we do not require any global/shared state. This means we can not assume any defaults for common setups and requires passing quite a few instances. Instances that are effectively only constructed once.\n\nAfter discussing this with @cboden, I figured it's worth opening this ticket as a basis for further discussion / RFC:\n\nThis ticket suggests we add a much simpler API on top of the existing class hierarchy (and does _not_ suggest _replacing_ it!). So we're merely talking about some API sugar.\n\nNote however, this comes at the cost of _some_ global state.\n\nAt the lowest level, we need a global accessor for the current loop (this has originally been suggested by @igorw (https://github.com/reactphp/event-loop/pull/10)):\n\n```\n$loop = \\React\\EventLoop\\loop();\n```\n\nStream component (requires global loop):\n\n```\n\\React\\Stream\\fopen('demo.txt', 'r')->then(function (Stream $stream) {\n\n});\n```\n\nDNS component (requires global loop and DNS `Resolver`):\n\n```\n\\React\\Dns\\lookup('www.google.com')->then(function ($ip) {\n echo $ip;\n});\n```\n\nSocketClient component (requires global loop and DNS `Resolver`):\n\n```\n\\React\\SocketClient\\connect('google.com:80')->then(function (Connection $connection) {\n\n});\n```\n\nSocket component (requires global loop):\n\n```\n\\React\\Socket\\listen('localhost:1234')->then(function (Socket $socket) {\n $socket->on('connection', function () { });\n});\n```\n","author":{"url":"https://github.com/clue","@type":"Person","name":"clue"},"datePublished":"2015-06-07T15:59:08Z","url":"https://github.com/reactphp/reactphp/issues/330"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:92039ac9-2313-e774-d40a-2dbaa5434787 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A55A:215B38:CA925:114792:6B0062B3 |
| html-safe-nonce | aaad2a9bfa06727c8b8da804e7ce8422161dedc63064da88be2bf76d206d23e8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTVBOjIxNUIzODpDQTkyNToxMTQ3OTI6NkIwMDYyQjMiLCJ2aXNpdG9yX2lkIjoiNzc4MDY3NDE1ODY0MzQwNTQ5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2610e26425f9b8caea88b8e61a8d20d9204f5e992ef6e4b1cd468c54f580ca0d |
| hovercard-subject-tag | issue:85913411 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/reactphp/reactphp/330/issue_layout |
| twitter:image | https://opengraph.githubassets.com/49a8053b90fc6e3c30c8043bc0e3a6fed7a2e45a3aa861591d00803928b01465/reactphp/reactphp/issues/330 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/49a8053b90fc6e3c30c8043bc0e3a6fed7a2e45a3aa861591d00803928b01465/reactphp/reactphp/issues/330 |
| og:image:alt | Our OOP API has a pretty good, SOLID design – but let's face it, this often makes it hard to work with. For example, take a look at the following code required to connect to a remote host: $loop = ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | clue |
| hostname | github.com |
| expected-hostname | github.com |
| None | 25854482a1773a7c1ebb8be3d2bc1c6e61d82d78126be63b5044474a86d44d9e |
| turbo-cache-control | no-preview |
| go-import | github.com/reactphp/reactphp git https://github.com/reactphp/reactphp.git |
| octolytics-dimension-user_id | 1696866 |
| octolytics-dimension-user_login | reactphp |
| octolytics-dimension-repository_id | 4287921 |
| octolytics-dimension-repository_nwo | reactphp/reactphp |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 4287921 |
| octolytics-dimension-repository_network_root_nwo | reactphp/reactphp |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e4f5c239e31f1f680e6bbc419ff92d774da616ec |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width