1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* This file is part of the O2System Framework package.
|
4
|
|
|
*
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE
|
6
|
|
|
* file that was distributed with this source code.
|
7
|
|
|
*
|
8
|
|
|
* @author Steeve Andrian Salim
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim
|
10
|
|
|
*/
|
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------
|
13
|
|
|
|
14
|
|
|
namespace O2System\Spl\Info;
|
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------
|
17
|
|
|
|
18
|
|
|
/**
|
19
|
|
|
* Class SplFileInfo
|
20
|
|
|
*
|
21
|
|
|
* @package O2System\Spl\Info
|
22
|
|
|
*/
|
23
|
|
|
class SplFileInfo extends \SplFileInfo
|
24
|
|
|
{
|
25
|
|
|
/**
|
26
|
|
|
* SplFileInfo::$mime
|
27
|
|
|
*
|
28
|
|
|
* File mime type.
|
29
|
|
|
*
|
30
|
|
|
* @var
|
31
|
|
|
*/
|
32
|
|
|
private $mime;
|
33
|
|
|
|
34
|
|
|
/**
|
35
|
|
|
* SplFileInfo::__construct
|
36
|
|
|
*
|
37
|
|
|
* @param string $filePath File Path.
|
38
|
|
|
*/
|
39
|
|
|
public function __construct($filePath)
|
40
|
|
|
{
|
41
|
|
|
parent::__construct($filePath);
|
42
|
|
|
|
43
|
|
|
if (file_exists($filePath)) {
|
44
|
|
|
$this->mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $filePath);
|
45
|
|
|
}
|
46
|
|
|
}
|
47
|
|
|
|
48
|
|
|
public function getMime()
|
49
|
|
|
{
|
50
|
|
|
return $this->mime;
|
51
|
|
|
}
|
52
|
|
|
|
53
|
|
|
/**
|
54
|
|
|
* SplFileInfo::getFilename
|
55
|
|
|
*
|
56
|
|
|
* @return string
|
57
|
|
|
*/
|
58
|
|
|
public function getFilename()
|
59
|
|
|
{
|
60
|
|
|
return str_replace('.' . $this->getExtension(), '', parent::getFilename());
|
61
|
|
|
}
|
62
|
|
|
|
63
|
|
|
/**
|
64
|
|
|
* SplFileInfo::getBasename
|
65
|
|
|
*
|
66
|
|
|
* @param string $suffix
|
67
|
|
|
*
|
68
|
|
|
* @return string
|
69
|
|
|
*/
|
70
|
|
|
public function getBasename($suffix = null)
|
71
|
|
|
{
|
72
|
|
|
if (is_null($suffix)) {
|
73
|
|
|
return parent::getBasename();
|
74
|
|
|
}
|
75
|
|
|
|
76
|
|
|
return str_replace('.' . $this->getExtension(), '.' . trim($suffix, '.'), parent::getFilename());
|
77
|
|
|
}
|
78
|
|
|
|
79
|
|
|
/**
|
80
|
|
|
* SplFileInfo::getDirectoryInfo
|
81
|
|
|
*
|
82
|
|
|
* @return \O2System\Spl\Info\SplDirectoryInfo
|
83
|
|
|
*/
|
84
|
|
|
public function getDirectoryInfo()
|
85
|
|
|
{
|
86
|
|
|
return new SplDirectoryInfo(dirname($this->getRealPath()));
|
87
|
|
|
}
|
88
|
|
|
} |