123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace DeviceBundle\Services;
- use Buzz\Message\RequestInterface as HttpRequestInterface;
- use Monolog\Handler\AbstractProcessingHandler;
- use WebserviceBundle\Services\Webservice;
- class MonologHandler extends AbstractProcessingHandler
- {
- /**
- * @var Webservice
- */
- protected $webservice;
-
- /**
- * @var string
- */
- protected $deviceGetUrl;
- /**
- * @var string
- */
- protected $deviceLogUrl;
- /**
- * @param Webservice $webservice
- * @param string $deviceGetUrl
- * @param string $deviceLogUrl
- */
- public function __construct(Webservice $webservice, $deviceGetUrl, $deviceLogUrl)
- {
- parent::__construct();
- $this->webservice = $webservice;
- $this->deviceGetUrl = $deviceGetUrl;
- $this->deviceLogUrl = $deviceLogUrl;
- }
- /**
- * Crea un DeviceLog por REST en la app Base
- *
- * @param array $record
- */
- protected function write(array $record)
- {
- $filters = array(
- 'deviceType' => $record['context']['deviceType'],
- 'deviceId' => $record['context']['deviceId'],
- );
- $device = $this->webservice->get($this->deviceGetUrl, $filters);
- if ($device) {
- $data['device'] = $device[0]['id'];
- $data['message'] = $record['formatted'];
- $result = $this->webservice->makeRequest($this->deviceLogUrl, HttpRequestInterface::METHOD_POST, $data);
- }
- }
- }
|