123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?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);
- }
- }
- }
|