1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
* @package MW |
8
|
|
|
* @subpackage Media |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MW\Media; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Creates a new media object. |
17
|
|
|
* |
18
|
|
|
* @package MW |
19
|
|
|
* @subpackage Media |
20
|
|
|
*/ |
21
|
|
|
class Factory |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Creates a new media object. |
25
|
|
|
* |
26
|
|
|
* Options for the factory are: |
27
|
|
|
* - image: Associative list of image related options |
28
|
|
|
* - application: Associative list of application related options |
29
|
|
|
* |
30
|
|
|
* @param resource|string $file File resource, path to the file or file content |
31
|
|
|
* @param array $options Associative list of options for configuring the media class |
32
|
|
|
* @return \Aimeos\MW\Media\Iface Media object |
33
|
|
|
*/ |
34
|
|
|
public static function get( $file, array $options = array() ) |
35
|
|
|
{ |
36
|
|
|
$content = $file; |
37
|
|
|
$mimetype = 'application/octet-stream'; |
|
|
|
|
38
|
|
|
|
39
|
|
|
if( @is_resource( $file ) && ( $content = stream_get_contents( $file ) ) === false ) { |
40
|
|
|
throw new \Aimeos\MW\Media\Exception( sprintf( 'Unable to read from stream' ) ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if( @is_file( $file ) && ( $content = @file_get_contents( $file ) ) === false ) { |
44
|
|
|
throw new \Aimeos\MW\Media\Exception( sprintf( 'Unable to read from file "%1$s"', $file ) ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$finfo = new \finfo( FILEINFO_MIME_TYPE ); |
48
|
|
|
$mimetype = $finfo->buffer( $content ); |
49
|
|
|
$mimeparts = explode( '/', $mimetype ); |
50
|
|
|
|
51
|
|
|
switch( $mimeparts[0] ) |
52
|
|
|
{ |
53
|
|
|
case 'image': |
54
|
|
|
return new \Aimeos\MW\Media\Image\Standard( $content, $mimetype, $options ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return new \Aimeos\MW\Media\Application\Standard( $content, $mimetype, $options ); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.