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 Cecil\Exception\Exception; |
12
|
|
|
use Symfony\Component\Finder\Finder; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Locates content. |
16
|
|
|
*/ |
17
|
|
|
class ContentLoad extends AbstractStep |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
* |
22
|
|
|
* @throws Exception |
23
|
|
|
*/ |
24
|
|
|
public function init($options) |
25
|
|
|
{ |
26
|
|
|
if (!is_dir($this->builder->getConfig()->getContentPath())) { |
27
|
|
|
throw new Exception(sprintf('%s not found!', $this->builder->getConfig()->getContentPath())); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$this->process = true; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function process() |
37
|
|
|
{ |
38
|
|
|
call_user_func_array($this->builder->getMessageCb(), ['LOCATE', 'Loading content']); |
39
|
|
|
|
40
|
|
|
$content = Finder::create() |
41
|
|
|
->files() |
42
|
|
|
->in($this->builder->getConfig()->getContentPath()) |
43
|
|
|
->name('/\.('.implode('|', $this->builder->getConfig()->get('content.ext')).')$/'); |
44
|
|
|
if (!$content instanceof Finder) { |
45
|
|
|
throw new Exception(sprintf("'%s->%s()' result must be an instance of 'Finder'.", __CLASS__, __FUNCTION__)); |
46
|
|
|
} |
47
|
|
|
$count = $content->count(); |
48
|
|
|
call_user_func_array($this->builder->getMessageCb(), ['LOCATE_PROGRESS', 'Start locating', 0, $count]); |
49
|
|
|
$this->builder->setContent($content); |
50
|
|
|
call_user_func_array($this->builder->getMessageCb(), ['LOCATE_PROGRESS', 'Files loaded', $count, $count]); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|