2017-03-27 10 views
-1

에서 클래스 "MyApp"를로드하려고했습니다. 심포니 2와 래칫 및 memcache를 websocket 채팅 프로젝트에 사용하여 심포니와 잘 작동하는 래칫과 제가 공식 웹 사이트의 "hello world"앱에서 테스트했습니다. 내가네임 스페이스

new Chat(new MyApp(), $this->getContainer()), 

내가이 오류를 얻을이 줄을 실행하면 문제는

Attempted to load class "MyApp" from namespace 

내 명령 줄 코드

<?php 
// myapplication/src/sandboxBundle/Command/SocketCommand.php 
// Change the namespace according to your bundle 
namespace check\roomsBundle\Command; 
use Ratchet\Session\SessionProvider; 
use Symfony\Component\HttpFoundation\Session\Storage\Handler; 
use Doctrine\Common\Cache\MemcacheCache; 
use Ratchet\App; 

use Symfony\Component\Console\Command\Command; 
use Symfony\Component\Console\Input\InputInterface; 
use Symfony\Component\Console\Output\OutputInterface; 
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler; 
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; 
// Include ratchet libs 
use Ratchet\Server\IoServer; 
use Ratchet\Http\HttpServer; 
use Ratchet\WebSocket\WsServer; 
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 
// Change the namespace according to your bundle 
use check\roomsBundle\Sockets\Chat; 
use Doctrine\ORM\EntityManager; 
use Symfony\Component\HttpFoundation\Session\Session; 

class WsServerCommand extends ContainerAwareCommand 
{ 
    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 
     ]); 
     $memcache = new \Memcache; 
     $memcache->connect('localhost', 11211); 

     $session = new SessionProvider(
      new Chat(new MyApp(), $this->getContainer()), 
      new Handler\MemcacheSessionHandler($memcache) 
     ); 

     $server = new App('localhost'); 
     $server->route('/sessDemo', $session); 
     $server->run(); 
    } 
} 

Chat.php 코드

<?php 
namespace check\roomsBundle\Sockets; 
use tuto\testBundle\Entity\Users; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\Request; 
use Ratchet\WebSocket\WsServerInterface; 
use Ratchet\MessageComponentInterface; 
use Ratchet\ConnectionInterface; 
use Symfony\Component\DependencyInjection\ContainerInterface; 
use Doctrine\ORM\EntityManager; 
use Symfony\Component\DependencyInjection\ContainerInterface as Container; 
use Symfony\Component\HttpFoundation\Session\Session; 



/** 
* This component will allow access to user data (FOSUserBundle) 
* for each connection in your Ratchet application. 
*/ 
class Chat implements MessageComponentInterface, WsServerInterface 
{ 
    /** 
    * @var \Ratchet\MessageComponentInterface 
    */ 
    protected $_app; 
    /** 
    * @var \Symfony\Component\DependencyInjection\ContainerInterface 
    */ 
    protected $_container; 
    /** 
    * @param MessageComponentInterface $app 
    * @param ContainerInterface $container 
    */ 
    public function __construct(MessageComponentInterface $app, ContainerInterface $container) 
    { 
     $this->_app = $app; 
     $this->_container = $container; 
    } 
    /** 
    * {@inheritdoc} 
    */ 
    public function onOpen(ConnectionInterface $conn) 
    { 
     if (!isset ($conn->Session) || !$conn->Session instanceof Session) { 
      throw new \RuntimeException('Session is not defined. Make sure that SessionProvider is executed before FOSUserProvider.'); 
     } 
     try { 
      $token  = unserialize($conn->Session->get('_security_main')); 
      $user  = $token->getUser(); 
      $provider = $this->_container->get('fos_user.user_provider.username'); 
      $conn->User = $provider->refreshUser($user); 
     } catch (Exception $ex) { 
      $conn->User = null; 
     } 
     return $this->_app->onOpen($conn); 
    } 

답변

1

어떤 사용의 MyApp가 아니다; 귀하의 페이지 상단에 있습니다. AppBundle \ Classes를 사용 하시겠습니까?

관련 문제