|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace allejo\stakx\Manager; |
|
4
|
|
|
|
|
5
|
|
|
use allejo\stakx\System\Folder; |
|
6
|
|
|
use Symfony\Component\Finder\SplFileInfo; |
|
7
|
|
|
|
|
8
|
|
|
class AssetManager extends TrackingManager |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* The location of where to write files to |
|
12
|
|
|
* |
|
13
|
|
|
* @var Folder |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $outputDirectory; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Files or patterns to exclude from copying |
|
19
|
|
|
* |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $excludes; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Files or patterns to ensure are copied regardless of excluded patterns |
|
26
|
|
|
* |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $includes; |
|
30
|
|
|
|
|
31
|
|
|
public function configureFinder ($includes = array(), $excludes = array()) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->excludes = $excludes; |
|
34
|
|
|
$this->includes = $includes; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Set the target directory of where files should be written to |
|
39
|
|
|
* |
|
40
|
|
|
* @param Folder $directory |
|
41
|
|
|
*/ |
|
42
|
|
|
public function setFolder ($directory) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->outputDirectory = $directory; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Copy all of the assets |
|
49
|
|
|
*/ |
|
50
|
|
|
public function copyFiles() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->scanTrackableItems( |
|
53
|
|
|
'.', |
|
54
|
|
|
array( |
|
55
|
|
|
'prefix' => '' |
|
56
|
|
|
), |
|
57
|
|
|
$this->includes, |
|
58
|
|
|
$this->excludes |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function handleTrackableItem($file, $options = array()) |
|
66
|
|
|
{ |
|
67
|
|
|
if (is_string($file)) |
|
68
|
|
|
{ |
|
69
|
|
|
$file = $this->fs->appendPath($options['prefix'], $file); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
if (!$this->fs->exists($file)) { return; } |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
if (!($file instanceof SplFileInfo)) |
|
75
|
|
|
{ |
|
76
|
|
|
$file = new SplFileInfo( |
|
77
|
|
|
$this->fs->absolutePath($file), |
|
78
|
|
|
$this->fs->getFolderPath($file), |
|
79
|
|
|
$file |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$filePath = $file->getRealPath(); |
|
84
|
|
|
$pathToStrip = $this->fs->appendPath(getcwd(), $options['prefix']); |
|
85
|
|
|
$siteTargetPath = ltrim(str_replace($pathToStrip, "", $filePath), DIRECTORY_SEPARATOR); |
|
86
|
|
|
|
|
87
|
|
|
try |
|
88
|
|
|
{ |
|
89
|
|
|
$this->addArrayToTracker( |
|
90
|
|
|
$file->getRelativePathname(), |
|
91
|
|
|
array(), |
|
92
|
|
|
$file->getRelativePathname() |
|
93
|
|
|
); |
|
94
|
|
|
$this->saveOptions($file->getRelativePathname(), $options); |
|
95
|
|
|
$this->outputDirectory->copyFile($filePath, $siteTargetPath); |
|
96
|
|
|
$this->output->info('Copying file: {file}...', array( |
|
97
|
|
|
'file' => $file->getRelativePathname() |
|
98
|
|
|
)); |
|
99
|
|
|
} |
|
100
|
|
|
catch (\Exception $e) |
|
101
|
|
|
{ |
|
102
|
|
|
$this->output->error($e->getMessage()); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.