path relative to ABSPATH => lowercase md5. * * @package Timaub\AfterHackChecklist */ namespace Timaub\AfterHackChecklist\Domain; final class CoreChecksums { /** @var string */ public $version = ''; /** @var string */ public $locale = ''; /** @var string */ public $requestedLocale = ''; /** @var array */ public $sums = array(); /** * Reads the decoded body of api.wordpress.org/core/checksums/1.0/ called WITH a locale. * Returns null for {"checksums":false} and for any other shape (the nested * per-version shape only comes back without a locale, N§A1). * * @param mixed $decoded json_decode( $body, true ). * @param string $version Version asked. * @param string $locale Locale asked in this call. * @param string $requestedLocale Site locale (equal to $locale unless this is the en_US fallback). */ public static function fromApiResponse( $decoded, string $version, string $locale, string $requestedLocale = '' ) { if ( ! is_array( $decoded ) || ! isset( $decoded['checksums'] ) || ! is_array( $decoded['checksums'] ) ) { return null; } $sums = array(); foreach ( $decoded['checksums'] as $path => $md5 ) { if ( ! is_string( $md5 ) ) { return null; } $sums[ (string) $path ] = strtolower( $md5 ); } if ( ! $sums ) { return null; } $c = new self(); $c->version = $version; $c->locale = $locale; $c->requestedLocale = '' === $requestedLocale ? $locale : $requestedLocale; $c->sums = $sums; return $c; } public function isFallback(): bool { return $this->locale !== $this->requestedLocale; } public function toArray(): array { return array( 'version' => $this->version, 'locale' => $this->locale, 'requestedLocale' => $this->requestedLocale, 'sums' => $this->sums, ); } public static function fromArray( array $a ): self { $c = new self(); $c->version = (string) $a['version']; $c->locale = (string) $a['locale']; $c->requestedLocale = isset( $a['requestedLocale'] ) ? (string) $a['requestedLocale'] : $c->locale; $c->sums = (array) $a['sums']; return $c; } }