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\Generator; |
10
|
|
|
|
11
|
|
|
use Cecil\Collection\Page\Collection as PagesCollection; |
12
|
|
|
use Cecil\Config; |
13
|
|
|
use Cecil\Util; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Abstract class AbstractGenerator. |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractGenerator implements GeneratorInterface |
19
|
|
|
{ |
20
|
|
|
/* @var Config */ |
21
|
|
|
protected $config; |
22
|
|
|
/* @var PagesCollection */ |
23
|
|
|
protected $pagesCollection; |
24
|
|
|
/* @var $messageCallback */ |
25
|
|
|
protected $messageCallback; |
26
|
|
|
/* @var PagesCollection */ |
27
|
|
|
protected $generatedPages; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function __construct(Config $config) |
33
|
|
|
{ |
34
|
|
|
$this->config = $config; |
35
|
|
|
// Create new empty collection |
36
|
|
|
//$this->generatedPages = new PagesCollection('generator-'.$this->getGeneratorName($this)); |
37
|
|
|
$this->generatedPages = new PagesCollection('generator-'.Util::formatClassName($this)); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param PagesCollection $pagesCollection |
42
|
|
|
* @param \Closure $messageCallback |
43
|
|
|
* |
44
|
|
|
* @return PagesCollection |
45
|
|
|
*/ |
46
|
|
|
public function runGenerate(PagesCollection $pagesCollection, \Closure $messageCallback): PagesCollection |
47
|
|
|
{ |
48
|
|
|
$this->pagesCollection = $pagesCollection; |
49
|
|
|
$this->messageCallback = $messageCallback; |
50
|
|
|
|
51
|
|
|
$this->generate(); |
52
|
|
|
|
53
|
|
|
return $this->generatedPages; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Format generator name. |
58
|
|
|
* |
59
|
|
|
* @param self $class |
|
|
|
|
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
protected static function getGeneratorName(self $class): string |
64
|
|
|
{ |
65
|
|
|
return strtolower(substr(strrchr(get_class($class), '\\'), 1)); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: