| 1 |
<?php |
| 2 |
|
| 3 |
namespace ElementorDeps; |
| 4 |
|
| 5 |
require_once \dirname(__FILE__) . "/AbstractConsumer.php"; |
| 6 |
/** |
| 7 |
* Consumes messages and writes them to a file |
| 8 |
*/ |
| 9 |
class ConsumerStrategies_FileConsumer extends ConsumerStrategies_AbstractConsumer |
| 10 |
{ |
| 11 |
/** |
| 12 |
* @var string path to a file that we want to write the messages to |
| 13 |
*/ |
| 14 |
private $_file; |
| 15 |
/** |
| 16 |
* Creates a new FileConsumer and assigns properties from the $options array |
| 17 |
* @param array $options |
| 18 |
*/ |
| 19 |
function __construct($options) |
| 20 |
{ |
| 21 |
parent::__construct($options); |
| 22 |
// what file to write to? |
| 23 |
$this->_file = isset($options['file']) ? $options['file'] : \dirname(__FILE__) . "/../../messages.txt"; |
| 24 |
} |
| 25 |
/** |
| 26 |
* Append $batch to a file |
| 27 |
* @param array $batch |
| 28 |
* @return bool |
| 29 |
*/ |
| 30 |
public function persist($batch) |
| 31 |
{ |
| 32 |
if (\count($batch) > 0) { |
| 33 |
return \file_put_contents($this->_file, \json_encode($batch) . "\n", \FILE_APPEND | \LOCK_EX) !== \false; |
| 34 |
} else { |
| 35 |
return \true; |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|