PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / trunk
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution vtrunk
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / Cache_Delivery / Nginx / Writer.php

Writer.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution trunk, at src/Performance/Cache_Delivery/Nginx/Writer.php

79 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The swpsp-nginx.conf writer.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Cache_Delivery\Nginx;
11
12 use RuntimeException;
13 use SolidWP\Performance\Cache_Delivery\Contracts\Writable;
14 use SolidWP\Performance\Filesystem\Filesystem;
15 use SolidWP\Performance\Psr\Log\LoggerInterface;
16
17 /**
18 * The swpsp-nginx.conf writer.
19 *
20 * @package SolidWP\Performance
21 */
22 final class Writer implements Writable {
23
24 /**
25 * @var Nginx_Conf_File
26 */
27 private Nginx_Conf_File $nginx_conf;
28
29 /**
30 * @var Filesystem
31 */
32 private Filesystem $filesystem;
33
34 /**
35 * @var LoggerInterface
36 */
37 private LoggerInterface $logger;
38
39 /**
40 * @param Nginx_Conf_File $nginx_conf The nginx conf object.
41 * @param Filesystem $filesystem The filesystem component.
42 * @param LoggerInterface $logger The logger.
43 */
44 public function __construct(
45 Nginx_Conf_File $nginx_conf,
46 Filesystem $filesystem,
47 LoggerInterface $logger
48 ) {
49 $this->nginx_conf = $nginx_conf;
50 $this->filesystem = $filesystem;
51 $this->logger = $logger;
52 }
53
54 /**
55 * Atomically write content to the swpsp-nginx.conf file.
56 *
57 * @param string $content The content to save to the swpsp-nginx.conf file.
58 *
59 * @return bool
60 */
61 public function write( string $content ): bool {
62 try {
63 $filepath = $this->nginx_conf->get_file_path();
64 $this->filesystem->write( $filepath, $content );
65 } catch ( RuntimeException $e ) {
66 $this->logger->error(
67 'Unable to write content to swpsp-nginx.conf file',
68 [
69 'exception' => $e,
70 ]
71 );
72
73 return false;
74 }
75
76 return true;
77 }
78 }
79