Commit 63b6c2d3 authored by Mat's avatar Mat

mise en place de la commande et du service

parent 631184cf
......@@ -16,18 +16,18 @@ services:
# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
#AppBundle\:
#resource: '../../src/AppBundle/*'
SocketBundle\:
resource: '../../src/SocketBundle/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
#exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
exclude: '../../src/SocketBundle/{Entity,Repository,Tests}'
# controllers are imported separately to make sure they're public
# and have a tag that allows actions to type-hint services
#AppBundle\Controller\:
#resource: '../../src/AppBundle/Controller'
#public: true
#tags: ['controller.service_arguments']
SocketBundle\Controller\:
resource: '../../src/SocketBundle/Controller'
public: true
tags: ['controller.service_arguments']
# add more services, or override services that need manual wiring
# AppBundle\Service\ExampleService:
......
<?php
/**
* Created by PhpStorm.
* User: mat
* Date: 2/07/18
* Time: 10:55
*/
namespace SocketBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class WsCommand extends ContainerAwareCommand
{
/**
*
*/
protected function configure()
{
$this->setName('ws:run');
$this->setDescription("Démarre le serveur Web Socket");
//parent::configure(); // pas nécessaire ici
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->write("Hello");
//parent::execute($input, $output); // pas nécessaire ici
}
}
\ No newline at end of file
......@@ -4,13 +4,16 @@ namespace SocketBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class DefaultController extends Controller
{
/**
* @Route("/")
*
* @Route("/{name}", name="homepage" )
*/
public function indexAction()
public function indexAction(AuthenticationUtils $utils, Request $request, $name)
{
return $this->render('SocketBundle:Default:index.html.twig');
}
......
<?php
/**
* Created by PhpStorm.
* User: mat
* Date: 2/07/18
* Time: 11:18
*/
namespace SocketBundle\Services;
use Ratchet\ConnectionInterface;
use Ratchet\MessageComponentInterface;
class ChatHub implements MessageComponentInterface
{
/*
* le curseur sur MessageComponentInterface -> Alt-Enter -> Add method stubs
* et hop, il ajoute tout ce qui doit être implémenté
*/
/**
* When a new connection is opened it will be passed to this method
*
* @param ConnectionInterface $conn The socket/connection that just connected to your application
* @throws \Exception
*/
function onOpen(ConnectionInterface $conn)
{
// TODO: Implement onOpen() method.
}
/**
* This is called before or after a socket is closed (depends on how it's closed). SendMessage to $conn will not result in an error if it has already been closed.
*
* @param ConnectionInterface $conn The socket/connection that is closing/closed
* @throws \Exception
*/
function onClose(ConnectionInterface $conn)
{
// TODO: Implement onClose() method.
}
/**
* If there is an error with one of the sockets, or somewhere in the application where an Exception is thrown,
* the Exception is sent back down the stack, handled by the Server and bubbled back up the application through this method
*
* @param ConnectionInterface $conn
* @param \Exception $e
* @throws \Exception
*/
function onError(ConnectionInterface $conn, \Exception $e)
{
// TODO: Implement onError() method.
}
/**
* Triggered when a client sends data through the socket
*
* @param \Ratchet\ConnectionInterface $from The socket/connection that sent the message to your application
* @param string $msg The message received
* @throws \Exception
*/
function onMessage(ConnectionInterface $from, $msg)
{
// TODO: Implement onMessage() method.
}}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment