|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Cecil\Step; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\Finder\Finder; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Load static files. |
|
15
|
|
|
*/ |
|
16
|
|
|
class StaticLoad extends AbstractStep |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
|
|
public function init($options) |
|
22
|
|
|
{ |
|
23
|
|
|
if (is_dir($this->builder->getConfig()->getStaticPath())) { |
|
24
|
|
|
$this->process = true; |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function process() |
|
32
|
|
|
{ |
|
33
|
|
|
call_user_func_array($this->builder->getMessageCb(), ['DATA', 'Loading static files']); |
|
34
|
|
|
|
|
35
|
|
|
$files = Finder::create() |
|
36
|
|
|
->files() |
|
37
|
|
|
->in($this->builder->getConfig()->getStaticPath()) |
|
38
|
|
|
->sortByName(true); |
|
39
|
|
|
$max = count($files); |
|
40
|
|
|
|
|
41
|
|
|
if ($max <= 0) { |
|
42
|
|
|
$message = 'No files'; |
|
43
|
|
|
call_user_func_array($this->builder->getMessageCb(), ['DATA_PROGRESS', $message]); |
|
44
|
|
|
|
|
45
|
|
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$count = 0; |
|
49
|
|
|
|
|
50
|
|
|
/* @var $file \Symfony\Component\Finder\SplFileInfo */ |
|
51
|
|
|
foreach ($files as $file) { |
|
52
|
|
|
$staticFiles[$count]['path'] = $file->getRelativePathname(); |
|
53
|
|
|
$staticFiles[$count]['date'] = (new \DateTime())->setTimestamp($file->getCTime()); |
|
54
|
|
|
$staticFiles[$count]['updated'] = (new \DateTime())->setTimestamp($file->getMTime()); |
|
55
|
|
|
$staticFiles[$count]['name'] = $file->getBasename(); |
|
56
|
|
|
$staticFiles[$count]['basename'] = $file->getBasename('.'.$file->getExtension()); |
|
57
|
|
|
$staticFiles[$count]['ext'] = $file->getExtension(); |
|
58
|
|
|
$this->builder->setStatic($staticFiles); |
|
|
|
|
|
|
59
|
|
|
$count++; |
|
60
|
|
|
|
|
61
|
|
|
$message = sprintf('%s', $file->getRelativePathname()); |
|
62
|
|
|
call_user_func_array($this->builder->getMessageCb(), ['DATA_PROGRESS', $message, $count, $max]); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|