PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / vendor / wp-media / wp-mixpanel / src / Classes / ConsumerStrategies / FileConsumer.php

FileConsumer.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at vendor/wp-media/wp-mixpanel/src/Classes/ConsumerStrategies/FileConsumer.php

39 lines 980 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Consumes messages and writes them to a file
5 */
6 class Imagify_WPMedia_ConsumerStrategies_FileConsumer extends Imagify_WPMedia_ConsumerStrategies_AbstractConsumer {
7
8 /**
9 * @var string path to a file that we want to write the messages to
10 */
11 private $_file;
12
13
14 /**
15 * Creates a new FileConsumer and assigns properties from the $options array
16 * @param array $options
17 */
18 function __construct($options) {
19 parent::__construct($options);
20
21 // what file to write to?
22 $this->_file = isset($options['file']) ? $options['file'] : dirname(__FILE__)."/../../messages.txt";
23 }
24
25
26 /**
27 * Append $batch to a file
28 * @param array $batch
29 * @return bool
30 */
31 public function persist($batch) {
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