|
@@ -5,6 +5,7 @@ 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
|
|
|
{
|
|
@@ -12,30 +13,40 @@ class MonologHandler extends AbstractProcessingHandler
|
|
|
/**
|
|
|
* @var Webservice
|
|
|
*/
|
|
|
- protected $webservice;
|
|
|
-
|
|
|
+ protected $webservice = null;
|
|
|
+
|
|
|
/**
|
|
|
* @var string
|
|
|
*/
|
|
|
- protected $deviceGetUrl;
|
|
|
+ protected $deviceGetUrl = null;
|
|
|
|
|
|
/**
|
|
|
* @var string
|
|
|
*/
|
|
|
- protected $deviceLogUrl;
|
|
|
+ protected $deviceLogUrl = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var ContainerInterface
|
|
|
+ */
|
|
|
+ protected $serviceContainer;
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * @param Webservice $webservice
|
|
|
- * @param string $deviceGetUrl
|
|
|
- * @param string $deviceLogUrl
|
|
|
+ * @param ContainerInterface $serviceContainer
|
|
|
*/
|
|
|
- public function __construct(Webservice $webservice, $deviceGetUrl, $deviceLogUrl)
|
|
|
+ public function __construct(ContainerInterface $serviceContainer)
|
|
|
{
|
|
|
parent::__construct();
|
|
|
- $this->webservice = $webservice;
|
|
|
- $this->deviceGetUrl = $deviceGetUrl;
|
|
|
- $this->deviceLogUrl = $deviceLogUrl;
|
|
|
+ $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');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -45,15 +56,19 @@ class MonologHandler extends AbstractProcessingHandler
|
|
|
*/
|
|
|
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);
|
|
|
+ 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) {
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|