/** * Checks if the given JSON file can be loaded into memory * * The method tries to free enough memory if needed * * @param $filePath * @return bool */ public function checkMemoryForJsonFile($filePath) { $guessedMemory = $this->guessMemoryForJsonFile($filePath); $availableMemory = $this->getAvailableMemory(); // DebugUtility::pl('Available memory: %s', GeneralUtility::formatBytes($availableMemory)); // DebugUtility::pl('We will need about %s', GeneralUtility::formatBytes($guessedMemory)); if ($guessedMemory > $availableMemory) { // DebugUtility::pl('Please free %s bytes', GeneralUtility::formatBytes($guessedMemory - $availableMemory)); if (!$this->freeMemory($guessedMemory - $availableMemory)) { DebugUtility::pl('Required estimated memory amount of %s not available', GeneralUtility::formatBytes($guessedMemory - $availableMemory)); // throw new MemoryException(sprintf( // 'Required memory amount of %s not available', // GeneralUtility::formatBytes($guessedMemory - $availableMemory)) // ); } } }
/** * Filter the given Database by the given comparisons * * @param Database $dataCollection Database instance to filter * @param array|SplFixedArray|\SplObjectStorage $comparisonCollection Filter conditions * @param bool $pushMatchesToResult If set to TRUE the matching objects will be added to the result through calling parent::push() * @return SplFixedArray */ protected function _filterCollectionWithComparisons($dataCollection, $comparisonCollection, $pushMatchesToResult = FALSE) { if (is_array($comparisonCollection)) { $comparisonCollection = SplFixedArray::fromArray($comparisonCollection); } else { $comparisonCollection->rewind(); $comparisonCollection = SplFixedArray::fromArray(iterator_to_array($comparisonCollection)); } $comparisonCollectionCount = $comparisonCollection->getSize(); if ($comparisonCollectionCount == 0) { return $dataCollection; } $dataCollectionRaw = $dataCollection->getRawData(); $dataCollectionCount = $dataCollectionRaw->getSize(); $resultArray = new SplFixedArray($dataCollectionCount); $i = 0; $matchesIndex = 0; while ($i < $dataCollectionCount) { $j = 0; $item = $dataCollectionRaw[$i]; $comparisonResult = TRUE; while ($j < $comparisonCollectionCount) { $comparison = $comparisonCollection[$j]; if (!$comparison->perform($item)) { $comparisonResult = FALSE; } $j++; } if ($comparisonResult) { $matchingItem = $dataCollection->getObjectDataForIndexOrTransformIfNotExists($i); if ($matchingItem === NULL) { DebugUtility::var_dump($item); DebugUtility::pl('Object for index %d is NULL', $i); } $resultArray[$matchesIndex] = $matchingItem; if ($pushMatchesToResult) { parent::offsetSet($matchesIndex, $matchingItem); } $matchesIndex++; } $i++; } $resultArray->setSize($matchesIndex); return SplFixedArray::fromArray($resultArray->toArray()); }