5
5
* @author Qiang Xue <qiang.xue@gmail.com>
6
6
* @link http://www.yiiframework.com/
7
* @copyright Copyright © 2008-2009 Yii Software LLC
7
* @copyright Copyright © 2008-2010 Yii Software LLC
8
8
* @license http://www.yiiframework.com/license/
16
16
* A property is defined by a getter method, and/or a setter method.
17
17
* Properties can be accessed in the way like accessing normal object members.
18
18
* Reading or writing a property will cause the invocation of the corresponding
19
* getter or setter method, e.g.,
19
* getter or setter method, e.g
21
21
* $a=$component->text; // equivalent to $a=$component->getText();
22
22
* $component->text='abc'; // equivalent to $component->setText('abc');
78
78
* or {@link disableBehavior}, respectively. When disabled, the behavior methods cannot
79
79
* be invoked via the component.
81
* Starting from version 1.1.0, a behavior's properties (either its public member variables or
82
* its properties defined via getters and/or setters) can be accessed through the component it
81
85
* @author Qiang Xue <qiang.xue@gmail.com>
82
* @version $Id: CComponent.php 963 2009-04-28 12:47:01Z qiang.xue $
86
* @version $Id: CComponent.php 1693 2010-01-09 15:04:56Z qiang.xue $
83
87
* @package system.base
117
121
else if(isset($this->_m[$name]))
118
122
return $this->_m[$name];
120
throw new CException(Yii::t('yii','Property "{class}.{property}" is not defined.',
121
array('{class}'=>get_class($this), '{property}'=>$name)));
123
else if(is_array($this->_m))
125
foreach($this->_m as $object)
127
if($object->getEnabled() && (property_exists($object,$name) || $object->canGetProperty($name)))
128
return $object->$name;
131
throw new CException(Yii::t('yii','Property "{class}.{property}" is not defined.',
132
array('{class}'=>get_class($this), '{property}'=>$name)));
139
150
$setter='set'.$name;
140
151
if(method_exists($this,$setter))
141
$this->$setter($value);
152
return $this->$setter($value);
142
153
else if(strncasecmp($name,'on',2)===0 && method_exists($this,$name))
144
155
// duplicating getEventHandlers() here for performance
145
156
$name=strtolower($name);
146
157
if(!isset($this->_e[$name]))
147
158
$this->_e[$name]=new CList;
148
$this->_e[$name]->add($value);
150
else if(method_exists($this,'get'.$name))
159
return $this->_e[$name]->add($value);
161
else if(is_array($this->_m))
163
foreach($this->_m as $object)
165
if($object->getEnabled() && (property_exists($object,$name) || $object->canSetProperty($name)))
166
return $object->$name=$value;
169
if(method_exists($this,'get'.$name))
151
170
throw new CException(Yii::t('yii','Property "{class}.{property}" is read only.',
152
171
array('{class}'=>get_class($this), '{property}'=>$name)));
212
231
foreach($this->_m as $object)
214
if($object->enabled && method_exists($object,$name))
233
if($object->getEnabled() && method_exists($object,$name))
215
234
return call_user_func_array(array($object,$name),$parameters);
510
529
call_user_func($handler,$event);
511
530
else if(is_callable($handler,true))
513
// an array: 0 - object, 1 - method name
514
list($object,$method)=$handler;
515
if(is_string($object)) // static method call
532
if(is_array($handler))
534
// an array: 0 - object, 1 - method name
535
list($object,$method)=$handler;
536
if(is_string($object)) // static method call
537
call_user_func($handler,$event);
538
else if(method_exists($object,$method))
539
$object->$method($event);
541
throw new CException(Yii::t('yii','Event "{class}.{event}" is attached with an invalid handler "{handler}".',
542
array('{class}'=>get_class($this), '{event}'=>$name, '{handler}'=>$handler[1])));
544
else // PHP 5.3: anonymous function
516
545
call_user_func($handler,$event);
517
else if(method_exists($object,$method))
518
$object->$method($event);
520
throw new CException(Yii::t('yii','Event "{class}.{event}" is attached with an invalid handler "{handler}".',
521
array('{class}'=>get_class($this), '{event}'=>$name, '{handler}'=>$handler[1])));
524
548
throw new CException(Yii::t('yii','Event "{class}.{event}" is attached with an invalid handler "{handler}".',
532
556
throw new CException(Yii::t('yii','Event "{class}.{event}" is not defined.',
533
557
array('{class}'=>get_class($this), '{event}'=>$name)));
561
* Evaluates a PHP expression or callback under the context of this component.
563
* Valid PHP callback can be class method name in the form of
564
* array(ClassName/Object, MethodName), or anonymous function (only available in PHP 5.3.0 or above).
566
* If a PHP callback is used, the corresponding function/method signature should be
568
* function foo($param1, $param2, ..., $component) { ... }
570
* where the array elements in the second parameter to this method will be passed
571
* to the callback as $param1, $param2, ...; and the last parameter will be the component itself.
573
* If a PHP expression is used, the second parameter will be "extracted" into PHP variables
574
* that can be directly accessed in the expression. See {@link http://us.php.net/manual/en/function.extract.php PHP extract}
575
* for more details. In the expression, the component object can be accessed using $this.
577
* @var mixed a PHP expression or PHP callback to be evaluated.
578
* @param array additional parameters to be passed to the above expression/callback.
579
* @return mixed the expression result
582
public function evaluateExpression($_expression_,$_data_=array())
584
if(is_string($_expression_))
587
return @eval('return '.$_expression_.';');
592
return call_user_func_array($_expression_, $_data_);
545
605
* that are not invoked yet will not be invoked anymore.
547
607
* @author Qiang Xue <qiang.xue@gmail.com>
548
* @version $Id: CComponent.php 963 2009-04-28 12:47:01Z qiang.xue $
608
* @version $Id: CComponent.php 1693 2010-01-09 15:04:56Z qiang.xue $
549
609
* @package system.base