1: <?php
2: namespace Worldline\Acquiring\Sdk\Logging;
3:
4: use Exception;
5: use UnexpectedValueException;
6:
7: /**
8: * Class ResourceLogger
9: *
10: * @package Worldline\Acquiring\Sdk\Logging
11: */
12: class ResourceLogger implements CommunicatorLogger
13: {
14: /** */
15: const DATE_FORMAT_STRING = DATE_ATOM;
16:
17: /** @var resource */
18: protected $resource;
19:
20: /** @param resource $resource */
21: public function __construct($resource)
22: {
23: if (!is_resource($resource)) {
24: throw new UnexpectedValueException('resource expected');
25: }
26: $this->resource = $resource;
27: }
28:
29: /** @inheritdoc */
30: public function log($message)
31: {
32: fwrite($this->resource, $this->getDatePrefix() . $message . PHP_EOL);
33: }
34:
35: /** @inheritdoc */
36: public function logException($message, Exception $exception)
37: {
38: fwrite($this->resource, $this->getDatePrefix() . $message . PHP_EOL . $exception . PHP_EOL);
39: }
40:
41: /** @return string */
42: protected function getDatePrefix()
43: {
44: return date(static::DATE_FORMAT_STRING) . ' ';
45: }
46: }
47: