1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mathielen\ImportEngineBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator; |
6
|
|
|
|
7
|
|
|
class StringOrFileList extends \ArrayObject |
8
|
|
|
{ |
9
|
|
|
public function __construct(array $listOrStringsOrFiles) |
10
|
|
|
{ |
11
|
|
|
foreach ($listOrStringsOrFiles as $k => &$v) { |
12
|
|
|
if (filter_var($v, FILTER_VALIDATE_URL)) { |
13
|
|
|
//nothing |
14
|
|
|
} elseif (is_dir($v)) { |
15
|
|
|
$iterator = new RecursiveDirectoryIterator($v, \FilesystemIterator::KEY_AS_PATHNAME); |
16
|
|
|
$iterator = new \RecursiveIteratorIterator($iterator); |
17
|
|
|
|
18
|
|
|
/** @var \Symfony\Component\Finder\SplFileInfo $file */ |
19
|
|
|
foreach ($iterator as $file) { |
20
|
|
|
if (is_file($file)) { |
21
|
|
|
$listOrStringsOrFiles[$file->getRelativePathname()] = $file; |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
unset($listOrStringsOrFiles[$k]); |
26
|
|
|
} elseif (is_file($v)) { |
27
|
|
|
$v = new \SplFileInfo($v); |
28
|
|
|
} else { |
29
|
|
|
throw new \RuntimeException("Unknown value type $v"); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
parent::__construct($listOrStringsOrFiles); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function offsetGet($offset) |
37
|
|
|
{ |
38
|
|
|
//offset could be myfile.sql?targetconnection |
39
|
|
|
$url = parse_url($offset); |
40
|
|
|
$offset = $url['path']; |
41
|
|
|
|
42
|
|
|
if (!parent::offsetExists($offset)) { |
|
|
|
|
43
|
|
|
return $this->checkStreamWrapper($offset); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$v = parent::offsetGet($offset); |
47
|
|
|
if ($v instanceof \SplFileInfo) { |
48
|
|
|
return file_get_contents($v); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $v; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function checkStreamWrapper($offset) |
55
|
|
|
{ |
56
|
|
|
foreach ($this as $k => &$v) { |
57
|
|
|
if (filter_var($v, FILTER_VALIDATE_URL)) { |
58
|
|
|
$path = $v.'/'.$offset; |
59
|
|
|
|
60
|
|
|
if (file_exists($path)) { |
61
|
|
|
return file_get_contents($path); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
throw new \InvalidArgumentException("Item with id '$offset' could not be found."); |
67
|
|
|
} |
68
|
|
|
} |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.