registerNamespace('t', 'http://schemas.microsoft.com/windows/2004/02/mit/task'); $nodes = $xpath->query('/t:Task/t:Actions/t:Exec/t:Command'); $actions = $xpath->query('/t:Task/t:Actions/*'); $command = $nodes === false ? null : $nodes->item(0); if ($actions === false || $nodes === false || $actions->length !== 1 || $nodes->length !== 1 || ! $command instanceof DOMElement || $command->textContent !== $old) { throw new LogicException('DEADLINE_TASK_GUI_ACTION_MISMATCH'); } $command->nodeValue = $new; $output = $document->saveXML(); if (! is_string($output)) { throw new LogicException('DEADLINE_TASK_GUI_XML'); } return $output; } public static function assertConserved(string $before, string $after, string $old, string $new): void { if (self::canonical(self::replacement($before, $old, $new)) !== self::canonical($after)) { throw new LogicException('DEADLINE_TASK_GUI_UNRELATED_DEFINITION_CHANGE'); } } public static function canonical(string $xml): string { $document = WindowsTaskXml::parse($xml); $xpath = new DOMXPath($document); $blanks = $xpath->query('//text()[normalize-space(.)=""]'); if ($blanks === false) { throw new LogicException('DEADLINE_TASK_GUI_XML'); } foreach ($blanks as $blank) { if ($blank instanceof DOMText && $blank->parentNode !== null) { $blank->parentNode->removeChild($blank); } } $canonical = $document->documentElement->C14N(); if (! is_string($canonical)) { throw new LogicException('DEADLINE_TASK_GUI_XML'); } return $canonical; } }