diff --git a/src/Event/Event.php b/src/Event/Event.php index c4d3756d528..332ebd7768e 100644 --- a/src/Event/Event.php +++ b/src/Event/Event.php @@ -21,8 +21,8 @@ * * @property string $name Name of the event * @property object $subject The object this event applies to - * @property mixed $result Property used to retain the result value of the event listeners - * @property array $data Custom data for the method that receives the event + * @property mixed $result (deprecated) Property used to retain the result value of the event listeners + * @property array $data (deprecated) Custom data for the method that receives the event */ class Event { @@ -76,12 +76,8 @@ class Event * @param object|null $subject the object that this event applies to (usually the object that is generating the event) * @param array|null $data any value you wish to be transported with this event to it can be read by listeners */ - public function __construct($name, $subject = null, $data = null) + public function __construct($name, $subject = null, array $data = null) { - if ($data !== null && !is_array($data)) { - trigger_error('Data parameter will be changing to array hint typing', E_USER_DEPRECATED); - } - $this->_name = $name; $this->_data = (array)$data; $this->_subject = $subject; @@ -99,11 +95,9 @@ public function __get($attribute) return $this->{$attribute}(); } if ($attribute === 'data') { - trigger_error('Public read access to data is deprecated, use data()', E_USER_DEPRECATED); return $this->_data; } if ($attribute === 'result') { - trigger_error('Public read access to result is deprecated, use result()', E_USER_DEPRECATED); return $this->_result; } } @@ -112,16 +106,15 @@ public function __get($attribute) * Provides backward compatibility for write access to data and result properties. * * @param string $attribute Attribute name. - * @param mixed $value + * @param mixed $value The value to set. + * @return void */ public function __set($attribute, $value) { if ($attribute === 'data') { - trigger_error('Public write access to data is deprecated, use setData()', E_USER_DEPRECATED); $this->_data = (array)$value; } if ($attribute === 'result') { - trigger_error('Public write access to result is deprecated, use setResult()', E_USER_DEPRECATED); $this->_result = $value; } } @@ -177,19 +170,22 @@ public function result() } /** - * @param null $value + * Listeners can attach a result value to the event. + * + * @param mixed $value The value to set. * @return $this */ public function setResult($value = null) { $this->_result = $value; + return $this; } /** * Access the event data/payload. * - * @param string|null $key + * @param string|null $key The data payload element to return, or null to return all data. * @return array|null The data payload if $key is null, or the data value for the given $key. If the $key does not * exist a null value is returned. */ @@ -198,12 +194,15 @@ public function data($key = null) if ($key !== null) { return isset($this->_data[$key]) ? $this->_data[$key] : null; } + return (array)$this->_data; } /** - * @param array|string $key - * @param mixed $value + * Assigns a value to the data/payload of this event. + * + * @param array|string $key An array will replace all payload data, and a key will set just that array item. + * @param mixed $value The value to set. * @return $this */ public function setData($key, $value = null) @@ -213,6 +212,7 @@ public function setData($key, $value = null) } else { $this->_data[$key] = $value; } + return $this; } } diff --git a/tests/TestCase/ORM/TableTest.php b/tests/TestCase/ORM/TableTest.php index 41a034cb473..73475691a73 100644 --- a/tests/TestCase/ORM/TableTest.php +++ b/tests/TestCase/ORM/TableTest.php @@ -27,8 +27,8 @@ use Cake\Event\EventManager; use Cake\I18n\Time; use Cake\ORM\Association\BelongsToMany; -use Cake\ORM\Association\HasMany; use Cake\ORM\AssociationCollection; +use Cake\ORM\Association\HasMany; use Cake\ORM\Entity; use Cake\ORM\Query; use Cake\ORM\RulesChecker;