1 <?php 2 3 declare(strict_types=1); 4 5 namespace OpenSpout\Reader\ODS\Helper; 6 7 use OpenSpout\Reader\Exception\XMLProcessingException; 8 use OpenSpout\Reader\Wrapper\XMLReader; 9 10 /** 11 * @internal 12 */ 13 final class SettingsHelper 14 { 15 public const SETTINGS_XML_FILE_PATH = 'settings.xml'; 16 17 /** 18 * Definition of XML nodes name and attribute used to parse settings data. 19 */ 20 public const XML_NODE_CONFIG_ITEM = 'config:config-item'; 21 public const XML_ATTRIBUTE_CONFIG_NAME = 'config:name'; 22 public const XML_ATTRIBUTE_VALUE_ACTIVE_TABLE = 'ActiveTable'; 23 24 /** 25 * @param string $filePath Path of the file to be read 26 * 27 * @return null|string Name of the sheet that was defined as active or NULL if none found 28 */ 29 public function getActiveSheetName(string $filePath): ?string 30 { 31 $xmlReader = new XMLReader(); 32 if (false === $xmlReader->openFileInZip($filePath, self::SETTINGS_XML_FILE_PATH)) { 33 return null; 34 } 35 36 $activeSheetName = null; 37 38 try { 39 while ($xmlReader->readUntilNodeFound(self::XML_NODE_CONFIG_ITEM)) { 40 if (self::XML_ATTRIBUTE_VALUE_ACTIVE_TABLE === $xmlReader->getAttribute(self::XML_ATTRIBUTE_CONFIG_NAME)) { 41 $activeSheetName = $xmlReader->readString(); 42 43 break; 44 } 45 } 46 } catch (XMLProcessingException $exception) { // @codeCoverageIgnore 47 // do nothing 48 } 49 50 $xmlReader->close(); 51 52 return $activeSheetName; 53 } 54 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body