Uecode\Bundle\QPushBundle\Provider\FileProvider::publish PHP Method

publish() public method

public publish ( array $message, array $options = [] )
$message array
$options array
    public function publish(array $message, array $options = [])
    {
        $fileName = microtime(false);
        $fileName = str_replace(' ', '', $fileName);
        $path = substr(hash('md5', $fileName), 0, 3);
        $fs = new Filesystem();
        if (!$fs->exists($this->queuePath . DIRECTORY_SEPARATOR . $path)) {
            $fs->mkdir($this->queuePath . DIRECTORY_SEPARATOR . $path);
        }
        $fs->dumpFile($this->queuePath . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $fileName . '.json', json_encode($message));
        return $fileName;
    }

Usage Example

Esempio n. 1
0
 public function testOnMessageReceived()
 {
     $this->provider->create();
     $id = $this->provider->publish(['foo' => 'bar']);
     $path = substr(hash('md5', $id), 0, 3);
     $this->assertTrue(is_file($this->basePath . DIRECTORY_SEPARATOR . $this->queueHash . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $id . '.json'));
     $this->provider->onMessageReceived(new MessageEvent('test', $this->provider->receive()[0]));
     $this->assertFalse(is_file($this->basePath . DIRECTORY_SEPARATOR . $this->queueHash . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $id . '.json'));
 }