| 1: | <?php | 
| 2: | namespace Worldline\Acquiring\Sdk\Logging; | 
| 3: |  | 
| 4: | use Exception; | 
| 5: | use SplFileObject; | 
| 6: |  | 
| 7: |  | 
| 8: |  | 
| 9: |  | 
| 10: |  | 
| 11: |  | 
| 12: | class SplFileObjectLogger implements CommunicatorLogger | 
| 13: | { | 
| 14: |  | 
| 15: | const DATE_FORMAT_STRING = DATE_ATOM; | 
| 16: |  | 
| 17: |  | 
| 18: | private $splFileObject; | 
| 19: |  | 
| 20: |  | 
| 21: | public function __construct(SplFileObject $splFileObject) | 
| 22: | { | 
| 23: | $this->splFileObject = $splFileObject; | 
| 24: | } | 
| 25: |  | 
| 26: |  | 
| 27: | public function getSplFileObject() | 
| 28: | { | 
| 29: | return $this->splFileObject; | 
| 30: | } | 
| 31: |  | 
| 32: |  | 
| 33: | public function log($message) | 
| 34: | { | 
| 35: | $this->splFileObject->fwrite($this->getDatePrefix() . $message . PHP_EOL); | 
| 36: | } | 
| 37: |  | 
| 38: |  | 
| 39: | public function logException($message, Exception $exception) | 
| 40: | { | 
| 41: | $this->splFileObject->fwrite($this->getDatePrefix() . $message . PHP_EOL . $exception . PHP_EOL); | 
| 42: | } | 
| 43: |  | 
| 44: |  | 
| 45: | protected function getDatePrefix() | 
| 46: | { | 
| 47: | return date(static::DATE_FORMAT_STRING) . ' '; | 
| 48: | } | 
| 49: | } | 
| 50: |  |