Created
October 9, 2015 04:56
-
-
Save tw3eX/82027ecb97fc3b70b277 to your computer and use it in GitHub Desktop.
First
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace RedisCommunucate; | |
class Communicate implements \Push\ICommunicated { | |
private $redisClient; | |
public function __construct($redisClient){ | |
$this->redisClient = $redisClient; | |
} | |
public function communicate($projectId, $data) | |
{ | |
$toSend = array( | |
"project" => $projectId | |
); | |
$data['data'] = json_decode($data['data']); | |
$to_send = array_merge($toSend, $data); | |
$to_send['data'] = array($toSend['data']); | |
$this->redisClient->rpush("centrifugo.api", json_encode($toSend)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Centrifugo test", | |
"type": "project", | |
"description": "Centrifugo test", | |
"license": "MIT", | |
"authors": [ | |
{ | |
"name": "Valeriy Zakharov", | |
"email": "[email protected]", | |
"homepage": "http://nothing-extra.ru", | |
"role": "Developer" | |
} | |
], | |
"require": { | |
"predis/predis": "^1.0" | |
}, | |
"autoload": { | |
"classmap": [ | |
"Push", | |
"RedisCommunucate" | |
], | |
"scripts": { | |
"post-update-cmd": [ | |
"composer dump-autoload" | |
] | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Push; | |
interface ICommunicated { | |
public function communicate($projectId,$data); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Push; | |
class Push{ | |
protected $projectSecret; | |
private $projectKey; | |
private $communicate; | |
public function __construct($project, $secret, ICommunicated $communicate ) | |
{ | |
$this->setProject($project, $secret)->setCommunicate($communicate); | |
} | |
private function setProject($projectKey, $projectSecret) | |
{ | |
$this->projectKey = $projectKey; | |
$this->projectSecret = $projectSecret; | |
return $this; | |
} | |
public function setCommunicate(ICommunicated $communicate) | |
{ | |
$this->communicate = $communicate; | |
return $this; | |
} | |
public function publish($channel, $data = []) | |
{ | |
return $this->send("publish", ["channel" => $channel, "data" => $data]); | |
} | |
public function send($method, $params = []) | |
{ | |
if (empty($params)) { | |
$params = new \StdClass(); | |
} | |
$data = json_encode(["method" => $method, "params" => $params]); | |
return | |
$this->communicate | |
->communicate( | |
$this->projectKey, | |
["data" => $data] | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment