Home » فروشگاه
tes, $index, 3)); return $node; case 32: $bytes = Util::read($this->fileHandle, $baseOffset + $index * 4, 4); [, $node] = unpack('N', $bytes); return $node; default: throw new InvalidDatabaseException( 'Unknown record size: ' . $this->metadata->recordSize ); } } /** * @return mixed */ private function resolveDataPointer(int $pointer) { $resolved = $pointer - $this->metadata->nodeCount + $this->metadata->searchTreeSize; if ($resolved >= $this->fileSize) { throw new InvalidDatabaseException( "The MaxMind DB file's search tree is corrupt" ); } [$data] = $this->decoder->decode($resolved); return $data; } /* * This is an extremely naive but reasonably readable implementation. There * are much faster algorithms (e.g., Boyer-Moore) for this if speed is ever * an issue, but I suspect it won't be. */ private function findMetadataStart(string $filename): int { $handle = $this->fileHandle; $fstat = fstat($handle); $fileSize = $fstat['size']; $marker = self::$METADATA_START_MARKER; $markerLength = self::$METADATA_START_MARKER_LENGTH; $minStart = $fileSize - min(self::$METADATA_MAX_SIZE, $fileSize); for ($offset = $fileSize - $markerLength; $offset >= $minStart; --$offset) { if (fseek($handle, $offset) !== 0) { break; } $value = fread($handle, $markerLength); if ($value === $marker) { return $offset + $markerLength; } } throw new InvalidDatabaseException( "Error opening database file ($filename). " . 'Is this a valid MaxMind DB file?' ); } /** * @throws InvalidArgumentException if arguments are passed to the method * @throws BadMethodCallException if the database has been closed * * @return Metadata object for the database */ public function metadata(): Metadata { if (\func_num_args()) { throw new ArgumentCountError( sprintf('%s() expects exactly 0 parameters, %d given', __METHOD__, \func_num_args()) ); } // Not technically required, but this makes it consistent with // C extension and it allows us to change our implementation later. if (!\is_resource($this->fileHandle)) { throw new BadMethodCallException( 'Attempt to read from a closed MaxMind DB.' ); } return clone $this->metadata; } /** * Closes the MaxMind DB and returns resources to the system. * * @throws Exception * if an I/O error occurs */ public function close(): void { if (\func_num_args()) { throw new ArgumentCountError( sprintf('%s() expects exactly 0 parameters, %d given', __METHOD__, \func_num_args()) ); } if (!\is_resource($this->fileHandle)) { throw new BadMethodCallException( 'Attempt to close a closed MaxMind DB.' ); } fclose($this->fileHandle); } }