123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace DeviceBundle\Services;
- use Buzz\Message\RequestInterface as HttpRequestInterface;
- use Monolog\Handler\AbstractProcessingHandler;
- use WebserviceBundle\Services\Webservice;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- class MonologHandler extends AbstractProcessingHandler
- {
- /**
- * @var Webservice
- */
- protected $webservice = null;
- /**
- * @var string
- */
- protected $deviceGetUrl = null;
- /**
- * @var string
- */
- protected $deviceLogUrl = null;
- /**
- * @var ContainerInterface
- */
- protected $serviceContainer;
- /**
- * @param ContainerInterface $serviceContainer
- */
- public function __construct(ContainerInterface $serviceContainer)
- {
- parent::__construct();
- $this->serviceContainer = $serviceContainer;
- if ($serviceContainer->has('webservice')) {
- $this->webservice = $serviceContainer->get('webservice');
- }
- if ($serviceContainer->hasParameter('remote_device_url')) {
- $this->deviceGetUrl = $serviceContainer->getParameter('remote_device_url');
- }
- if ($serviceContainer->hasParameter('remote_device_log_url')) {
- $this->deviceLogUrl = $serviceContainer->getParameter('remote_device_log_url');
- }
- }
- /**
- * Crea un DeviceLog por REST en la app Base
- *
- * @param array $record
- */
- protected function write(array $record)
- {
- try {
- $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'];
- $this->webservice->makeRequest($this->deviceLogUrl, HttpRequestInterface::METHOD_POST, $data);
- }
- } catch (\Exception $ex) {
- }
- }
- }
|