2021-06-27 11:19:26 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\GPodderSync\Core\EpisodeAction;
|
|
|
|
|
|
|
|
class EpisodeActionReader {
|
2021-08-23 11:30:18 +00:00
|
|
|
|
|
|
|
const EPISODEACTION_IDENTIFIER = 'EpisodeAction{';
|
|
|
|
|
2021-08-22 23:11:16 +00:00
|
|
|
/**
|
|
|
|
* @param string $episodeActionString
|
2021-08-23 11:30:18 +00:00
|
|
|
* @return EpisodeAction[]
|
2021-08-22 23:11:16 +00:00
|
|
|
*/
|
|
|
|
public function fromString(string $episodeActionString): array {
|
|
|
|
|
2021-08-23 11:30:18 +00:00
|
|
|
$episodeActions = [];
|
2021-08-22 23:11:16 +00:00
|
|
|
|
2021-08-23 11:30:18 +00:00
|
|
|
$episodeActionStrings = explode(self::EPISODEACTION_IDENTIFIER, $episodeActionString);
|
2021-08-22 23:11:16 +00:00
|
|
|
|
2021-08-23 11:30:18 +00:00
|
|
|
for($i = 1; $i < count($episodeActionStrings); $i++) {
|
2021-08-22 23:11:16 +00:00
|
|
|
|
|
|
|
preg_match(
|
|
|
|
'/EpisodeAction{(podcast=\')(?<podcast>.*?)(\', episode=\')(?<episode>.*?)(\', action=)(?<action>.*?)(, timestamp=)(?<timestamp>.*?)(, started=)(?<started>.*?)(, position=)(?<position>.*?)(, total=)(?<total>.*?)}]*/',
|
2021-08-23 11:30:18 +00:00
|
|
|
self::EPISODEACTION_IDENTIFIER . $episodeActionStrings[$i],
|
2021-08-22 23:11:16 +00:00
|
|
|
$matches
|
|
|
|
);
|
|
|
|
|
2021-08-23 11:30:18 +00:00
|
|
|
$episodeActions[] = new EpisodeAction(
|
2021-08-22 23:11:16 +00:00
|
|
|
$matches["podcast"],
|
|
|
|
$matches["episode"],
|
|
|
|
$matches["action"],
|
|
|
|
$matches["timestamp"],
|
|
|
|
(int)$matches["started"],
|
|
|
|
(int)$matches["position"],
|
|
|
|
(int)$matches["total"],
|
2021-08-23 11:30:18 +00:00
|
|
|
);
|
2021-08-22 23:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $episodeActions;
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|