<commit_before><?php

/**
 * This file is part of Ratchet for CakePHP.
 *
 ** (c) 2012 - 2013 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

App::uses('Security', 'Utility');
App::uses('CakeWampAppServer', 'Ratchet.Lib/Wamp');
App::uses('PhpSerializeHandler', 'Ratchet.Lib');
App::uses('CakeWampSessionHandler', 'Ratchet.Model/Datasource/Session');
App::uses('RatchetCakeSession', 'Ratchet.Lib');
App::uses('RatchetMessageQueueProxy', 'Ratchet.Lib/MessageQueue/Transports');
App::uses('RatchetMessageQueueModelUpdateCommand', 'RatchetModelPush.Lib/MessageQueue/Command');
App::uses('RatchetMessageQueueKillSwitchCommand', 'RatchetCommands.Lib/MessageQueue/Command');

use Ratchet\Http\HttpServer;
use Ratchet\Server\FlashPolicy;
use Ratchet\Server\IoServer;
use Ratchet\Session\SessionProvider;
use Ratchet\Wamp\WampServer;
use Ratchet\WebSocket\WsServer;
use React\EventLoop\Factory as LoopFactory;
use React\Socket\Server as Reactor;

class WebsocketShell extends Shell {

/**
 * The ReactPHP event loop making async programming in PHP possible
 *
 * @var \React\EventLoop\LoopInterface
 */
	private $__loop;

/**
 * The IO server handling the incoming websocket connections
 *
 * @var \Ratchet\Server\IoServer
 */
	private $__ioServer;

/**
 * Starts the websocket server
 *
 * @return void
 */
	public function start() {
		$this->__loop = LoopFactory::create();

		$socket = new Reactor($this->__loop);
		$socket->listen(Configure::read('Ratchet.Connection.websocket.port'), Configure::read('Ratchet.Connection.websocket.address'));
		$this->__ioServer = new IoServer(
			new HttpServer(
				new WsServer(
					new SessionProvider(
						new WampServer(
							new CakeWampAppServer(
								$this,
								$this->__loop,
								$this->params['verbose']
							)
						),
						new CakeWampSessionHandler(),
						array(),
						new PhpSerializeHandler()
					)
				)
			),
			$socket,
			$this->__loop
		);

		$this->__loop->run();
	}

/**<commit_msg>Added a warning when the configuration doesn't support ext-libevent<commit_after><?php

/**
 * This file is part of Ratchet for CakePHP.
 *
 ** (c) 2012 - 2013 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

App::uses('Security', 'Utility');
App::uses('CakeWampAppServer', 'Ratchet.Lib/Wamp');
App::uses('PhpSerializeHandler', 'Ratchet.Lib');
App::uses('CakeWampSessionHandler', 'Ratchet.Model/Datasource/Session');
App::uses('RatchetCakeSession', 'Ratchet.Lib');
App::uses('RatchetMessageQueueProxy', 'Ratchet.Lib/MessageQueue/Transports');
App::uses('RatchetMessageQueueModelUpdateCommand', 'RatchetModelPush.Lib/MessageQueue/Command');
App::uses('RatchetMessageQueueKillSwitchCommand', 'RatchetCommands.Lib/MessageQueue/Command');

use Ratchet\Http\HttpServer;
use Ratchet\Server\FlashPolicy;
use Ratchet\Server\IoServer;
use Ratchet\Session\SessionProvider;
use Ratchet\Wamp\WampServer;
use Ratchet\WebSocket\WsServer;
use React\EventLoop\Factory as LoopFactory;
use React\Socket\Server as Reactor;

class WebsocketShell extends Shell {

/**
 * The ReactPHP event loop making async programming in PHP possible
 *
 * @var \React\EventLoop\LoopInterface
 */
	private $__loop;

/**
 * The IO server handling the incoming websocket connections
 *
 * @var \Ratchet\Server\IoServer
 */
	private $__ioServer;

/**
 * Starts the websocket server
 *
 * @return void
 */
	public function start() {
		$this->__loop = LoopFactory::create();

		if ($this->__loop instanceof \React\EventLoop\StreamSelectLoop) {
			$this->out('<warning>Your configuration doesn\'t seem to support \'ext-libevent\'. It is highly reccomended that you install and configure it as it provides significant performance gains over stream select!</warning>');
		}

		$socket = new Reactor($this->__loop);
		$socket->listen(Configure::read('Ratchet.Connection.websocket.port'), Configure::read('Ratchet.Connection.websocket.address'));
		$this->__ioServer = new IoServer(
			new HttpServer(
				new WsServer(
					new SessionProvider(
						new WampServer(
							new CakeWampAppServer(
								$this,
								$this->__loop,
								$this->params['verbose']
							)
						),
						new CakeWampSessionHandler(),
						array(),
						new PhpSerializeHandler()
					)
				)
			),
			$socket,
			$this->__loop
		);

		$this->__loop->run();
	}

/**
{'fraction_non_alphanumeric': 0.13560844185002247, 'fraction_numerical': 0.003592276605298608, 'mean_word_length': 4.4, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6795191', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1363, 'n_words': 314}