|
@@ -0,0 +1,51 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace DeviceBundle\EventListener;
|
|
|
|
+
|
|
|
|
+use Doctrine\ORM\Event\LifecycleEventArgs;
|
|
|
|
+use DeviceBundle\Interfaces\DeviceInterface;
|
|
|
|
+use WebserviceBundle\Services\Webservice;
|
|
|
|
+use Buzz\Message\RequestInterface as HttpRequestInterface;
|
|
|
|
+
|
|
|
|
+class DeviceListener
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @var Webservice
|
|
|
|
+ */
|
|
|
|
+ private $webservice;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @var string
|
|
|
|
+ */
|
|
|
|
+ private $devicePostUrl;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param Webservice $webservice
|
|
|
|
+ * @param string $devicePostUrl
|
|
|
|
+ */
|
|
|
|
+ public function __construct(Webservice $webservice, $devicePostUrl)
|
|
|
|
+ {
|
|
|
|
+ $this->webservice = $webservice;
|
|
|
|
+ $this->devicePostUrl = $devicePostUrl;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param LifecycleEventArgs $args
|
|
|
|
+ */
|
|
|
|
+ public function postPersist(LifecycleEventArgs $args)
|
|
|
|
+ {
|
|
|
|
+ $entity = $args->getEntity();
|
|
|
|
+ if ($entity instanceof DeviceInterface) {
|
|
|
|
+ $data = array(
|
|
|
|
+ 'deviceType' => get_class($entity),
|
|
|
|
+ 'deviceId' => $entity->getId(),
|
|
|
|
+ 'ip' => $entity->getIp(),
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ $result = $this->webservice->makeGetRequest($this->devicePostUrl, HttpRequestInterface::METHOD_POST, $data);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|