<commit_before><?php

use Ratchet\ConnectionInterface as Conn;

class CakeWampAppServer implements Ratchet\Wamp\WampServerInterface {
    
    private $shell;
    private $loop;
    protected $connections = array();
    
    public function __construct($shell, $loop) {
        $this->shell = $shell;
        $this->loop = $loop;
        CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.construct', $this, array(
            'loop' => $this->loop,
        )));
    }
    
    public function onPublish(Conn $conn, $topic, $event, array $exclude, array $eligible) {
        $topic->broadcast($event);
        
        CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.onPublish.' . $topic->getId(), $this, array(
            'connection' => $conn,
            'topic' => $topic,
            'exclude' => $exclude,
            'eligible' => $eligible,
            'connectionData' => $this->connections[$conn->WAMP->sessionId],
        )));
    }

    public function onCall(Conn $conn, $id, $topic, array $params) {
        CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.Rpc.' . $topic->getId(), $this, array(
            'connection' => $conn,
            'id' => $id,
            'topic' => $topic,
            'params' => $params,
            'connectionData' => $this->connections[$conn->WAMP->sessionId],
        )));
    }

    public function onSubscribe(Conn $conn, $topic) {
        if (!isset($this->topics[$topic->getId()])) {
            $this->topics[$topic->getId()] = $topic;
            
            CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.onSubscribeNewTopic.' . $topic->getId(), $this, array(
                'connection' => $conn,
                'topic' => $topic,
                'connectionData' => $this->connections[$conn->WAMP->sessionId],
            )));
        }
        
        CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.onSubscribe.' . $topic->getId(), $this, array(
            'connection' => $conn,
            'topic' => $topic,
            'connectionData' => $this->connections[$conn->WAMP->sessionId],
        )));
    }
    
    public function onUnSubscribe(Conn $conn, $topic) {
        if ($this->topics[$topic->getId()]->count() > 0) {
            unset($this->topics[$topic->getId()]);
            
            CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.onUnSubscribeStaleTopic.' . $topic->getId(), $this, array(
                'connection' => $conn,
                'topic' => $topic,
                'connectionData' => $this->connections[$conn->WAMP->sessionId],<commit_msg>Storing true instead of the entire topic in the topic array *should* save memory<commit_after><?php

use Ratchet\ConnectionInterface as Conn;

class CakeWampAppServer implements Ratchet\Wamp\WampServerInterface {
    
    private $shell;
    private $loop;
    protected $connections = array();
    
    public function __construct($shell, $loop) {
        $this->shell = $shell;
        $this->loop = $loop;
        CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.construct', $this, array(
            'loop' => $this->loop,
        )));
    }
    
    public function onPublish(Conn $conn, $topic, $event, array $exclude, array $eligible) {
        $topic->broadcast($event);
        
        CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.onPublish.' . $topic->getId(), $this, array(
            'connection' => $conn,
            'topic' => $topic,
            'exclude' => $exclude,
            'eligible' => $eligible,
            'connectionData' => $this->connections[$conn->WAMP->sessionId],
        )));
    }

    public function onCall(Conn $conn, $id, $topic, array $params) {
        CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.Rpc.' . $topic->getId(), $this, array(
            'connection' => $conn,
            'id' => $id,
            'topic' => $topic,
            'params' => $params,
            'connectionData' => $this->connections[$conn->WAMP->sessionId],
        )));
    }

    public function onSubscribe(Conn $conn, $topic) {
        if (!isset($this->topics[$topic->getId()])) {
            $this->topics[$topic->getId()] = true;
            
            CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.onSubscribeNewTopic.' . $topic->getId(), $this, array(
                'connection' => $conn,
                'topic' => $topic,
                'connectionData' => $this->connections[$conn->WAMP->sessionId],
            )));
        }
        
        CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.onSubscribe.' . $topic->getId(), $this, array(
            'connection' => $conn,
            'topic' => $topic,
            'connectionData' => $this->connections[$conn->WAMP->sessionId],
        )));
    }
    
    public function onUnSubscribe(Conn $conn, $topic) {
        if (isset($this->topics[$topic->getId()]) && $topic->count() > 0) {
            unset($this->topics[$topic->getId()]);
            
            CakeEventManager::instance()->dispatch(new CakeEvent('Rachet.WampServer.onUnSubscribeStaleTopic.' . $topic->getId(), $this, array(
                'connection' => $conn,
                'topic' => $topic,
                'connectionData' => $this->connections[$conn->WAMP->sessionId],
{'fraction_non_alphanumeric': 0.17040029379361, 'fraction_numerical': 0.0003672420124862284, 'mean_word_length': 2.400124843945069, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 123, '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': '1173101', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1555, 'n_words': 273}