-
Notifications
You must be signed in to change notification settings - Fork 2
/
SitemapComponent.php
66 lines (56 loc) · 1.84 KB
/
SitemapComponent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace yiiExtensions\sitemap;
use CApplicationComponent;
use CException;
use Yii;
use yiiExtensions\sitemap\components\AppStructureBuilder;
use yiiExtensions\sitemap\components\AppStructureComponent;
/**
* Class SitemapComponent
*
* @author Alexander Bolshakov <[email protected]>
* @package yiiExtensions\sitemap
*/
class SitemapComponent extends CApplicationComponent
{
/**
* @var string
*/
public $structureBuilderClass = 'yiiExtensions\sitemap\components\AppStructureBuilder';
/**
* @var string
*/
public $structureComponentClass = 'yiiExtensions\sitemap\components\AppStructureComponent';
/**
* @var AppStructureBuilder
*/
protected $builderInstance;
/**
* @var array|AppStructureComponent[]
*/
protected $structure = array();
/**
* @param bool $refresh Whether structure renewal is needed.
* For example, if structure builder class or structure component class was changed.
*
* @return array|components\AppStructureComponent[]
*/
public function getApplicationStructure($refresh = false)
{
if ($refresh || empty($this->structure)) {
$this->initStructureBuilder();
$this->structure = $this->builderInstance->buildStructure();
}
return $this->structure;
}
protected function initStructureBuilder()
{
if ($this->builderInstance == null) {
$this->builderInstance = Yii::createComponent($this->structureBuilderClass);
if (!$this->builderInstance instanceof AppStructureBuilder) {
throw new CException('Application structure builder must be instance of AppStructureBuilder class');
}
$this->builderInstance->appStructureComponentClass = $this->structureComponentClass;
}
}
}