ApplicationEvent.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  */
11 namespace wcmf\lib\presentation;
12 
17 
18 /**
19  * ApplicationEvent instances are fired at different stages
20  * of the program flow. Note that depending on the stage, some of
21  * the properties may be null, because they are not initialized yet
22  * (e.g. controller).
23  * Listening to this application events allows users to intercept
24  * the application flow and change it by modifying the requests
25  * and responses.
26  *
27  * @author ingo herwig <ingo@wemove.com>
28  */
29 class ApplicationEvent extends Event {
30 
31  const NAME = __CLASS__;
32 
33  /**
34  * A BEFORE_ROUTE_ACTION event occurs before the request is mapped to
35  * an action key. The request data are in the original format at
36  * this stage.
37  */
38  const BEFORE_ROUTE_ACTION = 'BEFORE_ROUTE_ACTION';
39 
40  /**
41  * A BEFORE_INITIALIZE_CONTROLLER event occurs before the current
42  * controller is initialized.
43  */
44  const BEFORE_INITIALIZE_CONTROLLER = 'BEFORE_INITIALIZE_CONTROLLER';
45 
46  /**
47  * A BEFORE_EXECUTE_CONTROLLER event occurs after the current
48  * controller is initialized and before it is executed.
49  */
50  const BEFORE_EXECUTE_CONTROLLER = 'BEFORE_EXECUTE_CONTROLLER';
51 
52  /**
53  * A AFTER_EXECUTE_CONTROLLER event occurs after the current
54  * controller is executed.
55  */
56  const AFTER_EXECUTE_CONTROLLER = 'AFTER_EXECUTE_CONTROLLER';
57 
58  private $stage = null;
59  private $request = null;
60  private $response = null;
61  private $controller = null;
62 
63  /**
64  * Constructor.
65  * @param $stage The stage at which the event occurred.
66  * @param $request The request instance.
67  * @param $response The response instance (optional).
68  * @param $controller The controller instance (optional).
69  */
70  public function __construct($stage, Request $request, Response $response=null, Controller $controller=null) {
71  $this->stage = $stage;
72  $this->request = $request;
73  $this->response = $response;
74  $this->controller = $controller;
75  }
76 
77  /**
78  * Get the stage at which the event occurred.
79  * @return String
80  */
81  public function getStage() {
82  return $this->stage;
83  }
84 
85  /**
86  * Get the request.
87  * @return Request instance
88  */
89  public function getRequest() {
90  return $this->request;
91  }
92 
93  /**
94  * Get the response.
95  * @return Response instance
96  */
97  public function getResponse() {
98  return $this->response;
99  }
100 
101  /**
102  * Get the controller.
103  * @return Controller instance
104  */
105  public function getController() {
106  return $this->controller;
107  }
108 }
109 ?>
Response holds the response values that are used as output from Controller instances.
Definition: Response.php:20
Request holds the request values that are used as input to Controller instances.
Definition: Request.php:18
const AFTER_EXECUTE_CONTROLLER
A AFTER_EXECUTE_CONTROLLER event occurs after the current controller is executed.
getStage()
Get the stage at which the event occurred.
const BEFORE_ROUTE_ACTION
A BEFORE_ROUTE_ACTION event occurs before the request is mapped to an action key.
Event is the base class for all events.
Definition: Event.php:18
const BEFORE_INITIALIZE_CONTROLLER
A BEFORE_INITIALIZE_CONTROLLER event occurs before the current controller is initialized.
__construct($stage, Request $request, Response $response=null, Controller $controller=null)
Constructor.
ApplicationEvent instances are fired at different stages of the program flow.
const BEFORE_EXECUTE_CONTROLLER
A BEFORE_EXECUTE_CONTROLLER event occurs after the current controller is initialized and before it is...
Controller is the base class of all controllers.
Definition: Controller.php:49
Presentation related interfaces and classes.
Definition: namespaces.php:59