Completed
Pull Request — master (#72)
by
unknown
11:14
created
Classes/Service/SvgStoreService.php 2 patches
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -12,193 +12,193 @@
 block discarded – undo
12 12
  */
13 13
 class SvgStoreService implements SingletonInterface
14 14
 {
15
-    /**
16
-     * SVG-Sprite storage DIR.
17
-     *
18
-     * @var string
19
-     */
20
-    protected $outputDir = '/typo3temp/assets/svg/'; // fallback
21
-
22
-    public function __construct()
23
-    {
24
-        #$this->styl = []; # https://stackoverflow.com/questions/39583880/external-svg-fails-to-apply-internal-css
25
-        #$this->defs = []; # https://bugs.chromium.org/p/chromium/issues/detail?id=751733#c14
26
-        $this->svgs = [];
27
-
28
-        $this->sitePath = \TYPO3\CMS\Core\Core\Environment::getPublicPath(); // [^/]$
29
-
30
-        if (isset($GLOBALS['TSFE']->config['config']['svgstore.']['outputDir']) && !empty($GLOBALS['TSFE']->config['config']['svgstore.']['outputDir'])) {
31
-            $this->outputDir = '/typo3temp/'.$GLOBALS['TSFE']->config['config']['svgstore.']['outputDir']; // TODO; please beautify
32
-        }
33
-
34
-        $this->connPool = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class);
35
-        $this->svgCache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('svgstore');
36
-    }
37
-
38
-    public function process(string $html): string
39
-    {
40
-        $this->spritePath = $this->svgCache->get('spritePath');
41
-        $this->svgFileArr = $this->svgCache->get('svgFileArr');
42
-
43
-        if (empty($this->spritePath) && !$this->populateCache()) {
44
-            throw new \Exception('could not write file: '.$this->sitePath.$this->spritePath);
45
-        }
46
-
47
-        if (!file_exists($this->sitePath.$this->spritePath)) {
48
-            throw new \Exception('file does not exists: '.$this->sitePath.$this->spritePath);
49
-        }
50
-
51
-        if (!preg_match('/(?<head>.+?<\/head>)(?<body>.+)/s', $html, $html) && 5 == \count($html)) {
52
-            throw new \Exception('fix HTML!');
53
-        }
54
-
55
-        // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attributes
56
-        $html['body'] = preg_replace_callback('/<img(?<pre>[^>]*)src="(?<src>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>/s', function (array $matches): string { // ^[/]
57
-            if (!isset($this->svgFileArr[$matches['src']])) { // check usage
58
-                return $matches[0];
59
-            }
60
-            $attr = preg_replace('/\s(?:alt|ismap|loading|title|sizes|srcset|usemap)="[^"]*"/', '', $matches['pre'].$matches['post']); // cleanup
61
-
62
-            return sprintf('<svg%s %s><use href="%s#%s"/></svg>', $this->svgFileArr[$matches['src']]['attr'], $attr, $this->spritePath, $this->convertFilePath($matches['src']));
63
-        }, $html['body']);
64
-
65
-        // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attributes
66
-        $html['body'] = preg_replace_callback('/<object(?<pre>[^>]*)data="(?<data>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>(?:<\/object>)/s', function (array $matches): string { // ^[/]
67
-            if (!isset($this->svgFileArr[$matches['data']])) { // check usage
68
-                return $matches[0];
69
-            }
70
-            $attr = preg_replace('/\s(?:form|name|type|usemap)="[^"]*"/', '', $matches['pre'].$matches['post']); // cleanup
71
-
72
-            return sprintf('<svg%s %s><use href="%s#%s"/></svg>', $this->svgFileArr[$matches['src']]['attr'], $attr, $this->spritePath, $this->convertFilePath($matches['data']));
73
-        }, $html['body']);
74
-
75
-        return $html['head'].$html['body'];
76
-    }
77
-
78
-    private function convertFilePath(string $path): string
79
-    {
80
-        return preg_replace('/.svg$|[^\w\-]/', '', str_replace('/', '-', ltrim($path, '/'))); // ^[^/]
81
-    }
82
-
83
-    private function addFileToSpriteArr(string $hash, string $path): ?array
84
-    {
85
-        if (1 === preg_match('/;base64/', $svg = file_get_contents($this->sitePath.$path))) { // noop!
86
-            return null;
87
-        }
88
-
89
-        if (1 === preg_match('/<(?:style|defs|url\()/', $svg)) {
90
-            return null;# check links @ __construct
91
-        }
92
-
93
-        $svg = preg_replace('/<\/svg>.*|xlink:|\s(?:(?:width|height|version|xmlns)|(?:[a-z\-]+\:[a-z\-]+))="[^"]*"/s', '', $svg); // clean !?: \s+(?<atr>[\w\-]+)=["\'](?<val>[^"\']+)["\']
94
-
95
-        #$svg = preg_replace('/((?:id|class)=")/', '$1'.$hash.'__', $svg); // extend  IDs
96
-        #$svg = preg_replace('/(href="|url\()#/', '$1#'.$hash.'__', $svg); // recover IDs
97
-
98
-        #$svg = preg_replace_callback('/<style[^>]*>(?<styl>.+?)<\/style>|<defs[^>]*>(?<defs>.+?)<\/defs>/s', function(array $matches) use($hash): string {
99
-        #    if(isset($matches['styl']))
100
-        #    {
101
-        #        $this->styl[] = preg_replace('/\s*(\.|#){1}(.+?)\s*\{/', '$1'.$hash.'__$2{', $matches['styl']); // patch CSS # https://mathiasbynens.be/notes/css-escapes
102
-        #    }
103
-        #    if(isset($matches['defs']))
104
-        #    {
105
-        #        $this->defs[] = trim($matches['defs']);
106
-        #    }
107
-        #    return '';
108
-        #}, $svg);
109
-
110
-        $this->svgs[] = preg_replace('/.*<svg((?:(?!id=)[^>])+)(?:id="[^"]*")?([^>]*>)/s', 'id="'.$this->convertFilePath($path).'"$1$2', $svg, 1); // change ID;
111
-
112
-        return preg_match('/\s+viewBox="\s*([+-]?[\d\.]+(?:\s+[+-]?[\d\.]+){3})\s*"/', $svg, $match) ? ['attr' => ' viewBox="'.preg_replace('/\s+/', ' ', $match[1]).'"', 'hash' => $hash] : null;
113
-    }
114
-
115
-    private function populateCache(): bool
116
-    {
117
-        $storageArr = $this->getStorageArrayFromDB();
118
-        $svgFileArr = $this->getSvgFilesArrayFromDB(array_keys($storageArr));
119
-
120
-        $this->svgFileArr = [];
121
-        foreach ($svgFileArr as $index => $row) {
122
-            if (!$this->svgFileArr[($row['path'] = '/'.$storageArr[$row['storage']].$row['identifier'])] = $this->addFileToSpriteArr($row['sha1'], $row['path'])) { // ^[/]
123
-                unset($this->svgFileArr[$row['path']]);
124
-            }
125
-        }
126
-
127
-        $svg = preg_replace_callback(
128
-            '/<use(?<pre>.*?)(?:xlink:)?href="(?<href>\/.+?\.svg)#[^"]+"(?<post>.*?)[\s\/]*>(?:<\/use>)?/s',
129
-            function (array $matches): string {
130
-                return sprintf('<use%s href="#%s"/>', $matches['pre'].$matches['post'], $this->convertFilePath($matches['href']));
131
-            },
132
-            '<svg xmlns="http://www.w3.org/2000/svg">'
133
-            #."\n<style>\n".implode("\n", $this->styl)."\n</style>"
134
-            #."\n<defs>\n".implode("\n", $this->defs)."\n</defs>"
135
-            ."\n<symbol ".implode("</symbol>\n<symbol ", $this->svgs)."</symbol>\n"
136
-            .'</svg>'
137
-        );
138
-
139
-        #unset($this->styl); // save MEM
140
-        #unset($this->defs); // save MEM
141
-        unset($this->svgs); // save MEM
142
-
143
-        if (\is_int($var = $GLOBALS['TSFE']->config['config']['sourceopt.']['formatHtml']) && 1 == $var) {
144
-            $svg = preg_replace('/[\n\r\t\v\0]|\s{2,}/', '', $svg);
145
-        }
146
-
147
-        $svg = preg_replace('/<([a-z]+)\s*(\/|>\s*<\/\1)>\s*/i', '', $svg); // remove emtpy
148
-        $svg = preg_replace('/<((circle|ellipse|line|path|polygon|polyline|rect|stop|use)\s[^>]+?)\s*>\s*<\/\2>/', '<$1/>', $svg); // shorten/minify
149
-
150
-        if (!is_dir($this->sitePath.$this->outputDir)) {
151
-            GeneralUtility::mkdir_deep($this->sitePath.$this->outputDir);
152
-        }
153
-
154
-        $this->spritePath = $this->outputDir.hash('sha1', serialize($this->svgFileArr)).'.svg';
155
-        if (false === file_put_contents($this->sitePath.$this->spritePath, $svg)) {
156
-            return false;
157
-        }
158
-        unset($svg); // save MEM
159
-
160
-        $this->svgCache->set('svgFileArr', $this->svgFileArr);
161
-        $this->svgCache->set('spritePath', $this->spritePath);
162
-
163
-        return true;
164
-    }
165
-
166
-    private function getStorageArrayFromDB(): array
167
-    {
168
-        $storageResources = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class)->findAll();
169
-        foreach ($storageResources as $storage) {
170
-            if ('relative' == $storage->getConfiguration()['pathType']) {
171
-                $storageResources[$storage->getUid()] = rtrim($storage->getConfiguration()['basePath'], '/'); // [^/]$
172
-            }
173
-        }
174
-        unset($storageResources[0]); // keep!
175
-
176
-        return $storageResources;
177
-    }
178
-
179
-    private function getSvgFilesArrayFromDB(array $storageIds): array
180
-    {
181
-        return ($queryBuilder = $this->connPool->getQueryBuilderForTable('sys_file'))
182
-            ->select('sys_file.storage', 'sys_file.identifier', 'sys_file.sha1')
183
-            ->from('sys_file')
184
-            ->innerJoin(
185
-                'sys_file',
186
-                'sys_file_reference',
187
-                'sys_file_reference',
188
-                $queryBuilder->expr()->eq(
189
-                    'sys_file_reference.uid_local',
190
-                    $queryBuilder->quoteIdentifier('sys_file.uid')
191
-                )
192
-            )
193
-            ->where(
194
-                $queryBuilder->expr()->in('sys_file.storage', $queryBuilder->createNamedParameter($storageIds, \TYPO3\CMS\Core\Database\Connection::PARAM_INT_ARRAY)),
195
-                $queryBuilder->expr()->eq('sys_file.mime_type', $queryBuilder->createNamedParameter('image/svg+xml')),
196
-                $queryBuilder->expr()->lt('sys_file.size', $queryBuilder->createNamedParameter($GLOBALS['TSFE']->config['config']['svgstore.']['fileSize'])),
197
-            )
198
-            ->groupBy('sys_file.uid')
199
-            ->orderBy('sys_file.uid')
200
-            ->execute()
201
-            ->fetchAll() // TODO; use stdClass
202
-        ;
203
-    }
15
+	/**
16
+	 * SVG-Sprite storage DIR.
17
+	 *
18
+	 * @var string
19
+	 */
20
+	protected $outputDir = '/typo3temp/assets/svg/'; // fallback
21
+
22
+	public function __construct()
23
+	{
24
+		#$this->styl = []; # https://stackoverflow.com/questions/39583880/external-svg-fails-to-apply-internal-css
25
+		#$this->defs = []; # https://bugs.chromium.org/p/chromium/issues/detail?id=751733#c14
26
+		$this->svgs = [];
27
+
28
+		$this->sitePath = \TYPO3\CMS\Core\Core\Environment::getPublicPath(); // [^/]$
29
+
30
+		if (isset($GLOBALS['TSFE']->config['config']['svgstore.']['outputDir']) && !empty($GLOBALS['TSFE']->config['config']['svgstore.']['outputDir'])) {
31
+			$this->outputDir = '/typo3temp/'.$GLOBALS['TSFE']->config['config']['svgstore.']['outputDir']; // TODO; please beautify
32
+		}
33
+
34
+		$this->connPool = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class);
35
+		$this->svgCache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('svgstore');
36
+	}
37
+
38
+	public function process(string $html): string
39
+	{
40
+		$this->spritePath = $this->svgCache->get('spritePath');
41
+		$this->svgFileArr = $this->svgCache->get('svgFileArr');
42
+
43
+		if (empty($this->spritePath) && !$this->populateCache()) {
44
+			throw new \Exception('could not write file: '.$this->sitePath.$this->spritePath);
45
+		}
46
+
47
+		if (!file_exists($this->sitePath.$this->spritePath)) {
48
+			throw new \Exception('file does not exists: '.$this->sitePath.$this->spritePath);
49
+		}
50
+
51
+		if (!preg_match('/(?<head>.+?<\/head>)(?<body>.+)/s', $html, $html) && 5 == \count($html)) {
52
+			throw new \Exception('fix HTML!');
53
+		}
54
+
55
+		// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attributes
56
+		$html['body'] = preg_replace_callback('/<img(?<pre>[^>]*)src="(?<src>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>/s', function (array $matches): string { // ^[/]
57
+			if (!isset($this->svgFileArr[$matches['src']])) { // check usage
58
+				return $matches[0];
59
+			}
60
+			$attr = preg_replace('/\s(?:alt|ismap|loading|title|sizes|srcset|usemap)="[^"]*"/', '', $matches['pre'].$matches['post']); // cleanup
61
+
62
+			return sprintf('<svg%s %s><use href="%s#%s"/></svg>', $this->svgFileArr[$matches['src']]['attr'], $attr, $this->spritePath, $this->convertFilePath($matches['src']));
63
+		}, $html['body']);
64
+
65
+		// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attributes
66
+		$html['body'] = preg_replace_callback('/<object(?<pre>[^>]*)data="(?<data>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>(?:<\/object>)/s', function (array $matches): string { // ^[/]
67
+			if (!isset($this->svgFileArr[$matches['data']])) { // check usage
68
+				return $matches[0];
69
+			}
70
+			$attr = preg_replace('/\s(?:form|name|type|usemap)="[^"]*"/', '', $matches['pre'].$matches['post']); // cleanup
71
+
72
+			return sprintf('<svg%s %s><use href="%s#%s"/></svg>', $this->svgFileArr[$matches['src']]['attr'], $attr, $this->spritePath, $this->convertFilePath($matches['data']));
73
+		}, $html['body']);
74
+
75
+		return $html['head'].$html['body'];
76
+	}
77
+
78
+	private function convertFilePath(string $path): string
79
+	{
80
+		return preg_replace('/.svg$|[^\w\-]/', '', str_replace('/', '-', ltrim($path, '/'))); // ^[^/]
81
+	}
82
+
83
+	private function addFileToSpriteArr(string $hash, string $path): ?array
84
+	{
85
+		if (1 === preg_match('/;base64/', $svg = file_get_contents($this->sitePath.$path))) { // noop!
86
+			return null;
87
+		}
88
+
89
+		if (1 === preg_match('/<(?:style|defs|url\()/', $svg)) {
90
+			return null;# check links @ __construct
91
+		}
92
+
93
+		$svg = preg_replace('/<\/svg>.*|xlink:|\s(?:(?:width|height|version|xmlns)|(?:[a-z\-]+\:[a-z\-]+))="[^"]*"/s', '', $svg); // clean !?: \s+(?<atr>[\w\-]+)=["\'](?<val>[^"\']+)["\']
94
+
95
+		#$svg = preg_replace('/((?:id|class)=")/', '$1'.$hash.'__', $svg); // extend  IDs
96
+		#$svg = preg_replace('/(href="|url\()#/', '$1#'.$hash.'__', $svg); // recover IDs
97
+
98
+		#$svg = preg_replace_callback('/<style[^>]*>(?<styl>.+?)<\/style>|<defs[^>]*>(?<defs>.+?)<\/defs>/s', function(array $matches) use($hash): string {
99
+		#    if(isset($matches['styl']))
100
+		#    {
101
+		#        $this->styl[] = preg_replace('/\s*(\.|#){1}(.+?)\s*\{/', '$1'.$hash.'__$2{', $matches['styl']); // patch CSS # https://mathiasbynens.be/notes/css-escapes
102
+		#    }
103
+		#    if(isset($matches['defs']))
104
+		#    {
105
+		#        $this->defs[] = trim($matches['defs']);
106
+		#    }
107
+		#    return '';
108
+		#}, $svg);
109
+
110
+		$this->svgs[] = preg_replace('/.*<svg((?:(?!id=)[^>])+)(?:id="[^"]*")?([^>]*>)/s', 'id="'.$this->convertFilePath($path).'"$1$2', $svg, 1); // change ID;
111
+
112
+		return preg_match('/\s+viewBox="\s*([+-]?[\d\.]+(?:\s+[+-]?[\d\.]+){3})\s*"/', $svg, $match) ? ['attr' => ' viewBox="'.preg_replace('/\s+/', ' ', $match[1]).'"', 'hash' => $hash] : null;
113
+	}
114
+
115
+	private function populateCache(): bool
116
+	{
117
+		$storageArr = $this->getStorageArrayFromDB();
118
+		$svgFileArr = $this->getSvgFilesArrayFromDB(array_keys($storageArr));
119
+
120
+		$this->svgFileArr = [];
121
+		foreach ($svgFileArr as $index => $row) {
122
+			if (!$this->svgFileArr[($row['path'] = '/'.$storageArr[$row['storage']].$row['identifier'])] = $this->addFileToSpriteArr($row['sha1'], $row['path'])) { // ^[/]
123
+				unset($this->svgFileArr[$row['path']]);
124
+			}
125
+		}
126
+
127
+		$svg = preg_replace_callback(
128
+			'/<use(?<pre>.*?)(?:xlink:)?href="(?<href>\/.+?\.svg)#[^"]+"(?<post>.*?)[\s\/]*>(?:<\/use>)?/s',
129
+			function (array $matches): string {
130
+				return sprintf('<use%s href="#%s"/>', $matches['pre'].$matches['post'], $this->convertFilePath($matches['href']));
131
+			},
132
+			'<svg xmlns="http://www.w3.org/2000/svg">'
133
+			#."\n<style>\n".implode("\n", $this->styl)."\n</style>"
134
+			#."\n<defs>\n".implode("\n", $this->defs)."\n</defs>"
135
+			."\n<symbol ".implode("</symbol>\n<symbol ", $this->svgs)."</symbol>\n"
136
+			.'</svg>'
137
+		);
138
+
139
+		#unset($this->styl); // save MEM
140
+		#unset($this->defs); // save MEM
141
+		unset($this->svgs); // save MEM
142
+
143
+		if (\is_int($var = $GLOBALS['TSFE']->config['config']['sourceopt.']['formatHtml']) && 1 == $var) {
144
+			$svg = preg_replace('/[\n\r\t\v\0]|\s{2,}/', '', $svg);
145
+		}
146
+
147
+		$svg = preg_replace('/<([a-z]+)\s*(\/|>\s*<\/\1)>\s*/i', '', $svg); // remove emtpy
148
+		$svg = preg_replace('/<((circle|ellipse|line|path|polygon|polyline|rect|stop|use)\s[^>]+?)\s*>\s*<\/\2>/', '<$1/>', $svg); // shorten/minify
149
+
150
+		if (!is_dir($this->sitePath.$this->outputDir)) {
151
+			GeneralUtility::mkdir_deep($this->sitePath.$this->outputDir);
152
+		}
153
+
154
+		$this->spritePath = $this->outputDir.hash('sha1', serialize($this->svgFileArr)).'.svg';
155
+		if (false === file_put_contents($this->sitePath.$this->spritePath, $svg)) {
156
+			return false;
157
+		}
158
+		unset($svg); // save MEM
159
+
160
+		$this->svgCache->set('svgFileArr', $this->svgFileArr);
161
+		$this->svgCache->set('spritePath', $this->spritePath);
162
+
163
+		return true;
164
+	}
165
+
166
+	private function getStorageArrayFromDB(): array
167
+	{
168
+		$storageResources = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class)->findAll();
169
+		foreach ($storageResources as $storage) {
170
+			if ('relative' == $storage->getConfiguration()['pathType']) {
171
+				$storageResources[$storage->getUid()] = rtrim($storage->getConfiguration()['basePath'], '/'); // [^/]$
172
+			}
173
+		}
174
+		unset($storageResources[0]); // keep!
175
+
176
+		return $storageResources;
177
+	}
178
+
179
+	private function getSvgFilesArrayFromDB(array $storageIds): array
180
+	{
181
+		return ($queryBuilder = $this->connPool->getQueryBuilderForTable('sys_file'))
182
+			->select('sys_file.storage', 'sys_file.identifier', 'sys_file.sha1')
183
+			->from('sys_file')
184
+			->innerJoin(
185
+				'sys_file',
186
+				'sys_file_reference',
187
+				'sys_file_reference',
188
+				$queryBuilder->expr()->eq(
189
+					'sys_file_reference.uid_local',
190
+					$queryBuilder->quoteIdentifier('sys_file.uid')
191
+				)
192
+			)
193
+			->where(
194
+				$queryBuilder->expr()->in('sys_file.storage', $queryBuilder->createNamedParameter($storageIds, \TYPO3\CMS\Core\Database\Connection::PARAM_INT_ARRAY)),
195
+				$queryBuilder->expr()->eq('sys_file.mime_type', $queryBuilder->createNamedParameter('image/svg+xml')),
196
+				$queryBuilder->expr()->lt('sys_file.size', $queryBuilder->createNamedParameter($GLOBALS['TSFE']->config['config']['svgstore.']['fileSize'])),
197
+			)
198
+			->groupBy('sys_file.uid')
199
+			->orderBy('sys_file.uid')
200
+			->execute()
201
+			->fetchAll() // TODO; use stdClass
202
+		;
203
+	}
204 204
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         }
54 54
 
55 55
         // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attributes
56
-        $html['body'] = preg_replace_callback('/<img(?<pre>[^>]*)src="(?<src>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>/s', function (array $matches): string { // ^[/]
56
+        $html['body'] = preg_replace_callback('/<img(?<pre>[^>]*)src="(?<src>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>/s', function(array $matches): string { // ^[/]
57 57
             if (!isset($this->svgFileArr[$matches['src']])) { // check usage
58 58
                 return $matches[0];
59 59
             }
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         }, $html['body']);
64 64
 
65 65
         // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attributes
66
-        $html['body'] = preg_replace_callback('/<object(?<pre>[^>]*)data="(?<data>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>(?:<\/object>)/s', function (array $matches): string { // ^[/]
66
+        $html['body'] = preg_replace_callback('/<object(?<pre>[^>]*)data="(?<data>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>(?:<\/object>)/s', function(array $matches): string { // ^[/]
67 67
             if (!isset($this->svgFileArr[$matches['data']])) { // check usage
68 68
                 return $matches[0];
69 69
             }
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
         }
88 88
 
89 89
         if (1 === preg_match('/<(?:style|defs|url\()/', $svg)) {
90
-            return null;# check links @ __construct
90
+            return null; # check links @ __construct
91 91
         }
92 92
 
93 93
         $svg = preg_replace('/<\/svg>.*|xlink:|\s(?:(?:width|height|version|xmlns)|(?:[a-z\-]+\:[a-z\-]+))="[^"]*"/s', '', $svg); // clean !?: \s+(?<atr>[\w\-]+)=["\'](?<val>[^"\']+)["\']
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 
127 127
         $svg = preg_replace_callback(
128 128
             '/<use(?<pre>.*?)(?:xlink:)?href="(?<href>\/.+?\.svg)#[^"]+"(?<post>.*?)[\s\/]*>(?:<\/use>)?/s',
129
-            function (array $matches): string {
129
+            function(array $matches): string {
130 130
                 return sprintf('<use%s href="#%s"/>', $matches['pre'].$matches['post'], $this->convertFilePath($matches['href']));
131 131
             },
132 132
             '<svg xmlns="http://www.w3.org/2000/svg">'
Please login to merge, or discard this patch.