mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 02:13:15 +00:00
Add WebsocketServer command
This commit is contained in:
@@ -13,6 +13,8 @@ namespace KonsoleKommander;
|
|||||||
|
|
||||||
use Alchemy\Phrasea\Command\Plugin\ListPlugin;
|
use Alchemy\Phrasea\Command\Plugin\ListPlugin;
|
||||||
use Alchemy\Phrasea\Command\SearchEngine\IndexFull;
|
use Alchemy\Phrasea\Command\SearchEngine\IndexFull;
|
||||||
|
use Alchemy\Phrasea\Command\WebsocketServer;
|
||||||
|
use Alchemy\Phrasea\Core\Version;
|
||||||
use Alchemy\Phrasea\Command\BuildMissingSubdefs;
|
use Alchemy\Phrasea\Command\BuildMissingSubdefs;
|
||||||
use Alchemy\Phrasea\Command\CreateCollection;
|
use Alchemy\Phrasea\Command\CreateCollection;
|
||||||
use Alchemy\Phrasea\Command\MailTest;
|
use Alchemy\Phrasea\Command\MailTest;
|
||||||
@@ -20,7 +22,6 @@ use Alchemy\Phrasea\Command\Compile\Configuration;
|
|||||||
use Alchemy\Phrasea\Command\RecordAdd;
|
use Alchemy\Phrasea\Command\RecordAdd;
|
||||||
use Alchemy\Phrasea\Command\RescanTechnicalDatas;
|
use Alchemy\Phrasea\Command\RescanTechnicalDatas;
|
||||||
use Alchemy\Phrasea\Command\UpgradeDBDatas;
|
use Alchemy\Phrasea\Command\UpgradeDBDatas;
|
||||||
use Alchemy\Phrasea\Core\Version;
|
|
||||||
use Alchemy\Phrasea\CLI;
|
use Alchemy\Phrasea\CLI;
|
||||||
use Alchemy\Phrasea\Command\Plugin\AddPlugin;
|
use Alchemy\Phrasea\Command\Plugin\AddPlugin;
|
||||||
use Alchemy\Phrasea\Command\Plugin\RemovePlugin;
|
use Alchemy\Phrasea\Command\Plugin\RemovePlugin;
|
||||||
@@ -114,6 +115,8 @@ if ($cli['phraseanet.SE']->getName() === 'ElasticSearch') {
|
|||||||
$cli->command(new IndexFull('searchengine:index'));
|
$cli->command(new IndexFull('searchengine:index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cli->command(new WebsocketServer('ws-server:run'));
|
||||||
|
|
||||||
$cli->loadPlugins();
|
$cli->loadPlugins();
|
||||||
|
|
||||||
exit(is_int($cli->run()) ? : 1);
|
exit(is_int($cli->run()) ? : 1);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea;
|
|||||||
|
|
||||||
use Alchemy\Phrasea\Command\CommandInterface;
|
use Alchemy\Phrasea\Command\CommandInterface;
|
||||||
use Alchemy\Phrasea\Core\CLIProvider\TranslationExtractorServiceProvider;
|
use Alchemy\Phrasea\Core\CLIProvider\TranslationExtractorServiceProvider;
|
||||||
|
use Alchemy\Phrasea\Core\CLIProvider\WebsocketServerServiceProvider;
|
||||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||||
use Symfony\Component\Console;
|
use Symfony\Component\Console;
|
||||||
use Alchemy\Phrasea\Core\CLIProvider\CLIDriversServiceProvider;
|
use Alchemy\Phrasea\Core\CLIProvider\CLIDriversServiceProvider;
|
||||||
@@ -55,6 +56,7 @@ class CLI extends Application
|
|||||||
});
|
});
|
||||||
|
|
||||||
$this->register(new PluginServiceProvider());
|
$this->register(new PluginServiceProvider());
|
||||||
|
$this->register(new WebsocketServerServiceProvider());
|
||||||
$this->register(new ComposerSetupServiceProvider());
|
$this->register(new ComposerSetupServiceProvider());
|
||||||
$this->register(new CLIDriversServiceProvider());
|
$this->register(new CLIDriversServiceProvider());
|
||||||
$this->register(new LessBuilderServiceProvider());
|
$this->register(new LessBuilderServiceProvider());
|
||||||
|
|||||||
38
lib/Alchemy/Phrasea/Command/WebsocketServer.php
Normal file
38
lib/Alchemy/Phrasea/Command/WebsocketServer.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2014 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Command;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
class WebsocketServer extends Command
|
||||||
|
{
|
||||||
|
public function __construct($name = null)
|
||||||
|
{
|
||||||
|
parent::__construct($name);
|
||||||
|
|
||||||
|
$this
|
||||||
|
->setDescription("Runs the websocket server");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doExecute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$sessionConf = $this->container['conf']->get(['main', 'session', 'type'], 'file');
|
||||||
|
|
||||||
|
if (!in_array($sessionConf, ['memcached', 'memcache', 'redis'])) {
|
||||||
|
throw new RuntimeException(sprintf('Running the websocket server requires a server session storage, type `%s` provided', $sessionConf));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->container['ws.server']->run();
|
||||||
|
}
|
||||||
|
}
|
||||||
29
tests/Alchemy/Tests/Phrasea/Command/WebsocketServerTest.php
Normal file
29
tests/Alchemy/Tests/Phrasea/Command/WebsocketServerTest.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Alchemy\Tests\Phrasea\Command;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Command\WebsocketServer;
|
||||||
|
|
||||||
|
class WebsocketServerTest extends \PhraseanetTestCase
|
||||||
|
{
|
||||||
|
public function testRunWithoutProblems()
|
||||||
|
{
|
||||||
|
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
|
||||||
|
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
|
||||||
|
|
||||||
|
$sessionType = self::$DI['cli']['conf']->get(['main', 'session', 'type'], 'file');
|
||||||
|
self::$DI['cli']['conf']->set(['main', 'session', 'type'], 'memcached');
|
||||||
|
|
||||||
|
self::$DI['cli']['ws.server'] = $this->getMockBuilder('Ratchet\App')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
self::$DI['cli']['ws.server']->expects($this->once())
|
||||||
|
->method('run');
|
||||||
|
|
||||||
|
$command = new WebsocketServer('websocketserver');
|
||||||
|
$command->setContainer(self::$DI['cli']);
|
||||||
|
$command->execute($input, $output);
|
||||||
|
|
||||||
|
self::$DI['cli']['conf']->set(['main', 'session', 'type'], $sessionType);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user