Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
/**
3
 *
4
 *
5
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
6
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @copyright	  Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
 * @link		  http://cakephp.org CakePHP(tm) Project
14
 * @package		  Cake.Observer
15
 * @since		  CakePHP(tm) v 2.1
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
 
19
/**
20
 * Represents the transport class of events across the system. It receives a name, subject and an optional
21
 * payload. The name can be any string that uniquely identifies the event across the application, while the subject
22
 * represents the object that the event applies to.
23
 *
24
 * @package Cake.Event
25
 */
26
class CakeEvent {
27
 
28
/**
29
 * Name of the event
30
 *
31
 * @var string $name
32
 */
33
	protected $_name = null;
34
 
35
/**
36
 * The object this event applies to (usually the same object that generates the event)
37
 *
38
 * @var object
39
 */
40
	protected $_subject;
41
 
42
/**
43
 * Custom data for the method that receives the event
44
 *
45
 * @var mixed $data
46
 */
47
	public $data = null;
48
 
49
/**
50
 * Property used to retain the result value of the event listeners
51
 *
52
 * @var mixed $result
53
 */
54
	public $result = null;
55
 
56
/**
57
 * Flags an event as stopped or not, default is false
58
 *
59
 * @var boolean
60
 */
61
	protected $_stopped = false;
62
 
63
/**
64
 * Constructor
65
 *
66
 * @param string $name Name of the event
67
 * @param object $subject the object that this event applies to (usually the object that is generating the event)
68
 * @param mixed $data any value you wish to be transported with this event to it can be read by listeners
69
 *
70
 * ## Examples of usage:
71
 *
72
 * {{{
73
 *	$event = new CakeEvent('Order.afterBuy', $this, array('buyer' => $userData));
74
 *	$event = new CakeEvent('User.afterRegister', $UserModel);
75
 * }}}
76
 *
77
 */
78
	public function __construct($name, $subject = null, $data = null) {
79
		$this->_name = $name;
80
		$this->data = $data;
81
		$this->_subject = $subject;
82
	}
83
 
84
/**
85
 * Dynamically returns the name and subject if accessed directly
86
 *
87
 * @param string $attribute
88
 * @return mixed
89
 */
90
	public function __get($attribute) {
91
		if ($attribute === 'name' || $attribute === 'subject') {
92
			return $this->{$attribute}();
93
		}
94
	}
95
 
96
/**
97
 * Returns the name of this event. This is usually used as the event identifier
98
 *
99
 * @return string
100
 */
101
	public function name() {
102
		return $this->_name;
103
	}
104
 
105
/**
106
 * Returns the subject of this event
107
 *
108
 * @return string
109
 */
110
	public function subject() {
111
		return $this->_subject;
112
	}
113
 
114
/**
115
 * Stops the event from being used anymore
116
 *
117
 * @return void
118
 */
119
	public function stopPropagation() {
120
		return $this->_stopped = true;
121
	}
122
 
123
/**
124
 * Check if the event is stopped
125
 *
126
 * @return boolean True if the event is stopped
127
 */
128
	public function isStopped() {
129
		return $this->_stopped;
130
	}
131
 
132
}