Commit fc7c1f56 by Qiang Xue

initial import

parents
yii\
YiiBase
Yii
base\
Application
Behavior
Component
Event
Exception
Model
Module
<?php
namespace yii\base;
class CBehavior extends CComponent implements IBehavior
{
private $_enabled;
private $_owner;
/**
* Declares events and the corresponding event handler methods.
* The events are defined by the {@link owner} component, while the handler
* methods by the behavior class. The handlers will be attached to the corresponding
* events when the behavior is attached to the {@link owner} component; and they
* will be detached from the events when the behavior is detached from the component.
* @return array events (array keys) and the corresponding event handler methods (array values).
*/
public function events()
{
return array();
}
/**
* Attaches the behavior object to the component.
* The default implementation will set the {@link owner} property
* and attach event handlers as declared in {@link events}.
* Make sure you call the parent implementation if you override this method.
* @param CComponent $owner the component that this behavior is to be attached to.
*/
public function attach($owner)
{
$this->_owner=$owner;
foreach($this->events() as $event=>$handler)
$owner->attachEventHandler($event,array($this,$handler));
}
/**
* Detaches the behavior object from the component.
* The default implementation will unset the {@link owner} property
* and detach event handlers declared in {@link events}.
* Make sure you call the parent implementation if you override this method.
* @param CComponent $owner the component that this behavior is to be detached from.
*/
public function detach($owner)
{
foreach($this->events() as $event=>$handler)
$owner->detachEventHandler($event,array($this,$handler));
$this->_owner=null;
}
/**
* @return CComponent the owner component that this behavior is attached to.
*/
public function getOwner()
{
return $this->_owner;
}
/**
* @return boolean whether this behavior is enabled
*/
public function getEnabled()
{
return $this->_enabled;
}
/**
* @param boolean $value whether this behavior is enabled
*/
public function setEnabled($value)
{
if($this->_enabled!=$value && $this->_owner)
{
if($value)
{
foreach($this->events() as $event=>$handler)
$this->_owner->attachEventHandler($event,array($this,$handler));
}
else
{
foreach($this->events() as $event=>$handler)
$this->_owner->detachEventHandler($event,array($this,$handler));
}
}
$this->_enabled=$value;
}
}
<?php
namespace yii\base;
/**
* CEvent is the base class for all event classes.
*
* It encapsulates the parameters associated with an event.
* The {@link sender} property describes who raises the event.
* And the {@link handled} property indicates if the event is handled.
* If an event handler sets {@link handled} to true, those handlers
* that are not invoked yet will not be invoked anymore.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id: CComponent.php 3001 2011-02-24 16:42:44Z alexander.makarow $
* @package system.base
* @since 1.0
*/
class CEvent extends CComponent
{
/**
* @var object the sender of this event
*/
public $sender;
/**
* @var boolean whether the event is handled. Defaults to false.
* When a handler sets this true, the rest of the uninvoked event handlers will not be invoked anymore.
*/
public $handled=false;
/**
* Constructor.
* @param mixed $sender sender of the event
*/
public function __construct($sender=null)
{
$this->sender=$sender;
}
}
<?php
/**
* Yii bootstrap file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @version $Id: yii.php 2799 2011-01-01 19:31:13Z qiang.xue $
* @package system
* @since 1.0
*/
require(__DIR__.'/base/YiiBase.php');
/**
* Yii is a helper class serving common framework functionalities.
*
* It encapsulates {@link YiiBase} which provides the actual implementation.
* By writing your own Yii class, you can customize some functionalities of YiiBase.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id: yii.php 2799 2011-01-01 19:31:13Z qiang.xue $
* @package system
* @since 1.0
*/
class Yii extends yii\YiiBase
{
}
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