PluginProbe ʕ •ᴥ•ʔ
10Web Booster – Website speed optimization, Cache & Page Speed optimizer / trunk
10Web Booster – Website speed optimization, Cache & Page Speed optimizer vtrunk
2.33.0 2.30.5 2.30.7 2.30.9 2.31.10 2.31.8 2.32.11 2.32.21 2.32.3 2.32.4 2.32.7 2.6.31 2.6.40 2.6.42 2.6.7 2.7.37 2.7.44 2.7.47 2.8.18 2.8.19 2.8.32 2.8.34 2.8.35 2.9.23 2.9.24 2.9.25 2.9.27 v2.27.4 trunk 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.17 2.0.18 2.0.21 2.0.22 2.0.25 2.0.26 2.0.27 2.0.3 2.0.7 2.0.9 2.10.46 2.10.65 2.10.66 2.10.68 2.11.41 2.11.42 2.11.43 2.12.15 2.12.21 2.12.22 2.12.23 2.12.26 2.13.37 2.13.40 2.13.41 2.13.42 2.13.44 2.13.45 2.13.47 2.14.49 2.14.50 2.15.18 2.17.21 2.17.23 2.18.17 2.19.44 2.19.45 2.19.46 2.19.49 2.2.12 2.2.15 2.2.16 2.2.18 2.2.8 2.20.31 2.20.32 2.20.33 2.21.11 2.21.12 2.21.16 2.21.25 2.22.32 2.23.13 2.23.15 2.23.16 2.23.18 2.24.12 2.24.14 2.24.18 2.25.14 2.26.6 2.28.10 2.28.13 2.28.14 2.28.7 2.29.1 2.29.2 2.29.3 2.3.0 2.3.1 2.3.2 2.3.3 2.30.18
tenweb-speed-optimizer / vendor / enqueue / fs / FsProducer.php
tenweb-speed-optimizer / vendor / enqueue / fs Last commit date
.github 2 years ago CannotObtainLockException.php 4 years ago FsConnectionFactory.php 4 years ago FsConsumer.php 4 years ago FsContext.php 4 years ago FsDestination.php 4 years ago FsMessage.php 4 years ago FsProducer.php 4 years ago LICENSE 4 years ago LegacyFilesystemLock.php 4 years ago Lock.php 4 years ago README.md 2 years ago composer.json 2 years ago
FsProducer.php
110 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Enqueue\Fs;
6
7 use Interop\Queue\Destination;
8 use Interop\Queue\Exception\DeliveryDelayNotSupportedException;
9 use Interop\Queue\Exception\InvalidDestinationException;
10 use Interop\Queue\Exception\InvalidMessageException;
11 use Interop\Queue\Exception\PriorityNotSupportedException;
12 use Interop\Queue\Message;
13 use Interop\Queue\Producer;
14 use Makasim\File\TempFile;
15
16 class FsProducer implements Producer
17 {
18 /**
19 * @var float|int|null
20 */
21 private $timeToLive;
22
23 /**
24 * @var FsContext
25 */
26 private $context;
27
28 public function __construct(FsContext $context)
29 {
30 $this->context = $context;
31 }
32
33 /**
34 * @param FsDestination $destination
35 * @param FsMessage $message
36 */
37 public function send(Destination $destination, Message $message): void
38 {
39 InvalidDestinationException::assertDestinationInstanceOf($destination, FsDestination::class);
40 InvalidMessageException::assertMessageInstanceOf($message, FsMessage::class);
41
42 $this->context->workWithFile($destination, 'a+', function (FsDestination $destination, $file) use ($message) {
43 $fileInfo = $destination->getFileInfo();
44 if ($fileInfo instanceof TempFile && false == file_exists((string) $fileInfo)) {
45 return;
46 }
47
48 if (null !== $this->timeToLive) {
49 $message->setHeader('x-expire-at', microtime(true) + ($this->timeToLive / 1000));
50 }
51
52 $rawMessage = json_encode($message);
53 $rawMessage = str_replace('|{', '\|\{', $rawMessage);
54 $rawMessage = '|'.$rawMessage;
55
56 if (JSON_ERROR_NONE !== json_last_error()) {
57 throw new \InvalidArgumentException(sprintf(
58 'Could not encode value into json. Error %s and message %s',
59 json_last_error(),
60 json_last_error_msg()
61 ));
62 }
63
64 $rawMessage = str_repeat(' ', 64 - (strlen($rawMessage) % 64)).$rawMessage;
65
66 fwrite($file, $rawMessage);
67 });
68 }
69
70 public function setDeliveryDelay(int $deliveryDelay = null): Producer
71 {
72 if (null === $deliveryDelay) {
73 return $this;
74 }
75
76 throw DeliveryDelayNotSupportedException::providerDoestNotSupportIt();
77 }
78
79 public function getDeliveryDelay(): ?int
80 {
81 return null;
82 }
83
84 public function setPriority(int $priority = null): Producer
85 {
86 if (null === $priority) {
87 return $this;
88 }
89
90 throw PriorityNotSupportedException::providerDoestNotSupportIt();
91 }
92
93 public function getPriority(): ?int
94 {
95 return null;
96 }
97
98 public function setTimeToLive(int $timeToLive = null): Producer
99 {
100 $this->timeToLive = $timeToLive;
101
102 return $this;
103 }
104
105 public function getTimeToLive(): ?int
106 {
107 return null;
108 }
109 }
110