$conn->Session->all()
всегда пустой, чтобы я туда не писал <?php
namespace OwrBundle\Command;
use Symfony\Component\Console\{Command\Command, Input\InputInterface, Output\OutputInterface};
use Ratchet\{Server\IoServer, Http\HttpServer, WebSocket\WsServer};
use OwrBundle\Sockets\Chat;
class SocketCommand extends Command
{
protected function configure()
{
$this->setName('sockets:start-chat')
// the short description shown while running "php bin/console list"
->setHelp("Starts the chat socket demo")
// the full command description shown when running the command with
->setDescription('Starts the chat socket demo')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln([
'Chat socket',// A line
'============',// Another line
'Starting chat, open your browser.',// Empty line
]);
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Chat()
)
),
8080
);
$server->run();
}
}
<?php
namespace OwrBundle\Sockets;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Chat implements MessageComponentInterface {
protected $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn) {
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})\n";
}
public function onMessage(ConnectionInterface $from, $msg) {
$numRecv = count($this->clients) - 1;
echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
, $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');
foreach ($this->clients as $client) {
if ($from !== $client) {
// The sender is not the receiver, send to each client connected
$client->send($msg);
}
}
}
public function onClose(ConnectionInterface $conn) {
// The connection is closed, remove it, as we can no longer send it messages
$this->clients->detach($conn);
echo "Connection {$conn->resourceId} has disconnected\n";
}
public function onError(ConnectionInterface $conn, \Exception $e) {
echo "An error has occurred: {$e->getMessage()}\n";
$conn->close();
}
}
$dbParams = array(
'driver' => DB_DRIVER,
'user' => DB_USER,
'password' => DB_PASS,
'dbname' => DB_NAME,
'host' => DB_HOST
);
$config = Setup::createAnnotationMetadataConfiguration(array(APP_DIR."/Model"), APP_DEV, null, null, false);
$entityManager = EntityManager::create($dbParams, $config);
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
$container
->register('doctrine.setup')
->addArgument(array(
array(APP_DIR."/Model"),
APP_DEV,
null,
null,
false
))
->setFactory(array(Doctrine\ORM\Tools\Setup::class, 'createAnnotationMetadataConfiguration'));
$container
->register('doctrine')
->addArgument(array(
'driver' => DB_DRIVER,
'user' => DB_USER,
'password' => DB_PASS,
'dbname' => DB_NAME,
'host' => DB_HOST
))
->addArgument(new Reference('doctrine.setup'))
->setFactory(array(Doctrine\ORM\EntityManager::class, 'create'));
Notice: Array to string conversion in /Applications/MAMP PRO/site/owl-dev/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php on line 103
Fatal error: Uncaught Doctrine\ORM\Mapping\MappingException: Class "Model\CountryModel" is not a valid entity or mapped super class. in /Applications/MAMP PRO/site/owl-dev/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php on line 346
$container
->register('doctrine.cache', '\Doctrine\Common\Cache\MemcachedCache')
->setPublic(false)
->addMethodCall('setMemcached', array(new Reference('memcached')))
->addMethodCall('save', array('cache_id', 'my_data'));
$container
->register('doctrine.setup')
->addArgument(array(
array(APP_DIR."/Model"),
APP_DEV,
null,
null,
false
))
->setFactory(array(Doctrine\ORM\Tools\Setup::class, 'createAnnotationMetadataConfiguration'));
$container
->register('doctrine')
->addArgument(array(
'driver' => DB_DRIVER,
'user' => DB_USER,
'password' => DB_PASS,
'dbname' => DB_NAME,
'host' => DB_HOST
))
->addArgument(new Reference('doctrine.setup'))
->setFactory(array(Doctrine\ORM\EntityManager::class, 'create'));