Moodle PHP Documentation 4.1
Moodle 4.1.19+ (Build: 20250711) (5f47dc23ffc)
Box\Spout\Reader\XLSX\Manager\SharedStringsManager Class Reference

Public Member Functions

 __construct ( $filePath, $tempFolder, $workbookRelationshipsManager, $entityFactory, $helperFactory, $cachingStrategyFactory)
 
 cleanup ()
 Destroys the cache, freeing memory and removing any created artifacts.
 
 extractSharedStrings ()
 Builds an in-memory array containing all the shared strings of the sheet.
 
 getStringAtIndex ($sharedStringIndex)
 Returns the shared string at the given index, using the previously chosen caching strategy.
 
 hasSharedStrings ()
 Returns whether the XLSX file contains a shared strings XML file.
 

Public Attributes

const XML_ATTRIBUTE_COUNT = 'count'
 Definition of XML attributes used to parse data.
 
const XML_ATTRIBUTE_UNIQUE_COUNT = 'uniqueCount'
 
const XML_ATTRIBUTE_VALUE_PRESERVE = 'preserve'
 
const XML_ATTRIBUTE_XML_SPACE = 'xml:space'
 
const XML_NODE_R = 'r'
 
const XML_NODE_SI = 'si'
 
const XML_NODE_SST = 'sst'
 Definition of XML nodes names used to parse data.
 
const XML_NODE_T = 't'
 

Protected Member Functions

 getBestSharedStringsCachingStrategy ($sharedStringsUniqueCount)
 Returns the best shared strings caching strategy.
 
 getSharedStringsUniqueCount ($xmlReader)
 Returns the shared strings unique count, as specified in <sst> tag.
 
 processSharedStringsItem ($xmlReader, $sharedStringIndex)
 Processes the shared strings item XML node which the given XML reader is positioned on.
 
 shouldExtractTextNodeValue ($textNode)
 Not all text nodes' values must be extracted.
 
 shouldPreserveWhitespace ($textNode)
 If the text node has the attribute 'xml:space="preserve"', then preserve whitespace.
 

Protected Attributes

CachingStrategyInterface $cachingStrategy
 The best caching strategy for storing shared strings.
 
CachingStrategyFactory $cachingStrategyFactory
 Factory to create shared strings caching strategies.
 
InternalEntityFactory $entityFactory
 Factory to create entities.
 
string $filePath
 Path of the XLSX file being read.
 
HelperFactory $helperFactory
 Factory to create helpers.
 
string $tempFolder
 Temporary folder where the temporary files to store shared strings will be stored.
 
WorkbookRelationshipsManager $workbookRelationshipsManager
 Helps retrieving workbook relationships.
 

Constructor & Destructor Documentation

◆ __construct()

Box\Spout\Reader\XLSX\Manager\SharedStringsManager::__construct ( $filePath,
$tempFolder,
$workbookRelationshipsManager,
$entityFactory,
$helperFactory,
$cachingStrategyFactory )
Parameters
string$filePathPath of the XLSX file being read
string$tempFolderTemporary folder where the temporary files to store shared strings will be stored
WorkbookRelationshipsManager$workbookRelationshipsManagerHelps retrieving workbook relationships
InternalEntityFactory$entityFactoryFactory to create entities
HelperFactory$helperFactoryFactory to create helpers
CachingStrategyFactory$cachingStrategyFactoryFactory to create shared strings caching strategies

Member Function Documentation

◆ cleanup()

Box\Spout\Reader\XLSX\Manager\SharedStringsManager::cleanup ( )

Destroys the cache, freeing memory and removing any created artifacts.

Return values
void

◆ extractSharedStrings()

Box\Spout\Reader\XLSX\Manager\SharedStringsManager::extractSharedStrings ( )

Builds an in-memory array containing all the shared strings of the sheet.

All the strings are stored in a XML file, located at 'xl/sharedStrings.xml'. It is then accessed by the sheet data, via the string index in the built table.

More documentation available here: http://msdn.microsoft.com/en-us/library/office/gg278314.aspx

The XML file can be really big with sheets containing a lot of data. That is why we need to use a XML reader that provides streaming like the XMLReader library.

Exceptions
Box\Spout\Common\Exception\IOExceptionIf shared strings XML file can't be read
Return values
void

◆ getBestSharedStringsCachingStrategy()

Box\Spout\Reader\XLSX\Manager\SharedStringsManager::getBestSharedStringsCachingStrategy ( $sharedStringsUniqueCount)
protected

Returns the best shared strings caching strategy.

Parameters
int | null$sharedStringsUniqueCountNumber of unique shared strings (NULL if unknown)
Return values
CachingStrategyInterface

◆ getSharedStringsUniqueCount()

Box\Spout\Reader\XLSX\Manager\SharedStringsManager::getSharedStringsUniqueCount ( $xmlReader)
protected

Returns the shared strings unique count, as specified in <sst> tag.

Parameters
Box\Spout\Reader\Wrapper\XMLReader$xmlReaderXMLReader instance
Exceptions
Box\Spout\Common\Exception\IOExceptionIf sharedStrings.xml is invalid and can't be read
Return values
int|nullNumber of unique shared strings in the sharedStrings.xml file

◆ getStringAtIndex()

Box\Spout\Reader\XLSX\Manager\SharedStringsManager::getStringAtIndex ( $sharedStringIndex)

Returns the shared string at the given index, using the previously chosen caching strategy.

Parameters
int$sharedStringIndexIndex of the shared string in the sharedStrings.xml file
Exceptions
Box\Spout\Reader\Exception\SharedStringNotFoundExceptionIf no shared string found for the given index
Return values
stringThe shared string at the given index

◆ hasSharedStrings()

Box\Spout\Reader\XLSX\Manager\SharedStringsManager::hasSharedStrings ( )

Returns whether the XLSX file contains a shared strings XML file.

Return values
bool

◆ processSharedStringsItem()

Box\Spout\Reader\XLSX\Manager\SharedStringsManager::processSharedStringsItem ( $xmlReader,
$sharedStringIndex )
protected

Processes the shared strings item XML node which the given XML reader is positioned on.

Parameters
Box\Spout\Reader\Wrapper\XMLReader$xmlReaderXML Reader positioned on a "<si>" node
int$sharedStringIndexIndex of the processed shared strings item
Return values
void

◆ shouldExtractTextNodeValue()

Box\Spout\Reader\XLSX\Manager\SharedStringsManager::shouldExtractTextNodeValue ( $textNode)
protected

Not all text nodes' values must be extracted.

Some text nodes are part of a node describing the pronunciation for instance. We'll only consider the nodes whose parents are "<si>" or "<r>".

Parameters
DOMElement$textNodeText node to check
Return values
boolWhether the given text node's value must be extracted

◆ shouldPreserveWhitespace()

Box\Spout\Reader\XLSX\Manager\SharedStringsManager::shouldPreserveWhitespace ( $textNode)
protected

If the text node has the attribute 'xml:space="preserve"', then preserve whitespace.

Parameters
DOMElement$textNodeThe text node element (<t>) whose whitespace may be preserved
Return values
boolWhether whitespace should be preserved

The documentation for this class was generated from the following file: