~fusonic/chive/1.1

« back to all changes in this revision

Viewing changes to yii/base/CComponent.php

  • Committer: Matthias Burtscher
  • Date: 2010-02-12 09:12:35 UTC
  • Revision ID: matthias.burtscher@fusonic.net-20100212091235-jqxrb62klx872ajc
* Updated Yii to 1.1.0
* Removed CodePress and CodeMirror
* Updated jQuery and some plugins
* Cleaned some code ...

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *
5
5
 * @author Qiang Xue <qiang.xue@gmail.com>
6
6
 * @link http://www.yiiframework.com/
7
 
 * @copyright Copyright &copy; 2008-2009 Yii Software LLC
 
7
 * @copyright Copyright &copy; 2008-2010 Yii Software LLC
8
8
 * @license http://www.yiiframework.com/license/
9
9
 */
10
10
 
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
20
20
 * <pre>
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.
80
80
 *
 
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
 
83
 * is attached to.
 
84
 *
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
84
88
 * @since 1.0
85
89
 */
116
120
                }
117
121
                else if(isset($this->_m[$name]))
118
122
                        return $this->_m[$name];
119
 
                else
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))
 
124
                {
 
125
                        foreach($this->_m as $object)
 
126
                        {
 
127
                                if($object->getEnabled() && (property_exists($object,$name) || $object->canGetProperty($name)))
 
128
                                        return $object->$name;
 
129
                        }
 
130
                }
 
131
                throw new CException(Yii::t('yii','Property "{class}.{property}" is not defined.',
 
132
                        array('{class}'=>get_class($this), '{property}'=>$name)));
122
133
        }
123
134
 
124
135
        /**
138
149
        {
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))
143
154
                {
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);
149
 
                }
150
 
                else if(method_exists($this,'get'.$name))
 
159
                        return $this->_e[$name]->add($value);
 
160
                }
 
161
                else if(is_array($this->_m))
 
162
                {
 
163
                        foreach($this->_m as $object)
 
164
                        {
 
165
                                if($object->getEnabled() && (property_exists($object,$name) || $object->canSetProperty($name)))
 
166
                                        return $object->$name=$value;
 
167
                        }
 
168
                }
 
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)));
153
172
                else
211
230
                {
212
231
                        foreach($this->_m as $object)
213
232
                        {
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);
216
235
                        }
217
236
                }
510
529
                                        call_user_func($handler,$event);
511
530
                                else if(is_callable($handler,true))
512
531
                                {
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))
 
533
                                        {
 
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);
 
540
                                                else
 
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])));
 
543
                                        }
 
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);
519
 
                                        else
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])));
522
546
                                }
523
547
                                else
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)));
534
558
        }
 
559
 
 
560
        /**
 
561
         * Evaluates a PHP expression or callback under the context of this component.
 
562
         *
 
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).
 
565
         *
 
566
         * If a PHP callback is used, the corresponding function/method signature should be
 
567
         * <pre>
 
568
         * function foo($param1, $param2, ..., $component) { ... }
 
569
         * </pre>
 
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.
 
572
         *
 
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.
 
576
         *
 
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
 
580
         * @since 1.1.0
 
581
         */
 
582
        public function evaluateExpression($_expression_,$_data_=array())
 
583
        {
 
584
                if(is_string($_expression_))
 
585
                {
 
586
                        extract($_data_);
 
587
                        return @eval('return '.$_expression_.';');
 
588
                }
 
589
                else
 
590
                {
 
591
                        $_data_[]=$this;
 
592
                        return call_user_func_array($_expression_, $_data_);
 
593
                }
 
594
        }
535
595
}
536
596
 
537
597
 
545
605
 * that are not invoked yet will not be invoked anymore.
546
606
 *
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
550
610
 * @since 1.0
551
611
 */
590
650
 * TextAlign::Right.
591
651
 *
592
652
 * @author Qiang Xue <qiang.xue@gmail.com>
593
 
 * @version $Id: CComponent.php 963 2009-04-28 12:47:01Z qiang.xue $
 
653
 * @version $Id: CComponent.php 1693 2010-01-09 15:04:56Z qiang.xue $
594
654
 * @package system.base
595
655
 * @since 1.0
596
656
 */