|
1
|
|
|
<?php |
|
2
|
|
|
namespace Nubs\Which\PathBuilder; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Appends extensions to an array of files. |
|
6
|
|
|
*/ |
|
7
|
|
|
trait WindowsExtensionAppenderTrait |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Append the extensions to the paths. |
|
11
|
|
|
* |
|
12
|
|
|
* @param array $paths The file paths to append to. |
|
13
|
|
|
* @param array $extensions The extensions. |
|
14
|
|
|
* @return array The full combination of every path with every extension. |
|
15
|
|
|
*/ |
|
16
|
|
|
protected function _appendExtensionsToPaths(array $paths, array $extensions) |
|
17
|
|
|
{ |
|
18
|
|
|
$getPathsWithExtensions = function($path) use($extensions) { |
|
19
|
|
|
if ($this->_hasExtension($path)) { |
|
20
|
|
|
return [$path]; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
$addExtension = function($extension) use($path) { |
|
24
|
|
|
return $this->_addExtension($path, $extension); |
|
25
|
|
|
}; |
|
26
|
|
|
|
|
27
|
|
|
return array_map($addExtension, $extensions); |
|
28
|
|
|
}; |
|
29
|
|
|
|
|
30
|
|
|
return call_user_func_array('array_merge', array_map($getPathsWithExtensions, $paths)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Adds an extension to a path. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $path The path. |
|
37
|
|
|
* @param string $extension The extension to add. |
|
38
|
|
|
* @return string The path with extension. |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function _addExtension($path, $extension) |
|
41
|
|
|
{ |
|
42
|
|
|
return $path . $extension; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Checks to see if a path already has an extension. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $path The path to check. |
|
49
|
|
|
* @return boolean True if it has an extension, false otherwise. |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function _hasExtension($path) |
|
52
|
|
|
{ |
|
53
|
|
|
return strpos($path, '.') !== false; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|