Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/10/2017, 04:31
Minniek
 
Fecha de Ingreso: enero-2009
Mensajes: 178
Antigüedad: 15 años, 4 meses
Puntos: 2
Exclamación Symfony, acceder a variables de un servicio

buenos días,
Tengo un servicio corriendo con el siguiente comando:
Código PHP:
php app/console Project:notification:server 
con la siguiente configuracion:
Código PHP:
services:
    
project.notification:
    class: 
NotificationsBundleCommandServerCommand 

y la clase
Código PHP:
class ServerCommand extends ContainerAwareCommand {

    public 
$notification;

    
/**
     * Configure a new Command Line
     */
    
protected function configure()
    {
        
$this->setName('Project:notification:server') ->setDescription('Start the notification server.');
    }

    public function 
getNotification()
    {
        return 
$this->notification;
    }

    protected function 
execute(InputInterface $inputOutputInterface $output)
    {
        
$this->notification = new Notification();
        
$server IoServer::factory(new HttpServer(
            new 
WsServer(
                
$this->notification
            
)
        ), 
8081);

        
$server->loop->addPeriodicTimer(1, function ()  {
            
$this->notification->sendToAll('Hello');
        });

        
$server->run();
    }

Quisiera que desde otro controlador , tomar la instacia del servicio y poder acceder a la variable $notificacion pero cuando hago eso obtengo una nueva instancia del servicio, es decir, no es persistente.

Quisiera que el servicio puede ser accesible desde cualquier controlador

Alguna idea?