file = $file; $this->headers = $headers; } /** * @inheritDoc */ public function fields(): array { $content = $this->fileContent(); $headers = []; foreach ( $this->headers as $field => $regex ) { $headers[ $field ] = ''; if ( \preg_match( '/^[ \t\/*#@]*' . \preg_quote( $regex, '/' ) . ':(.*)$/mi', $content, $match ) && $match[ 1 ] ) { $headers[ $field ] = \trim( \preg_replace( '/\s*(?:\*\/|\?>).*/', '', $match[ 1 ] ) ); } } return $headers; } /** * @return string */ private function fileContent(): string { return \strval( \str_replace( "\r", "\n", $this->file->fread( 8 * 1024 ) ) ); } }