ApplicationEvent.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 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 occured.
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 occured.
79  * @return String
80  */
81  public function getStage() {
82  return $this->_stage;
83  }
84  /**
85  * Get the request.
86  * @return Request instance
87  */
88  public function getRequest() {
89  return $this->_request;
90  }
91 
92  /**
93  * Get the response.
94  * @return Response instance
95  */
96  public function getResponse() {
97  return $this->_response;
98  }
99 
100  /**
101  * Get the controller.
102  * @return Controller instance
103  */
104  public function getController() {
105  return $this->_controller;
106  }
107 }
108 ?>
Response holds the response values that are used as output from Controller instances.
Definition: Response.php:20
Controller is the base class of all controllers.
Definition: Controller.php:48
const BEFORE_INITIALIZE_CONTROLLER
A BEFORE_INITIALIZE_CONTROLLER event occurs before the current controller is initialized.
Presentation related interfaces and classes.
Definition: namespaces.php:59
const AFTER_EXECUTE_CONTROLLER
A AFTER_EXECUTE_CONTROLLER event occurs after the current controller is executed. ...
getStage()
Get the stage at which the event occured.
Request holds the request values that are used as input to Controller instances.
Definition: Request.php:20
const BEFORE_EXECUTE_CONTROLLER
A BEFORE_EXECUTE_CONTROLLER event occurs after the current controller is initialized and before it is...
const BEFORE_ROUTE_ACTION
A BEFORE_ROUTE_ACTION event occurs before the request is mapped to an action key. ...
ApplicationEvent instances are fired at different stages of the program flow.
__construct($stage, Request $request, Response $response=null, Controller $controller=null)
Constructor.
Event is the base class for all events.
Definition: Event.php:18