diff options
author | Kevin Decherf <kevin@kdecherf.com> | 2018-10-24 22:11:35 +0200 |
---|---|---|
committer | Kevin Decherf <kevin@kdecherf.com> | 2018-10-24 22:13:03 +0200 |
commit | 44e63667d9cf331aeedef8cb964538823c0a145d (patch) | |
tree | 1d2c0b21db6013bb07e0186f9fc004f706bbaeaa | |
parent | 5ba5e22a092068aeb12213578fd8fc4edb2399fe (diff) | |
download | wallabag-44e63667d9cf331aeedef8cb964538823c0a145d.tar.gz wallabag-44e63667d9cf331aeedef8cb964538823c0a145d.tar.zst wallabag-44e63667d9cf331aeedef8cb964538823c0a145d.zip |
updateOriginUrl: add comment blocks for the parse_url diff check
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/ContentProxy.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 92351986..a93f4a2d 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -328,6 +328,18 @@ class ContentProxy | |||
328 | $parsed_entry_url = parse_url($entry->getUrl()); | 328 | $parsed_entry_url = parse_url($entry->getUrl()); |
329 | $parsed_content_url = parse_url($url); | 329 | $parsed_content_url = parse_url($url); |
330 | 330 | ||
331 | /** | ||
332 | * The following part computes the list of part changes between two | ||
333 | * parse_url arrays. | ||
334 | * | ||
335 | * As array_diff_assoc only computes changes to go from the left array | ||
336 | * to the right one, we make two differents arrays to have both | ||
337 | * directions. We merge these two arrays and sort keys before passing | ||
338 | * the result to the switch. | ||
339 | * | ||
340 | * The resulting array gives us all changing parts between the two | ||
341 | * urls: scheme, host, path, query and/or fragment. | ||
342 | */ | ||
331 | $diff_ec = array_diff_assoc($parsed_entry_url, $parsed_content_url); | 343 | $diff_ec = array_diff_assoc($parsed_entry_url, $parsed_content_url); |
332 | $diff_ce = array_diff_assoc($parsed_content_url, $parsed_entry_url); | 344 | $diff_ce = array_diff_assoc($parsed_content_url, $parsed_entry_url); |
333 | 345 | ||
@@ -340,6 +352,17 @@ class ContentProxy | |||
340 | return false; | 352 | return false; |
341 | } | 353 | } |
342 | 354 | ||
355 | /** | ||
356 | * This switch case lets us apply different behaviors according to | ||
357 | * changing parts of urls. | ||
358 | * | ||
359 | * As $diff_keys is an array, we provide arrays as cases. ['path'] means | ||
360 | * 'only the path is different between the two urls' whereas | ||
361 | * ['fragment', 'query'] means 'only fragment and query string parts are | ||
362 | * different between the two urls'. | ||
363 | * | ||
364 | * Note that values in $diff_keys are sorted. | ||
365 | */ | ||
343 | switch ($diff_keys) { | 366 | switch ($diff_keys) { |
344 | case ['path']: | 367 | case ['path']: |
345 | if (($parsed_entry_url['path'] . '/' === $parsed_content_url['path']) // diff is trailing slash, we only replace the url of the entry | 368 | if (($parsed_entry_url['path'] . '/' === $parsed_content_url['path']) // diff is trailing slash, we only replace the url of the entry |