-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
253 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,2 @@ | ||
REDIS_HOST=0.0.0.0 | ||
REDIS_PORT=6379 | ||
REDIS_PASSWORD= | ||
REDIS_USERNAME= | ||
REDIS_DATABASE=0 | ||
|
||
SERVER_HOST=0.0.0.0 | ||
SERVER_PORT=8080 | ||
SERVER_WORKERNUM=1 | ||
|
||
CONFIG_FILE=./config.json | ||
TRANSPORT_FILE=/configs/transport.yml | ||
ADAPTER_FILE=/configs/adapter.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,46 @@ | ||
<?php | ||
error_reporting(E_ALL ^ E_DEPRECATED); | ||
|
||
use Octamp\Wamp\Adapter\RedisAdapter; | ||
use Octamp\Wamp\Config\AdapterConfiguration; | ||
use Octamp\Wamp\Config\TransportConfiguration; | ||
use Octamp\Wamp\Config\TransportProviderConfig; | ||
use Octamp\Wamp\Wamp; | ||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; | ||
use Symfony\Component\Config\Definition\Processor; | ||
use Symfony\Component\Dotenv\Dotenv; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
$loader = require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$env = new Dotenv(); | ||
$env->loadEnv(dirname(__DIR__) . '/.env'); | ||
$rootPath = dirname(__DIR__); | ||
|
||
$env = new Dotenv(); | ||
$env->loadEnv($rootPath . '/.env'); | ||
|
||
$redisOptions = [ | ||
'options' => [ | ||
'database' => $_ENV['REDIS_DATABASE'] ?? 0, | ||
] | ||
]; | ||
try { | ||
$processor = new Processor(); | ||
$transportConfig = (object)$processor->processConfiguration(new TransportConfiguration(), Yaml::parseFile($rootPath . $_ENV['TRANSPORT_FILE'])); | ||
$transportProviderConfig = new TransportProviderConfig( | ||
host: $transportConfig->host, | ||
port: $transportConfig->port, | ||
workerNum: $transportConfig->workerNum, | ||
realms: $transportConfig->realms ?? [], | ||
auth: $transportConfig->auths ?? [] | ||
); | ||
$adapterConfig = (object)$processor->processConfiguration(new AdapterConfiguration(), Yaml::parseFile($rootPath . $_ENV['ADAPTER_FILE'])); | ||
$adapter = new RedisAdapter( | ||
$adapterConfig->host, | ||
$adapterConfig->port, | ||
$adapterConfig->auth?->username ?? null, | ||
$adapterConfig->auth?->password ?? null, | ||
$adapterConfig->options ?? [] | ||
); | ||
} catch (InvalidConfigurationException $exception) { | ||
printf('[INVALID][%s]: %s', $exception->getPath(), $exception->getMessage()); | ||
exit(1); | ||
} | ||
|
||
$adapter = new RedisAdapter( | ||
$_ENV['REDIS_HOST'], | ||
$_ENV['REDIS_PORT'], | ||
$_ENV['REDIS_USERNAME'] ?? null, | ||
$_ENV['REDIS_PASSWORD'] ?? null, | ||
$redisOptions | ||
); | ||
$transportConfig = new TransportProviderConfig( | ||
host: $_ENV['SERVER_HOST'], | ||
port: $_ENV['SERVER_PORT'], | ||
workerNum: $_ENV['SERVER_WORKERNUM'], | ||
realms: [ | ||
[ | ||
'name' => 'realm1' | ||
], | ||
], | ||
auth: [ | ||
[ | ||
'method' => 'ticket', | ||
'type' => 'dynamic', | ||
'authenticator' => 'testing', | ||
'authenticator-realm' => 'realm1', | ||
'realms' => ['realm1'] | ||
], | ||
[ | ||
'method' => 'wampcra', | ||
'type' => 'static', | ||
'users' => [ | ||
[ | ||
'authid' => 'auth', | ||
'secret' => 'qa2/QVmmjSx1JJuyH5EI2gMDQf+ARnfwMcLOpUfln74=', | ||
'role' => 'auth', | ||
'salt' => 'salt1', | ||
'keylen' => 32, | ||
'iterations' => 1000 | ||
], | ||
], | ||
] | ||
], | ||
); | ||
$wamp = new Wamp($transportConfig, $adapter); | ||
$wamp = new Wamp($transportProviderConfig, $adapter); | ||
|
||
$wamp->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
adapter: | ||
type: redis | ||
host: 0.0.0.0 | ||
port: 6379 | ||
# -- Uncomment the auth if you need username and password | ||
# auth: | ||
# username: | ||
# password: | ||
# | ||
# -- Uncomment options if you need to include other redis option such as database | ||
options: | ||
database: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
transport: | ||
host: 0.0.0.0 | ||
port: 8080 | ||
workerNum: 1 | ||
realms: | ||
- name: realm1 | ||
auths: | ||
- method: anonymous | ||
type: static | ||
# -- You can add more method, such us the examples below | ||
# - method: ticket | ||
# type: dynamic | ||
# authenticator: testing | ||
# authenticatorRealm: realm1 | ||
# realms: | ||
# - realm1 | ||
# - method: wampcra | ||
# type: static | ||
# users: | ||
# - authid: auth | ||
# secret: qa2/QVmmjSx1JJuyH5EI2gMDQf+ARnfwMcLOpUfln74= | ||
# role: auth | ||
# salt: salt1 | ||
# keylen: 32 | ||
# iterations: 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Octamp\Wamp\Config; | ||
|
||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class AdapterConfiguration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$treeBuilder = new TreeBuilder('adapter'); | ||
$this->configure($treeBuilder->getRootNode()); | ||
|
||
return $treeBuilder; | ||
} | ||
|
||
protected function configure(NodeDefinition|ArrayNodeDefinition $rootNode): void | ||
{ | ||
$rootNode | ||
->children() | ||
->enumNode('type') | ||
->values(['redis']) | ||
->defaultValue('redis') | ||
->end() | ||
->scalarNode('host') | ||
->defaultValue('0.0.0.0') | ||
->end() | ||
->integerNode('port') | ||
->defaultValue(6379) | ||
->end() | ||
->arrayNode('auth') | ||
->children() | ||
->scalarNode('username')->end() | ||
->scalarNode('password')->end() | ||
->end() | ||
->end() | ||
->arrayNode('options') | ||
->ignoreExtraKeys(false) | ||
->children() | ||
->integerNode('database')->defaultValue(0)->end() | ||
->end() | ||
->end() | ||
->end(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Octamp\Wamp\Config; | ||
|
||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class TransportConfiguration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$treeBuilder = new TreeBuilder('transport'); | ||
$this->configure($treeBuilder->getRootNode()); | ||
|
||
return $treeBuilder; | ||
} | ||
|
||
protected function configure(NodeDefinition|ArrayNodeDefinition $rootNode): void | ||
{ | ||
$rootNode | ||
->children() | ||
->scalarNode('host')->isRequired()->end() | ||
->integerNode('port')->isRequired()->end() | ||
->integerNode('workerNum')->defaultValue(1)->end() | ||
->arrayNode('realms')->requiresAtLeastOneElement() | ||
->arrayPrototype() | ||
->children() | ||
->scalarNode('name')->isRequired()->end() | ||
->end() | ||
->end() | ||
->isRequired() | ||
->validate() | ||
->ifEmpty()->thenInvalid('Realms should not empty') | ||
->end() | ||
->end() | ||
->arrayNode('auths') | ||
->arrayPrototype() | ||
->children() | ||
->enumNode('method')->values(['anonymous', 'ticket', 'wampcra'])->isRequired()->end() | ||
->enumNode('type')->values(['static', 'dynamic'])->isRequired()->end() | ||
->scalarNode('authenticator')->end() | ||
->scalarNode('authenticatorRealm')->end() | ||
->arrayNode('realms') | ||
->scalarPrototype()->end() | ||
->validate() | ||
->ifEmpty()->thenInvalid('Realms should not empty') | ||
->end() | ||
->end() | ||
->arrayNode('users') | ||
->arrayPrototype()->ignoreExtraKeys(false)->end() | ||
->validate() | ||
->ifEmpty()->thenInvalid('Users should not empty') | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
->isRequired() | ||
->validate() | ||
->ifEmpty()->thenInvalid('Auths should have one auth method') | ||
->end() | ||
->end() | ||
->end(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.