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