|
@@ -20,21 +20,46 @@ class DeviceListener
|
|
|
*/
|
|
|
private $devicePostUrl;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ private $deviceDeletePostUrl;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @param Webservice $webservice
|
|
|
* @param string $devicePostUrl
|
|
|
+ * @param string $deviceDeletePostUrl
|
|
|
*/
|
|
|
- public function __construct(Webservice $webservice, $devicePostUrl)
|
|
|
+ public function __construct(Webservice $webservice, $devicePostUrl, $deviceDeletePostUrl)
|
|
|
{
|
|
|
$this->webservice = $webservice;
|
|
|
$this->devicePostUrl = $devicePostUrl;
|
|
|
+ $this->deviceDeletePostUrl = $deviceDeletePostUrl;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param LifecycleEventArgs $args
|
|
|
*/
|
|
|
public function postPersist(LifecycleEventArgs $args)
|
|
|
+ {
|
|
|
+ $this->send($args, $this->devicePostUrl, HttpRequestInterface::METHOD_POST);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param LifecycleEventArgs $args
|
|
|
+ */
|
|
|
+ public function preRemove(LifecycleEventArgs $args)
|
|
|
+ {
|
|
|
+ $this->send($args, $this->deviceDeletePostUrl, HttpRequestInterface::METHOD_DELETE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param LifecycleEventArgs $arg
|
|
|
+ * @param string $url
|
|
|
+ * @param string $method
|
|
|
+ */
|
|
|
+ private function send(LifecycleEventArgs $args, $url, $method)
|
|
|
{
|
|
|
$entity = $args->getEntity();
|
|
|
if ($entity instanceof DeviceInterface) {
|
|
@@ -43,8 +68,8 @@ class DeviceListener
|
|
|
'deviceId' => $entity->getId(),
|
|
|
'ip' => $entity->getIp(),
|
|
|
);
|
|
|
-
|
|
|
- $result = $this->webservice->makeGetRequest($this->devicePostUrl, HttpRequestInterface::METHOD_POST, $data);
|
|
|
+
|
|
|
+ return $this->webservice->makeGetRequest($url, $method, $data);
|
|
|
}
|
|
|
}
|
|
|
|