WP Retina 2x - Version 6.3.4

Version Description

None.

Download this release

Release Info

Developer TigrouMeow
Plugin Icon 128x128 WP Retina 2x
Version 6.3.4
Comparing to
See all releases

Code changes from version 6.3.3 to 6.3.4

classes/optimize.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once(WR2X_PATH . '/vendor/autoload.php');
3
+
4
+ use Psr\Log\LoggerInterface;
5
+
6
+ class Meow_Logger implements LoggerInterface
7
+ {
8
+
9
+ public $errors = [];
10
+
11
+ public function reset() {
12
+ $this->errors = [];
13
+ }
14
+
15
+ public function log($level, $message, array $context = []): void
16
+ {
17
+ if ( is_array( $message ) ) {
18
+ $exception = $message['exception'];
19
+ $this->errors[] = $exception->getMessage();
20
+ }
21
+ else {
22
+ $this->errors[] = $message;
23
+ }
24
+ }
25
+
26
+ public function critical($message, array $context = []): void
27
+ {
28
+ $this->log( $message, $context );
29
+ }
30
+
31
+ public function error($message, array $context = []): void
32
+ {
33
+ $this->log( $message, $context );
34
+ }
35
+
36
+ public function emergency($message, array $context = []): void
37
+ {
38
+ $this->log( $message, $context );
39
+ }
40
+
41
+ public function alert($message, array $context = []): void
42
+ {
43
+ $this->log( $message, $context );
44
+ }
45
+
46
+ public function warning($message, array $context = []): void
47
+ {
48
+ $this->log( $message, $context );
49
+ }
50
+
51
+ public function notice($message, array $context = []): void
52
+ {
53
+ $this->log( $message, $context );
54
+ }
55
+
56
+ public function info($message, array $context = []): void
57
+ {
58
+ $this->log( $message, $context );
59
+ }
60
+
61
+ public function debug($message, array $context = []): void
62
+ {
63
+ $this->log( $message, $context );
64
+ }
65
+ }
66
+
67
+ class Meow_WR2X_Optimize
68
+ {
69
+
70
+ private $core;
71
+ private $optimizer;
72
+ private $postmeta_key = '_wr2x_optimize';
73
+
74
+ public function __construct($core)
75
+ {
76
+ $this->core = $core;
77
+ $this->logger = new Meow_Logger();
78
+ $factory = new \ImageOptimizer\OptimizerFactory([], $this->logger);
79
+ $this->optimizer = $factory->get();
80
+ }
81
+
82
+ public function optimize_image($media_id)
83
+ {
84
+ $meta = wp_get_attachment_metadata($media_id);
85
+ if (!isset($meta['file'])) return;
86
+
87
+ $uploads = wp_upload_dir();
88
+ if ($retina = $this->core->get_retina($uploads['basedir'] . '/' . $meta['file'])) {
89
+ $meta['retina_file'] = substr($retina, strlen($uploads['basedir']) + 1);
90
+ }
91
+
92
+ $pathinfo = pathinfo($meta['file']);
93
+ $basepath = trailingslashit($uploads['basedir']) . $pathinfo['dirname'];
94
+
95
+ // Main
96
+ $normal_file = trailingslashit($basepath) . $pathinfo['basename'];
97
+ $optimized_result = $this->optimize($normal_file);
98
+
99
+ if (!$optimized_result) {
100
+ delete_post_meta($media_id, $this->postmeta_key);
101
+ return;
102
+ }
103
+ update_post_meta($media_id, $this->postmeta_key, $optimized_result);
104
+
105
+ if (isset($meta['retina_file'])) {
106
+ $pathinfo = pathinfo($meta['retina_file']);
107
+ $retina_file = trailingslashit($basepath) . $pathinfo['basename'];
108
+ $retina_optimized_result = $this->optimize($retina_file);
109
+ }
110
+
111
+ // Thumbnails
112
+ $sizes = $this->core->get_image_sizes();
113
+ foreach ($sizes as $name => $attr) {
114
+ $normal_file = "";
115
+ $pathinfo = null;
116
+ $retina_file = null;
117
+
118
+ if (!isset($meta['sizes'][$name]) || !isset($meta['sizes'][$name]['file'])) {
119
+ continue;
120
+ }
121
+
122
+ $normal_file = trailingslashit($basepath) . $meta['sizes'][$name]['file'];
123
+ $pathinfo = pathinfo($normal_file);
124
+ $retina_file = trailingslashit($pathinfo['dirname']) . $pathinfo['filename'] . $this->core->retina_extension() . $pathinfo['extension'];
125
+ $normal_file_optimized_result = $this->optimize($normal_file);
126
+ $retina_file_optimized_result = $this->optimize($retina_file);
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Optimize the image and return the sizes before and after.
132
+ * If the image does not exist, return false.
133
+ *
134
+ * @param string $filepath
135
+ * @return array
136
+ */
137
+ private function optimize($filepath)
138
+ {
139
+
140
+
141
+ // $lines = [];
142
+ // $output = exec( 'whereis ls', $lines );
143
+ // $output = exec( 'whereis jpegtran', $lines );
144
+ // $output = exec( 'jpegtran -v -h', $lines );
145
+
146
+ if (!file_exists($filepath)) {
147
+ return false;
148
+ }
149
+ try {
150
+ $before_filesize = filesize($filepath);
151
+ $this->optimizer->optimize( $filepath );
152
+ if ( !empty( $this->logger->errors ) ) {
153
+ $this->logger->reset();
154
+ return false;
155
+ }
156
+ $after_filesize = filesize($filepath);
157
+ return ['before' => $before_filesize, 'after' => $after_filesize];
158
+ }
159
+ catch (Exception $e) {
160
+ return false;
161
+ }
162
+ }
163
+ }
vendor/composer/autoload_files.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // autoload_files.php @generated by Composer
4
+
5
+ $vendorDir = dirname(dirname(__FILE__));
6
+ $baseDir = dirname($vendorDir);
7
+
8
+ return array(
9
+ 'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
10
+ '0d59ee240a4cd96ddbb4ff164fccea4d' => $vendorDir . '/symfony/polyfill-php73/bootstrap.php',
11
+ '6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
12
+ );
vendor/psr/log/LICENSE ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2012 PHP Framework Interoperability Group
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
vendor/psr/log/Psr/Log/AbstractLogger.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Psr\Log;
4
+
5
+ /**
6
+ * This is a simple Logger implementation that other Loggers can inherit from.
7
+ *
8
+ * It simply delegates all log-level-specific methods to the `log` method to
9
+ * reduce boilerplate code that a simple Logger that does the same thing with
10
+ * messages regardless of the error level has to implement.
11
+ */
12
+ abstract class AbstractLogger implements LoggerInterface
13
+ {
14
+ /**
15
+ * System is unusable.
16
+ *
17
+ * @param string $message
18
+ * @param mixed[] $context
19
+ *
20
+ * @return void
21
+ */
22
+ public function emergency($message, array $context = array())
23
+ {
24
+ $this->log(LogLevel::EMERGENCY, $message, $context);
25
+ }
26
+
27
+ /**
28
+ * Action must be taken immediately.
29
+ *
30
+ * Example: Entire website down, database unavailable, etc. This should
31
+ * trigger the SMS alerts and wake you up.
32
+ *
33
+ * @param string $message
34
+ * @param mixed[] $context
35
+ *
36
+ * @return void
37
+ */
38
+ public function alert($message, array $context = array())
39
+ {
40
+ $this->log(LogLevel::ALERT, $message, $context);
41
+ }
42
+
43
+ /**
44
+ * Critical conditions.
45
+ *
46
+ * Example: Application component unavailable, unexpected exception.
47
+ *
48
+ * @param string $message
49
+ * @param mixed[] $context
50
+ *
51
+ * @return void
52
+ */
53
+ public function critical($message, array $context = array())
54
+ {
55
+ $this->log(LogLevel::CRITICAL, $message, $context);
56
+ }
57
+
58
+ /**
59
+ * Runtime errors that do not require immediate action but should typically
60
+ * be logged and monitored.
61
+ *
62
+ * @param string $message
63
+ * @param mixed[] $context
64
+ *
65
+ * @return void
66
+ */
67
+ public function error($message, array $context = array())
68
+ {
69
+ $this->log(LogLevel::ERROR, $message, $context);
70
+ }
71
+
72
+ /**
73
+ * Exceptional occurrences that are not errors.
74
+ *
75
+ * Example: Use of deprecated APIs, poor use of an API, undesirable things
76
+ * that are not necessarily wrong.
77
+ *
78
+ * @param string $message
79
+ * @param mixed[] $context
80
+ *
81
+ * @return void
82
+ */
83
+ public function warning($message, array $context = array())
84
+ {
85
+ $this->log(LogLevel::WARNING, $message, $context);
86
+ }
87
+
88
+ /**
89
+ * Normal but significant events.
90
+ *
91
+ * @param string $message
92
+ * @param mixed[] $context
93
+ *
94
+ * @return void
95
+ */
96
+ public function notice($message, array $context = array())
97
+ {
98
+ $this->log(LogLevel::NOTICE, $message, $context);
99
+ }
100
+
101
+ /**
102
+ * Interesting events.
103
+ *
104
+ * Example: User logs in, SQL logs.
105
+ *
106
+ * @param string $message
107
+ * @param mixed[] $context
108
+ *
109
+ * @return void
110
+ */
111
+ public function info($message, array $context = array())
112
+ {
113
+ $this->log(LogLevel::INFO, $message, $context);
114
+ }
115
+
116
+ /**
117
+ * Detailed debug information.
118
+ *
119
+ * @param string $message
120
+ * @param mixed[] $context
121
+ *
122
+ * @return void
123
+ */
124
+ public function debug($message, array $context = array())
125
+ {
126
+ $this->log(LogLevel::DEBUG, $message, $context);
127
+ }
128
+ }
vendor/psr/log/Psr/Log/InvalidArgumentException.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Psr\Log;
4
+
5
+ class InvalidArgumentException extends \InvalidArgumentException
6
+ {
7
+ }
vendor/psr/log/Psr/Log/LogLevel.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Psr\Log;
4
+
5
+ /**
6
+ * Describes log levels.
7
+ */
8
+ class LogLevel
9
+ {
10
+ const EMERGENCY = 'emergency';
11
+ const ALERT = 'alert';
12
+ const CRITICAL = 'critical';
13
+ const ERROR = 'error';
14
+ const WARNING = 'warning';
15
+ const NOTICE = 'notice';
16
+ const INFO = 'info';
17
+ const DEBUG = 'debug';
18
+ }
vendor/psr/log/Psr/Log/LoggerAwareInterface.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Psr\Log;
4
+
5
+ /**
6
+ * Describes a logger-aware instance.
7
+ */
8
+ interface LoggerAwareInterface
9
+ {
10
+ /**
11
+ * Sets a logger instance on the object.
12
+ *
13
+ * @param LoggerInterface $logger
14
+ *
15
+ * @return void
16
+ */
17
+ public function setLogger(LoggerInterface $logger);
18
+ }
vendor/psr/log/Psr/Log/LoggerAwareTrait.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Psr\Log;
4
+
5
+ /**
6
+ * Basic Implementation of LoggerAwareInterface.
7
+ */
8
+ trait LoggerAwareTrait
9
+ {
10
+ /**
11
+ * The logger instance.
12
+ *
13
+ * @var LoggerInterface|null
14
+ */
15
+ protected $logger;
16
+
17
+ /**
18
+ * Sets a logger.
19
+ *
20
+ * @param LoggerInterface $logger
21
+ */
22
+ public function setLogger(LoggerInterface $logger)
23
+ {
24
+ $this->logger = $logger;
25
+ }
26
+ }
vendor/psr/log/Psr/Log/LoggerInterface.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Psr\Log;
4
+
5
+ /**
6
+ * Describes a logger instance.
7
+ *
8
+ * The message MUST be a string or object implementing __toString().
9
+ *
10
+ * The message MAY contain placeholders in the form: {foo} where foo
11
+ * will be replaced by the context data in key "foo".
12
+ *
13
+ * The context array can contain arbitrary data. The only assumption that
14
+ * can be made by implementors is that if an Exception instance is given
15
+ * to produce a stack trace, it MUST be in a key named "exception".
16
+ *
17
+ * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
18
+ * for the full interface specification.
19
+ */
20
+ interface LoggerInterface
21
+ {
22
+ /**
23
+ * System is unusable.
24
+ *
25
+ * @param string $message
26
+ * @param mixed[] $context
27
+ *
28
+ * @return void
29
+ */
30
+ public function emergency($message, array $context = array());
31
+
32
+ /**
33
+ * Action must be taken immediately.
34
+ *
35
+ * Example: Entire website down, database unavailable, etc. This should
36
+ * trigger the SMS alerts and wake you up.
37
+ *
38
+ * @param string $message
39
+ * @param mixed[] $context
40
+ *
41
+ * @return void
42
+ */
43
+ public function alert($message, array $context = array());
44
+
45
+ /**
46
+ * Critical conditions.
47
+ *
48
+ * Example: Application component unavailable, unexpected exception.
49
+ *
50
+ * @param string $message
51
+ * @param mixed[] $context
52
+ *
53
+ * @return void
54
+ */
55
+ public function critical($message, array $context = array());
56
+
57
+ /**
58
+ * Runtime errors that do not require immediate action but should typically
59
+ * be logged and monitored.
60
+ *
61
+ * @param string $message
62
+ * @param mixed[] $context
63
+ *
64
+ * @return void
65
+ */
66
+ public function error($message, array $context = array());
67
+
68
+ /**
69
+ * Exceptional occurrences that are not errors.
70
+ *
71
+ * Example: Use of deprecated APIs, poor use of an API, undesirable things
72
+ * that are not necessarily wrong.
73
+ *
74
+ * @param string $message
75
+ * @param mixed[] $context
76
+ *
77
+ * @return void
78
+ */
79
+ public function warning($message, array $context = array());
80
+
81
+ /**
82
+ * Normal but significant events.
83
+ *
84
+ * @param string $message
85
+ * @param mixed[] $context
86
+ *
87
+ * @return void
88
+ */
89
+ public function notice($message, array $context = array());
90
+
91
+ /**
92
+ * Interesting events.
93
+ *
94
+ * Example: User logs in, SQL logs.
95
+ *
96
+ * @param string $message
97
+ * @param mixed[] $context
98
+ *
99
+ * @return void
100
+ */
101
+ public function info($message, array $context = array());
102
+
103
+ /**
104
+ * Detailed debug information.
105
+ *
106
+ * @param string $message
107
+ * @param mixed[] $context
108
+ *
109
+ * @return void
110
+ */
111
+ public function debug($message, array $context = array());
112
+
113
+ /**
114
+ * Logs with an arbitrary level.
115
+ *
116
+ * @param mixed $level
117
+ * @param string $message
118
+ * @param mixed[] $context
119
+ *
120
+ * @return void
121
+ *
122
+ * @throws \Psr\Log\InvalidArgumentException
123
+ */
124
+ public function log($level, $message, array $context = array());
125
+ }
vendor/psr/log/Psr/Log/LoggerTrait.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Psr\Log;
4
+
5
+ /**
6
+ * This is a simple Logger trait that classes unable to extend AbstractLogger
7
+ * (because they extend another class, etc) can include.
8
+ *
9
+ * It simply delegates all log-level-specific methods to the `log` method to
10
+ * reduce boilerplate code that a simple Logger that does the same thing with
11
+ * messages regardless of the error level has to implement.
12
+ */
13
+ trait LoggerTrait
14
+ {
15
+ /**
16
+ * System is unusable.
17
+ *
18
+ * @param string $message
19
+ * @param array $context
20
+ *
21
+ * @return void
22
+ */
23
+ public function emergency($message, array $context = array())
24
+ {
25
+ $this->log(LogLevel::EMERGENCY, $message, $context);
26
+ }
27
+
28
+ /**
29
+ * Action must be taken immediately.
30
+ *
31
+ * Example: Entire website down, database unavailable, etc. This should
32
+ * trigger the SMS alerts and wake you up.
33
+ *
34
+ * @param string $message
35
+ * @param array $context
36
+ *
37
+ * @return void
38
+ */
39
+ public function alert($message, array $context = array())
40
+ {
41
+ $this->log(LogLevel::ALERT, $message, $context);
42
+ }
43
+
44
+ /**
45
+ * Critical conditions.
46
+ *
47
+ * Example: Application component unavailable, unexpected exception.
48
+ *
49
+ * @param string $message
50
+ * @param array $context
51
+ *
52
+ * @return void
53
+ */
54
+ public function critical($message, array $context = array())
55
+ {
56
+ $this->log(LogLevel::CRITICAL, $message, $context);
57
+ }
58
+
59
+ /**
60
+ * Runtime errors that do not require immediate action but should typically
61
+ * be logged and monitored.
62
+ *
63
+ * @param string $message
64
+ * @param array $context
65
+ *
66
+ * @return void
67
+ */
68
+ public function error($message, array $context = array())
69
+ {
70
+ $this->log(LogLevel::ERROR, $message, $context);
71
+ }
72
+
73
+ /**
74
+ * Exceptional occurrences that are not errors.
75
+ *
76
+ * Example: Use of deprecated APIs, poor use of an API, undesirable things
77
+ * that are not necessarily wrong.
78
+ *
79
+ * @param string $message
80
+ * @param array $context
81
+ *
82
+ * @return void
83
+ */
84
+ public function warning($message, array $context = array())
85
+ {
86
+ $this->log(LogLevel::WARNING, $message, $context);
87
+ }
88
+
89
+ /**
90
+ * Normal but significant events.
91
+ *
92
+ * @param string $message
93
+ * @param array $context
94
+ *
95
+ * @return void
96
+ */
97
+ public function notice($message, array $context = array())
98
+ {
99
+ $this->log(LogLevel::NOTICE, $message, $context);
100
+ }
101
+
102
+ /**
103
+ * Interesting events.
104
+ *
105
+ * Example: User logs in, SQL logs.
106
+ *
107
+ * @param string $message
108
+ * @param array $context
109
+ *
110
+ * @return void
111
+ */
112
+ public function info($message, array $context = array())
113
+ {
114
+ $this->log(LogLevel::INFO, $message, $context);
115
+ }
116
+
117
+ /**
118
+ * Detailed debug information.
119
+ *
120
+ * @param string $message
121
+ * @param array $context
122
+ *
123
+ * @return void
124
+ */
125
+ public function debug($message, array $context = array())
126
+ {
127
+ $this->log(LogLevel::DEBUG, $message, $context);
128
+ }
129
+
130
+ /**
131
+ * Logs with an arbitrary level.
132
+ *
133
+ * @param mixed $level
134
+ * @param string $message
135
+ * @param array $context
136
+ *
137
+ * @return void
138
+ *
139
+ * @throws \Psr\Log\InvalidArgumentException
140
+ */
141
+ abstract public function log($level, $message, array $context = array());
142
+ }
vendor/psr/log/Psr/Log/NullLogger.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Psr\Log;
4
+
5
+ /**
6
+ * This Logger can be used to avoid conditional log calls.
7
+ *
8
+ * Logging should always be optional, and if no logger is provided to your
9
+ * library creating a NullLogger instance to have something to throw logs at
10
+ * is a good way to avoid littering your code with `if ($this->logger) { }`
11
+ * blocks.
12
+ */
13
+ class NullLogger extends AbstractLogger
14
+ {
15
+ /**
16
+ * Logs with an arbitrary level.
17
+ *
18
+ * @param mixed $level
19
+ * @param string $message
20
+ * @param array $context
21
+ *
22
+ * @return void
23
+ *
24
+ * @throws \Psr\Log\InvalidArgumentException
25
+ */
26
+ public function log($level, $message, array $context = array())
27
+ {
28
+ // noop
29
+ }
30
+ }
vendor/psr/log/Psr/Log/Test/DummyTest.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Psr\Log\Test;
4
+
5
+ /**
6
+ * This class is internal and does not follow the BC promise.
7
+ *
8
+ * Do NOT use this class in any way.
9
+ *
10
+ * @internal
11
+ */
12
+ class DummyTest
13
+ {
14
+ public function __toString()
15
+ {
16
+ return 'DummyTest';
17
+ }
18
+ }
vendor/psr/log/Psr/Log/Test/LoggerInterfaceTest.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Psr\Log\Test;
4
+
5
+ use Psr\Log\LoggerInterface;
6
+ use Psr\Log\LogLevel;
7
+ use PHPUnit\Framework\TestCase;
8
+
9
+ /**
10
+ * Provides a base test class for ensuring compliance with the LoggerInterface.
11
+ *
12
+ * Implementors can extend the class and implement abstract methods to run this
13
+ * as part of their test suite.
14
+ */
15
+ abstract class LoggerInterfaceTest extends TestCase
16
+ {
17
+ /**
18
+ * @return LoggerInterface
19
+ */
20
+ abstract public function getLogger();
21
+
22
+ /**
23
+ * This must return the log messages in order.
24
+ *
25
+ * The simple formatting of the messages is: "<LOG LEVEL> <MESSAGE>".
26
+ *
27
+ * Example ->error('Foo') would yield "error Foo".
28
+ *
29
+ * @return string[]
30
+ */
31
+ abstract public function getLogs();
32
+
33
+ public function testImplements()
34
+ {
35
+ $this->assertInstanceOf('Psr\Log\LoggerInterface', $this->getLogger());
36
+ }
37
+
38
+ /**
39
+ * @dataProvider provideLevelsAndMessages
40
+ */
41
+ public function testLogsAtAllLevels($level, $message)
42
+ {
43
+ $logger = $this->getLogger();
44
+ $logger->{$level}($message, array('user' => 'Bob'));
45
+ $logger->log($level, $message, array('user' => 'Bob'));
46
+
47
+ $expected = array(
48
+ $level.' message of level '.$level.' with context: Bob',
49
+ $level.' message of level '.$level.' with context: Bob',
50
+ );
51
+ $this->assertEquals($expected, $this->getLogs());
52
+ }
53
+
54
+ public function provideLevelsAndMessages()
55
+ {
56
+ return array(
57
+ LogLevel::EMERGENCY => array(LogLevel::EMERGENCY, 'message of level emergency with context: {user}'),
58
+ LogLevel::ALERT => array(LogLevel::ALERT, 'message of level alert with context: {user}'),
59
+ LogLevel::CRITICAL => array(LogLevel::CRITICAL, 'message of level critical with context: {user}'),
60
+ LogLevel::ERROR => array(LogLevel::ERROR, 'message of level error with context: {user}'),
61
+ LogLevel::WARNING => array(LogLevel::WARNING, 'message of level warning with context: {user}'),
62
+ LogLevel::NOTICE => array(LogLevel::NOTICE, 'message of level notice with context: {user}'),
63
+ LogLevel::INFO => array(LogLevel::INFO, 'message of level info with context: {user}'),
64
+ LogLevel::DEBUG => array(LogLevel::DEBUG, 'message of level debug with context: {user}'),
65
+ );
66
+ }
67
+
68
+ /**
69
+ * @expectedException \Psr\Log\InvalidArgumentException
70
+ */
71
+ public function testThrowsOnInvalidLevel()
72
+ {
73
+ $logger = $this->getLogger();
74
+ $logger->log('invalid level', 'Foo');
75
+ }
76
+
77
+ public function testContextReplacement()
78
+ {
79
+ $logger = $this->getLogger();
80
+ $logger->info('{Message {nothing} {user} {foo.bar} a}', array('user' => 'Bob', 'foo.bar' => 'Bar'));
81
+
82
+ $expected = array('info {Message {nothing} Bob Bar a}');
83
+ $this->assertEquals($expected, $this->getLogs());
84
+ }
85
+
86
+ public function testObjectCastToString()
87
+ {
88
+ if (method_exists($this, 'createPartialMock')) {
89
+ $dummy = $this->createPartialMock('Psr\Log\Test\DummyTest', array('__toString'));
90
+ } else {
91
+ $dummy = $this->getMock('Psr\Log\Test\DummyTest', array('__toString'));
92
+ }
93
+ $dummy->expects($this->once())
94
+ ->method('__toString')
95
+ ->will($this->returnValue('DUMMY'));
96
+
97
+ $this->getLogger()->warning($dummy);
98
+
99
+ $expected = array('warning DUMMY');
100
+ $this->assertEquals($expected, $this->getLogs());
101
+ }
102
+
103
+ public function testContextCanContainAnything()
104
+ {
105
+ $closed = fopen('php://memory', 'r');
106
+ fclose($closed);
107
+
108
+ $context = array(
109
+ 'bool' => true,
110
+ 'null' => null,
111
+ 'string' => 'Foo',
112
+ 'int' => 0,
113
+ 'float' => 0.5,
114
+ 'nested' => array('with object' => new DummyTest),
115
+ 'object' => new \DateTime,
116
+ 'resource' => fopen('php://memory', 'r'),
117
+ 'closed' => $closed,
118
+ );
119
+
120
+ $this->getLogger()->warning('Crazy context data', $context);
121
+
122
+ $expected = array('warning Crazy context data');
123
+ $this->assertEquals($expected, $this->getLogs());
124
+ }
125
+
126
+ public function testContextExceptionKeyCanBeExceptionOrOtherValues()
127
+ {
128
+ $logger = $this->getLogger();
129
+ $logger->warning('Random message', array('exception' => 'oops'));
130
+ $logger->critical('Uncaught Exception!', array('exception' => new \LogicException('Fail')));
131
+
132
+ $expected = array(
133
+ 'warning Random message',
134
+ 'critical Uncaught Exception!'
135
+ );
136
+ $this->assertEquals($expected, $this->getLogs());
137
+ }
138
+ }
vendor/psr/log/Psr/Log/Test/TestLogger.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Psr\Log\Test;
4
+
5
+ use Psr\Log\AbstractLogger;
6
+
7
+ /**
8
+ * Used for testing purposes.
9
+ *
10
+ * It records all records and gives you access to them for verification.
11
+ *
12
+ * @method bool hasEmergency($record)
13
+ * @method bool hasAlert($record)
14
+ * @method bool hasCritical($record)
15
+ * @method bool hasError($record)
16
+ * @method bool hasWarning($record)
17
+ * @method bool hasNotice($record)
18
+ * @method bool hasInfo($record)
19
+ * @method bool hasDebug($record)
20
+ *
21
+ * @method bool hasEmergencyRecords()
22
+ * @method bool hasAlertRecords()
23
+ * @method bool hasCriticalRecords()
24
+ * @method bool hasErrorRecords()
25
+ * @method bool hasWarningRecords()
26
+ * @method bool hasNoticeRecords()
27
+ * @method bool hasInfoRecords()
28
+ * @method bool hasDebugRecords()
29
+ *
30
+ * @method bool hasEmergencyThatContains($message)
31
+ * @method bool hasAlertThatContains($message)
32
+ * @method bool hasCriticalThatContains($message)
33
+ * @method bool hasErrorThatContains($message)
34
+ * @method bool hasWarningThatContains($message)
35
+ * @method bool hasNoticeThatContains($message)
36
+ * @method bool hasInfoThatContains($message)
37
+ * @method bool hasDebugThatContains($message)
38
+ *
39
+ * @method bool hasEmergencyThatMatches($message)
40
+ * @method bool hasAlertThatMatches($message)
41
+ * @method bool hasCriticalThatMatches($message)
42
+ * @method bool hasErrorThatMatches($message)
43
+ * @method bool hasWarningThatMatches($message)
44
+ * @method bool hasNoticeThatMatches($message)
45
+ * @method bool hasInfoThatMatches($message)
46
+ * @method bool hasDebugThatMatches($message)
47
+ *
48
+ * @method bool hasEmergencyThatPasses($message)
49
+ * @method bool hasAlertThatPasses($message)
50
+ * @method bool hasCriticalThatPasses($message)
51
+ * @method bool hasErrorThatPasses($message)
52
+ * @method bool hasWarningThatPasses($message)
53
+ * @method bool hasNoticeThatPasses($message)
54
+ * @method bool hasInfoThatPasses($message)
55
+ * @method bool hasDebugThatPasses($message)
56
+ */
57
+ class TestLogger extends AbstractLogger
58
+ {
59
+ /**
60
+ * @var array
61
+ */
62
+ public $records = [];
63
+
64
+ public $recordsByLevel = [];
65
+
66
+ /**
67
+ * @inheritdoc
68
+ */
69
+ public function log($level, $message, array $context = [])
70
+ {
71
+ $record = [
72
+ 'level' => $level,
73
+ 'message' => $message,
74
+ 'context' => $context,
75
+ ];
76
+
77
+ $this->recordsByLevel[$record['level']][] = $record;
78
+ $this->records[] = $record;
79
+ }
80
+
81
+ public function hasRecords($level)
82
+ {
83
+ return isset($this->recordsByLevel[$level]);
84
+ }
85
+
86
+ public function hasRecord($record, $level)
87
+ {
88
+ if (is_string($record)) {
89
+ $record = ['message' => $record];
90
+ }
91
+ return $this->hasRecordThatPasses(function ($rec) use ($record) {
92
+ if ($rec['message'] !== $record['message']) {
93
+ return false;
94
+ }
95
+ if (isset($record['context']) && $rec['context'] !== $record['context']) {
96
+ return false;
97
+ }
98
+ return true;
99
+ }, $level);
100
+ }
101
+
102
+ public function hasRecordThatContains($message, $level)
103
+ {
104
+ return $this->hasRecordThatPasses(function ($rec) use ($message) {
105
+ return strpos($rec['message'], $message) !== false;
106
+ }, $level);
107
+ }
108
+
109
+ public function hasRecordThatMatches($regex, $level)
110
+ {
111
+ return $this->hasRecordThatPasses(function ($rec) use ($regex) {
112
+ return preg_match($regex, $rec['message']) > 0;
113
+ }, $level);
114
+ }
115
+
116
+ public function hasRecordThatPasses(callable $predicate, $level)
117
+ {
118
+ if (!isset($this->recordsByLevel[$level])) {
119
+ return false;
120
+ }
121
+ foreach ($this->recordsByLevel[$level] as $i => $rec) {
122
+ if (call_user_func($predicate, $rec, $i)) {
123
+ return true;
124
+ }
125
+ }
126
+ return false;
127
+ }
128
+
129
+ public function __call($method, $args)
130
+ {
131
+ if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) {
132
+ $genericMethod = $matches[1] . ('Records' !== $matches[3] ? 'Record' : '') . $matches[3];
133
+ $level = strtolower($matches[2]);
134
+ if (method_exists($this, $genericMethod)) {
135
+ $args[] = $level;
136
+ return call_user_func_array([$this, $genericMethod], $args);
137
+ }
138
+ }
139
+ throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '::' . $method . '()');
140
+ }
141
+
142
+ public function reset()
143
+ {
144
+ $this->records = [];
145
+ $this->recordsByLevel = [];
146
+ }
147
+ }
vendor/psr/log/README.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ PSR Log
2
+ =======
3
+
4
+ This repository holds all interfaces/classes/traits related to
5
+ [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md).
6
+
7
+ Note that this is not a logger of its own. It is merely an interface that
8
+ describes a logger. See the specification for more details.
9
+
10
+ Installation
11
+ ------------
12
+
13
+ ```bash
14
+ composer require psr/log
15
+ ```
16
+
17
+ Usage
18
+ -----
19
+
20
+ If you need a logger, you can use the interface like this:
21
+
22
+ ```php
23
+ <?php
24
+
25
+ use Psr\Log\LoggerInterface;
26
+
27
+ class Foo
28
+ {
29
+ private $logger;
30
+
31
+ public function __construct(LoggerInterface $logger = null)
32
+ {
33
+ $this->logger = $logger;
34
+ }
35
+
36
+ public function doSomething()
37
+ {
38
+ if ($this->logger) {
39
+ $this->logger->info('Doing work');
40
+ }
41
+
42
+ try {
43
+ $this->doSomethingElse();
44
+ } catch (Exception $exception) {
45
+ $this->logger->error('Oh no!', array('exception' => $exception));
46
+ }
47
+
48
+ // do something useful
49
+ }
50
+ }
51
+ ```
52
+
53
+ You can then pick one of the implementations of the interface to get a logger.
54
+
55
+ If you want to implement the interface, you can require this package and
56
+ implement `Psr\Log\LoggerInterface` in your code. Please read the
57
+ [specification text](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md)
58
+ for details.
vendor/psr/log/composer.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "psr/log",
3
+ "description": "Common interface for logging libraries",
4
+ "keywords": ["psr", "psr-3", "log"],
5
+ "homepage": "https://github.com/php-fig/log",
6
+ "license": "MIT",
7
+ "authors": [
8
+ {
9
+ "name": "PHP-FIG",
10
+ "homepage": "https://www.php-fig.org/"
11
+ }
12
+ ],
13
+ "require": {
14
+ "php": ">=5.3.0"
15
+ },
16
+ "autoload": {
17
+ "psr-4": {
18
+ "Psr\\Log\\": "Psr/Log/"
19
+ }
20
+ },
21
+ "extra": {
22
+ "branch-alias": {
23
+ "dev-master": "1.1.x-dev"
24
+ }
25
+ }
26
+ }