Commit 1fbf81be by Qiang Xue

User WIP.

parent 5f0f721c
......@@ -204,7 +204,7 @@ doIt('a', array(
~~~
if ($event === null) {
return new Event($this);
return new Event();
} elseif ($event instanceof CoolEvent) {
return $event->instance();
} else {
......
......@@ -422,7 +422,10 @@ class Component extends \yii\base\Object
$this->ensureBehaviors();
if (isset($this->_e[$name]) && $this->_e[$name]->getCount()) {
if ($event === null) {
$event = new Event($this);
$event = new Event;
}
if ($event->sender === null) {
$event->sender = $this;
}
$event->handled = false;
$event->name = $name;
......
......@@ -28,7 +28,8 @@ class Event extends \yii\base\Object
*/
public $name;
/**
* @var object the sender of this event
* @var object the sender of this event. If not set, this property will be
* set as the object whose "trigger()" method is called.
*/
public $sender;
/**
......@@ -38,21 +39,7 @@ class Event extends \yii\base\Object
*/
public $handled = false;
/**
* @var mixed extra data associated with the event.
* @var mixed extra custom data associated with the event.
*/
public $data;
/**
* Constructor.
*
* @param mixed $sender sender of the event
* @param mixed $data extra data associated with the event
* @param array $config name-value pairs that will be used to initialize the object properties
*/
public function __construct($sender = null, $data = null, $config = array())
{
$this->sender = $sender;
$this->data = $data;
parent::__construct($config);
}
}
......@@ -258,7 +258,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public function beforeValidate()
{
$event = new ModelEvent($this);
$event = new ModelEvent;
$this->trigger(self::EVENT_BEFORE_VALIDATE, $event);
return $event->isValid;
}
......
......@@ -847,7 +847,7 @@ class ActiveRecord extends Model
*/
public function beforeSave($insert)
{
$event = new ModelEvent($this);
$event = new ModelEvent;
$this->trigger($insert ? self::EVENT_BEFORE_INSERT : self::EVENT_BEFORE_UPDATE, $event);
return $event->isValid;
}
......@@ -887,7 +887,7 @@ class ActiveRecord extends Model
*/
public function beforeDelete()
{
$event = new ModelEvent($this);
$event = new ModelEvent;
$this->trigger(self::EVENT_BEFORE_DELETE, $event);
return $event->isValid;
}
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\web;
/**
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
interface Identity
{
/**
* Returns an ID that can uniquely identify a user identity.
* The returned ID can be a string, an integer, or any serializable data.
* @return mixed an ID that uniquely identifies a user identity.
*/
public function getId();
/**
* Returns a key that can be used to check the validity of a given identity ID.
* The space of such keys should be big and random enough to defeat potential identity attacks.
* The returned key can be a string, an integer, or any serializable data.
* @return mixed a key that is used to check the validity of a given identity ID.
* @see validateAuthKey()
*/
public function getAuthKey();
/**
* Validates the given auth key.
* @param string $authKey the given auth key
* @return boolean whether the given auth key is valid.
* @see getAuthKey()
*/
public function validateAuthKey($authKey);
/**
* Finds an identity by the given ID.
* @param mixed $id the ID to be looked for
* @return Identity the identity object that matches the given ID.
* Null should be returned if such an identity cannot be found.
*/
public static function findIdentity($id);
}
\ No newline at end of file
......@@ -7,6 +7,7 @@
namespace yii\web;
use Yii;
use yii\helpers\FileHelper;
/**
......@@ -178,6 +179,6 @@ class Response extends \yii\base\Response
*/
public function getCookies()
{
return \Yii::$app->getRequest()->getCookies();
return Yii::$app->getRequest()->getCookies();
}
}
......@@ -619,6 +619,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
}
/**
* Returns a value indicating whether there is a flash message associated with the specified key.
* @param string $key key identifying the flash message
* @return boolean whether the specified flash message exists
*/
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\web;
use yii\base\Event;
/**
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class UserEvent extends Event
{
/**
* @var Identity the identity object associated with this event
*/
public $identity;
/**
* @var boolean whether the login is cookie-based. This property is only meaningful
* for [[User::EVENT_BEFORE_LOGIN]] and [[User::EVENT_AFTER_LOGIN]] events.
*/
public $fromCookie;
/**
* @var boolean whether the login or logout should proceed.
* Event handlers may modify this property to determine whether the login or logout should proceed.
* This property is only meaningful for [[User::EVENT_BEFORE_LOGIN]] and [[User::EVENT_BEFORE_LOGOUT]] events.
*/
public $isValid;
}
\ No newline at end of file
......@@ -352,7 +352,7 @@ class NewComponent extends Component
public function raiseEvent()
{
$this->trigger('click', new Event($this));
$this->trigger('click', new Event);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment