MediaWiki  1.28.0
RiffExtractor.php
Go to the documentation of this file.
1 <?php
26  public static function findChunksFromFile( $filename, $maxChunks = -1 ) {
27  $file = fopen( $filename, 'rb' );
28  $info = self::findChunks( $file, $maxChunks );
29  fclose( $file );
30  return $info;
31  }
32 
33  public static function findChunks( $file, $maxChunks = -1 ) {
34  $riff = fread( $file, 4 );
35  if ( $riff !== 'RIFF' ) {
36  return false;
37  }
38 
39  // Next four bytes are fileSize
40  $fileSize = fread( $file, 4 );
41  if ( !$fileSize || strlen( $fileSize ) != 4 ) {
42  return false;
43  }
44 
45  // Next four bytes are the FourCC
46  $fourCC = fread( $file, 4 );
47  if ( !$fourCC || strlen( $fourCC ) != 4 ) {
48  return false;
49  }
50 
51  // Create basic info structure
52  $info = [
53  'fileSize' => self::extractUInt32( $fileSize ),
54  'fourCC' => $fourCC,
55  'chunks' => [],
56  ];
57  $numberOfChunks = 0;
58 
59  // Find out the chunks
60  while ( !feof( $file ) && !( $numberOfChunks >= $maxChunks && $maxChunks >= 0 ) ) {
61  $chunkStart = ftell( $file );
62 
63  $chunkFourCC = fread( $file, 4 );
64  if ( !$chunkFourCC || strlen( $chunkFourCC ) != 4 ) {
65  return $info;
66  }
67 
68  $chunkSize = fread( $file, 4 );
69  if ( !$chunkSize || strlen( $chunkSize ) != 4 ) {
70  return $info;
71  }
72  $intChunkSize = self::extractUInt32( $chunkSize );
73 
74  // Add chunk info to the info structure
75  $info['chunks'][] = [
76  'fourCC' => $chunkFourCC,
77  'start' => $chunkStart,
78  'size' => $intChunkSize
79  ];
80 
81  // Uneven chunks have padding bytes
82  $padding = $intChunkSize % 2;
83  // Seek to the next chunk
84  fseek( $file, $intChunkSize + $padding, SEEK_CUR );
85 
86  }
87 
88  return $info;
89  }
90 
96  public static function extractUInt32( $string ) {
97  return unpack( 'V', $string )[1];
98  }
99 };
static findChunksFromFile($filename, $maxChunks=-1)
static findChunks($file, $maxChunks=-1)
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static extractUInt32($string)
Extract a little-endian uint32 from a 4 byte string.