AdminController.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
17 
18 /**
19  * AdminController is used to perform admin tasks.
20  *
21  * The controller supports the following actions:
22  *
23  * <div class="controller-action">
24  * <div> __Action__ clearCaches </div>
25  * <div>
26  * Clear all cache instances.
27  * | Parameter | Description
28  * |-----------------------|-------------------------
29  * | __Response Actions__ | |
30  * | `ok` | In all cases
31  * </div>
32  * </div>
33  *
34  * @author ingo herwig <ingo@wemove.com>
35  */
36 class AdminController extends Controller {
37 
38  /**
39  * @see Controller::doExecute()
40  */
41  protected function doExecute($method=null) {
42  $request = $this->getRequest();
43  $response = $this->getResponse();
44 
45  // process actions
46  if ($request->getAction() == 'clearCaches') {
47  $this->clearCaches();
48  }
49 
50  $response->setAction('ok');
51  }
52 
53  /**
54  * Clear all cache instances found in the configuration
55  */
56  protected function clearCaches() {
57  $config = $this->getConfiguration();
58  foreach($config->getSections() as $section) {
59  $sectionValues = $config->getSection($section, true);
60  if (isset($sectionValues['__class'])) {
61  $instance = ObjectFactory::getInstance($section);
62  if ($instance instanceof Cache) {
63  $instance->clearAll();
64  }
65  elseif ($instance instanceof View) {
66  $instance->clearCache();
67  }
68  }
69  }
70  }
71 }
72 ?>
getConfiguration()
Get the Configuration instance.
Definition: Controller.php:323
AdminController is used to perform admin tasks.
clearCaches()
Clear all cache instances found in the configuration.
getRequest()
Get the Request instance.
Definition: Controller.php:251
static getInstance($name, $dynamicConfiguration=[])
View defines the interface for all view implementations.
Definition: View.php:18
Application controllers.
Definition: namespaces.php:3
Controller is the base class of all controllers.
Definition: Controller.php:49
getResponse()
Get the Response instance.
Definition: Controller.php:259
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...
Cache defines the interface for cache implementations.
Definition: Cache.php:21