Overview

Namespaces

  • Evenement
  • None
  • PHP
  • Psr
    • Http
      • Message
  • Ratchet
    • Http
    • RFC6455
      • Handshake
      • Messaging
    • Server
    • Session
      • Serialize
      • Storage
        • Proxy
    • Wamp
    • WebSocket
  • React
    • EventLoop
      • Tick
      • Timer
    • Socket
    • Stream
  • Symfony
    • Component
      • HttpFoundation
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
      • Routing
        • Annotation
        • Exception
        • Generator
          • Dumper
        • Loader
          • DependencyInjection
        • Matcher
          • Dumper
        • Tests
          • Annotation
          • Fixtures
            • AnnotatedClasses
            • OtherAnnotatedClasses
          • Generator
            • Dumper
          • Loader
          • Matcher
            • Dumper

Classes

  • ConnContext
  • WsConnection
  • WsServer

Interfaces

  • MessageCallableInterface
  • MessageComponentInterface
  • WsServerInterface
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: namespace Ratchet\WebSocket;
 3: use Ratchet\AbstractConnectionDecorator;
 4: use Ratchet\RFC6455\Messaging\DataInterface;
 5: use Ratchet\RFC6455\Messaging\Frame;
 6: 
 7: /**
 8:  * {@inheritdoc}
 9:  * @property \StdClass $WebSocket
10:  */
11: class WsConnection extends AbstractConnectionDecorator {
12:     /**
13:      * {@inheritdoc}
14:      */
15:     public function send($msg) {
16:         if (!$this->WebSocket->closing) {
17:             if (!($msg instanceof DataInterface)) {
18:                 $msg = new Frame($msg);
19:             }
20: 
21:             $this->getConnection()->send($msg->getContents());
22:         }
23: 
24:         return $this;
25:     }
26: 
27:     /**
28:      * @param int|\Ratchet\RFC6455\Messaging\DataInterface
29:      */
30:     public function close($code = 1000) {
31:         if ($this->WebSocket->closing) {
32:             return;
33:         }
34: 
35:         if ($code instanceof DataInterface) {
36:             $this->send($code);
37:         } else {
38:             $this->send(new Frame(pack('n', $code), true, Frame::OP_CLOSE));
39:         }
40: 
41:         $this->getConnection()->close();
42: 
43:         $this->WebSocket->closing = true;
44:     }
45: }
46: 
Ratchet API documentation generated by ApiGen 2.8.0