Compare commits
6 Commits
a218ba6932
...
0.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| ea6395df14 | |||
| 0c63f0f160 | |||
| 4be42b4c50 | |||
| 8fe2206f31 | |||
| c48b6ab90d | |||
| b5d10ae94b |
@@ -0,0 +1,3 @@
|
||||
composer.lock
|
||||
/nbproject/
|
||||
/vendor/
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "potter/socket",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Potter\\": "src/Potter/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jay Potter",
|
||||
"email": "j@ypotter.ca"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "stable",
|
||||
"require": {
|
||||
"evenement/evenement": ">=3.0.2",
|
||||
"graham-campbell/result-type": ">=1.1.4",
|
||||
"phpoption/phpoption": ">=1.9.5",
|
||||
"potter/container": ">=0.0.1",
|
||||
"react/cache": ">=1.2.0",
|
||||
"react/dns": ">=1.14.0",
|
||||
"react/event-loop": ">=1.6.0",
|
||||
"react/promise": ">=3.3.0",
|
||||
"react/socket": ">=1.17.0",
|
||||
"react/stream": ">=1.4.0",
|
||||
"symfony/polyfill-ctype": ">=1.37.0",
|
||||
"symfony/polyfill-mbstring": ">=1.38.2",
|
||||
"symfony/polyfill-php80": ">=1.37.0",
|
||||
"vlucas/phpdotenv": ">=5.6.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Potter;
|
||||
|
||||
use \React\Socket\SocketServer;
|
||||
|
||||
trait Socket
|
||||
{
|
||||
private static function addSocketBehaviour(Container $container): void
|
||||
{
|
||||
static::getEnvironment($container)
|
||||
->required('APPLICATION_PORT');
|
||||
|
||||
self::addSocketServer($container);
|
||||
}
|
||||
|
||||
private static function addSocketServer(Container $container): void
|
||||
{
|
||||
$container->addShared(SocketServer::class)
|
||||
->addArgument('127.0.0.1:' . $_ENV['APPLICATION_PORT']);
|
||||
}
|
||||
|
||||
abstract private static function getEnvironment(Container $container): \Dotenv\Dotenv;
|
||||
|
||||
private static function getSocketServer(Container $container): SocketServer
|
||||
{
|
||||
return $container->get(SocketServer::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user