| Total Complexity | 7 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | class HistoryControllerFactory implements Factory |
||
| 17 | { |
||
| 18 | use Extensible; |
||
| 19 | |||
| 20 | public function create($service, array $params = array()) |
||
| 21 | { |
||
| 22 | $request = Injector::inst()->get(HTTPRequest::class); |
||
| 23 | $id = $request->param('ID'); |
||
| 24 | |||
| 25 | if ($id) { |
||
| 26 | $page = SiteTree::get()->byID($id); |
||
| 27 | if ($page && $this->isEnabled($page)) { |
||
| 28 | return Injector::inst()->create(CMSPageHistoryViewerController::class); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | // Injector is not used to prevent an infinite loop |
||
| 33 | return new CMSPageHistoryController(); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Only activate for pages that have a history viewer capability applied. Modules can provide their |
||
| 38 | * own two cents about this criteria. |
||
| 39 | * |
||
| 40 | * @param SiteTree $record |
||
| 41 | * @return bool |
||
| 42 | */ |
||
| 43 | public function isEnabled(SiteTree $record) |
||
| 53 | } |
||
| 54 | |||
| 56 |