Created
April 24, 2018 11:22
-
-
Save tabuna/dc5f59237f0c54897de93aa45aee261c to your computer and use it in GitHub Desktop.
Сравнение XLF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class DiffXLF | |
*/ | |
class DiffXLF | |
{ | |
/** | |
* @var array | |
*/ | |
private $first = []; | |
/** | |
* @var array | |
*/ | |
private $secondary = []; | |
/** | |
* @param $file | |
* | |
* @return array | |
*/ | |
private function load($file): array | |
{ | |
$xml = new SimpleXMLElement(file_get_contents($file)); | |
return $this->fillKeys($xml); | |
} | |
/** | |
* @param SimpleXMLElement $XMLElement | |
* | |
* @return array | |
*/ | |
private function fillKeys(SimpleXMLElement $XMLElement) | |
{ | |
foreach ($XMLElement->file->body->children() as $item) { | |
$ids[] = (string) $item->attributes()->id; | |
} | |
return $ids ?? []; | |
} | |
/** | |
* @param $first | |
* @param $secondary | |
* | |
* @return array | |
*/ | |
public function diff($first, $secondary) | |
{ | |
$this->first = $this->load($first); | |
$this->secondary = $this->load($secondary); | |
return array_merge( | |
array_diff($this->first, $this->secondary), | |
array_diff($this->secondary, $this->first) | |
); | |
} | |
} | |
$diff = new DiffXLF(); | |
$diff = $diff->diff('messages.en.xlf', 'messages.ru.xlf'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment