Complex classes like TComponent often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TComponent, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 282 | class TComponent |
||
| 283 | { |
||
| 284 | /** |
||
| 285 | * @var array event handler lists |
||
| 286 | */ |
||
| 287 | private $_e=array(); |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @var boolean if listening is enabled. Automatically turned on or off in |
||
| 291 | * constructor according to {@link getAutoGlobalListen}. Default false, off |
||
| 292 | */ |
||
| 293 | private $_listeningenabled=false; |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @var array static registered global event handler lists |
||
| 297 | */ |
||
| 298 | private static $_ue=array(); |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @var boolean if object behaviors are on or off. default true, on |
||
| 302 | */ |
||
| 303 | private $_behaviorsenabled=true; |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @var TPriorityMap list of object behaviors |
||
| 307 | */ |
||
| 308 | private $_m=null; |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @var array static global class behaviors, these behaviors are added upon instantiation of a class |
||
| 312 | */ |
||
| 313 | private static $_um=array(); |
||
| 314 | |||
| 315 | |||
| 316 | /** |
||
| 317 | * @const string the name of the global {@link raiseEvent} listener |
||
| 318 | */ |
||
| 319 | const GLOBAL_RAISE_EVENT_LISTENER='fxGlobalListener'; |
||
| 320 | |||
| 321 | |||
| 322 | /** |
||
| 323 | * The common __construct |
||
| 324 | * If desired by the new object, this will auto install and listen to global event functions |
||
| 325 | * as defined by the object via 'fx' methods. This also attaches any predefined behaviors. |
||
| 326 | * This function installs all class behaviors in a class hierarchy from the deepest subclass |
||
| 327 | * through each parent to the top most class, TComponent. |
||
| 328 | */ |
||
| 329 | public function __construct() { |
||
| 330 | if($this->getAutoGlobalListen()) |
||
| 331 | $this->listen(); |
||
| 332 | |||
| 333 | $classes=array_reverse($this->getClassHierarchy(true)); |
||
| 334 | foreach($classes as $class) { |
||
| 335 | if(isset(self::$_um[$class])) |
||
| 336 | $this->attachBehaviors(self::$_um[$class]); |
||
| 337 | } |
||
| 338 | } |
||
| 339 | |||
| 340 | |||
| 341 | /** |
||
| 342 | * Tells TComponent whether or not to automatically listen to global events. |
||
| 343 | * Defaults to false because PHP variable cleanup is affected if this is true. |
||
| 344 | * When unsetting a variable that is listening to global events, {@link unlisten} |
||
| 345 | * must explicitly be called when cleaning variables allocation or else the global |
||
| 346 | * event registry will contain references to the old object. This is true for PHP 5.4 |
||
| 347 | * |
||
| 348 | * Override this method by a subclass to change the setting. When set to true, this |
||
| 349 | * will enable {@link __construct} to call {@link listen}. |
||
| 350 | * |
||
| 351 | * @return boolean whether or not to auto listen to global events during {@link __construct}, default false |
||
| 352 | */ |
||
| 353 | public function getAutoGlobalListen() { |
||
| 356 | |||
| 357 | |||
| 358 | /** |
||
| 359 | * The common __destruct |
||
| 360 | * This unlistens from the global event routines if listening |
||
| 361 | * |
||
| 362 | * PHP 5.3 does not __destruct objects when they are nulled and thus unlisten must be |
||
| 363 | * called must be explicitly called. |
||
| 364 | */ |
||
| 365 | public function __destruct() { |
||
| 369 | |||
| 370 | |||
| 371 | /** |
||
| 372 | * This utility function is a private array filter method. The array values |
||
| 373 | * that start with 'fx' are filtered in. |
||
| 374 | */ |
||
| 375 | private function filter_prado_fx($name) { |
||
| 378 | |||
| 379 | |||
| 380 | /** |
||
| 381 | * This returns an array of the class name and the names of all its parents. The base object first, |
||
| 382 | * {@link TComponent}, and the deepest subclass is last. |
||
| 383 | * @param boolean optional should the names be all lowercase true/false |
||
| 384 | * @return array array of strings being the class hierarchy of $this. |
||
| 385 | */ |
||
| 386 | public function getClassHierarchy($lowercase = false) |
||
| 395 | |||
| 396 | |||
| 397 | /** |
||
| 398 | * This adds an object's fx event handlers into the global broadcaster to listen into any |
||
| 399 | * broadcast global events called through {@link raiseEvent} |
||
| 400 | * |
||
| 401 | * Behaviors may implement the function: |
||
| 402 | * <code> |
||
| 403 | * public function dyListen($globalEvents[, $chain]) { |
||
| 404 | * $this->listen(); //eg |
||
| 405 | * } |
||
| 406 | * </code> |
||
| 407 | * to be executed when listen is called. All attached behaviors are notified through dyListen. |
||
| 408 | * |
||
| 409 | * @return numeric the number of global events that were registered to the global event registry |
||
| 410 | */ |
||
| 411 | public function listen() { |
||
| 431 | |||
| 432 | /** |
||
| 433 | * this removes an object's fx events from the global broadcaster |
||
| 434 | * |
||
| 435 | * Behaviors may implement the function: |
||
| 436 | * <code> |
||
| 437 | * public function dyUnlisten($globalEvents[, $chain]) { |
||
| 438 | * $this->behaviorUnlisten(); //eg |
||
| 439 | * } |
||
| 440 | * </code> |
||
| 441 | * to be executed when listen is called. All attached behaviors are notified through dyUnlisten. |
||
| 442 | * |
||
| 443 | * @return numeric the number of global events that were unregistered from the global event registry |
||
| 444 | */ |
||
| 445 | public function unlisten() { |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Gets the state of listening to global events |
||
| 468 | * @return boolean is Listening to global broadcast enabled |
||
| 469 | */ |
||
| 470 | public function getListeningToGlobalEvents() |
||
| 474 | |||
| 475 | |||
| 476 | /** |
||
| 477 | * Calls a method. |
||
| 478 | * Do not call this method directly. This is a PHP magic method that we override |
||
| 479 | * to allow behaviors, dynamic events (intra-object/behavior events), |
||
| 480 | * undefined dynamic and global events, and |
||
| 481 | * to allow using the following syntax to call a property setter or getter. |
||
| 482 | * <code> |
||
| 483 | * $this->getPropertyName($value); // if there's a $this->getjsPropertyName() method |
||
| 484 | * $this->setPropertyName($value); // if there's a $this->setjsPropertyName() method |
||
| 485 | * </code> |
||
| 486 | * |
||
| 487 | * Additional object behaviors override class behaviors. |
||
| 488 | * dynamic and global events do not fail even if they aren't implemented. |
||
| 489 | * Any intra-object/behavior dynamic events that are not implemented by the behavior |
||
| 490 | * return the first function paramater or null when no parameters are specified. |
||
| 491 | * |
||
| 492 | * @param string method name that doesn't exist and is being called on the object |
||
| 493 | * @param mixed method parameters |
||
| 494 | * @throws TInvalidOperationException If the property is not defined or read-only or |
||
| 495 | * method is undefined |
||
| 496 | * @return mixed result of the method call, or false if 'fx' or 'dy' function but |
||
| 497 | * is not found in the class, otherwise it runs |
||
| 498 | */ |
||
| 499 | public function __call($method, $args) |
||
| 563 | |||
| 564 | |||
| 565 | /** |
||
| 566 | * Returns a property value or an event handler list by property or event name. |
||
| 567 | * Do not call this method. This is a PHP magic method that we override |
||
| 568 | * to allow using the following syntax to read a property: |
||
| 569 | * <code> |
||
| 570 | * $value=$component->PropertyName; |
||
| 571 | * $value=$component->jsPropertyName; // return JavaScript literal |
||
| 572 | * </code> |
||
| 573 | * and to obtain the event handler list for an event, |
||
| 574 | * <code> |
||
| 575 | * $eventHandlerList=$component->EventName; |
||
| 576 | * </code> |
||
| 577 | * This will also return the global event handler list when specifing an 'fx' |
||
| 578 | * event, |
||
| 579 | * <code> |
||
| 580 | * $globalEventHandlerList=$component->fxEventName; |
||
| 581 | * </code> |
||
| 582 | * When behaviors are enabled, this will return the behavior of a specific |
||
| 583 | * name, a property of a behavior, or an object 'on' event defined by the behavior. |
||
| 584 | * @param string the property name or the event name |
||
| 585 | * @return mixed the property value or the event handler list as {@link TPriorityList} |
||
| 586 | * @throws TInvalidOperationException if the property/event is not defined. |
||
| 587 | */ |
||
| 588 | public function __get($name) |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Sets value of a component property. |
||
| 636 | * Do not call this method. This is a PHP magic method that we override |
||
| 637 | * to allow using the following syntax to set a property or attach an event handler. |
||
| 638 | * <code> |
||
| 639 | * $this->PropertyName=$value; |
||
| 640 | * $this->jsPropertyName=$value; // $value will be treated as a JavaScript literal |
||
| 641 | * $this->EventName=$handler; |
||
| 642 | * $this->fxEventName=$handler; //global event listener |
||
| 643 | * </code> |
||
| 644 | * When behaviors are enabled, this will also set a behaviors properties and events. |
||
| 645 | * @param string the property name or event name |
||
| 646 | * @param mixed the property value or event handler |
||
| 647 | * @throws TInvalidOperationException If the property is not defined or read-only. |
||
| 648 | */ |
||
| 649 | public function __set($name,$value) |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Checks if a property value is null, there are no events in the object |
||
| 694 | * event list or global event list registered under the name, and, if |
||
| 695 | * behaviors are enabled, |
||
| 696 | * Do not call this method. This is a PHP magic method that we override |
||
| 697 | * to allow using isset() to detect if a component property is set or not. |
||
| 698 | * This also works for global events. When behaviors are enabled, it |
||
| 699 | * will check for a behavior of the specified name, and also check |
||
| 700 | * the behavior for events and properties. |
||
| 701 | * @param string the property name or the event name |
||
| 702 | * @since 3.2.3 |
||
| 703 | */ |
||
| 704 | public function __isset($name) |
||
| 705 | { |
||
| 706 | if(method_exists($this,$getter='get'.$name)) |
||
| 707 | return $this->$getter()!==null; |
||
| 708 | else if(method_exists($this,$jsgetter='getjs'.$name)) |
||
| 709 | return $this->$jsgetter()!==null; |
||
| 710 | else if(strncasecmp($name,'on',2)===0&&method_exists($this,$name)) |
||
| 711 | { |
||
| 712 | $name=strtolower($name); |
||
| 713 | return isset($this->_e[$name])&&$this->_e[$name]->getCount(); |
||
| 714 | } |
||
| 715 | else if(strncasecmp($name,'fx',2)===0) |
||
| 716 | { |
||
| 717 | $name=strtolower($name); |
||
| 718 | return isset(self::$_ue[$name])&&self::$_ue[$name]->getCount(); |
||
| 719 | } |
||
| 720 | else if($this->_m!==null&&$this->_m->getCount()>0&&$this->_behaviorsenabled) |
||
| 721 | { |
||
| 722 | if(isset($this->_m[$name])) |
||
| 723 | return true; |
||
| 724 | foreach($this->_m->toArray() as $behavior) |
||
| 725 | { |
||
| 726 | if((!($behavior instanceof IBehavior)||$behavior->getEnabled())) |
||
| 727 | return isset($behavior->$name); |
||
| 728 | } |
||
| 729 | |||
| 730 | } |
||
| 731 | else |
||
| 732 | return false; |
||
| 733 | } |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Sets a component property to be null. Clears the object or global |
||
| 737 | * events. When enabled, loops through all behaviors and unsets the |
||
| 738 | * property or event. |
||
| 739 | * Do not call this method. This is a PHP magic method that we override |
||
| 740 | * to allow using unset() to set a component property to be null. |
||
| 741 | * @param string the property name or the event name |
||
| 742 | * @throws TInvalidOperationException if the property is read only. |
||
| 743 | * @since 3.2.3 |
||
| 744 | */ |
||
| 745 | public function __unset($name) |
||
| 774 | |||
| 775 | /** |
||
| 776 | * Determines whether a property is defined. |
||
| 777 | * A property is defined if there is a getter or setter method |
||
| 778 | * defined in the class. Note, property names are case-insensitive. |
||
| 779 | * @param string the property name |
||
| 780 | * @return boolean whether the property is defined |
||
| 781 | */ |
||
| 782 | public function hasProperty($name) |
||
| 786 | |||
| 787 | /** |
||
| 788 | * Determines whether a property can be read. |
||
| 789 | * A property can be read if the class has a getter method |
||
| 790 | * for the property name. Note, property name is case-insensitive. |
||
| 791 | * This also checks for getjs. When enabled, it loops through all |
||
| 792 | * active behaviors for the get property when undefined by the object. |
||
| 793 | * @param string the property name |
||
| 794 | * @return boolean whether the property can be read |
||
| 795 | */ |
||
| 796 | public function canGetProperty($name) |
||
| 810 | |||
| 811 | /** |
||
| 812 | * Determines whether a property can be set. |
||
| 813 | * A property can be written if the class has a setter method |
||
| 814 | * for the property name. Note, property name is case-insensitive. |
||
| 815 | * This also checks for setjs. When enabled, it loops through all |
||
| 816 | * active behaviors for the set property when undefined by the object. |
||
| 817 | * @param string the property name |
||
| 818 | * @return boolean whether the property can be written |
||
| 819 | */ |
||
| 820 | public function canSetProperty($name) |
||
| 834 | |||
| 835 | /** |
||
| 836 | * Evaluates a property path. |
||
| 837 | * A property path is a sequence of property names concatenated by '.' character. |
||
| 838 | * For example, 'Parent.Page' refers to the 'Page' property of the component's |
||
| 839 | * 'Parent' property value (which should be a component also). |
||
| 840 | * When a property is not defined by an object, this also loops through all |
||
| 841 | * active behaviors of the object. |
||
| 842 | * @param string property path |
||
| 843 | * @return mixed the property path value |
||
| 844 | */ |
||
| 845 | public function getSubProperty($path) |
||
| 852 | |||
| 853 | /** |
||
| 854 | * Sets a value to a property path. |
||
| 855 | * A property path is a sequence of property names concatenated by '.' character. |
||
| 856 | * For example, 'Parent.Page' refers to the 'Page' property of the component's |
||
| 857 | * 'Parent' property value (which should be a component also). |
||
| 858 | * When a property is not defined by an object, this also loops through all |
||
| 859 | * active behaviors of the object. |
||
| 860 | * @param string property path |
||
| 861 | * @param mixed the property path value |
||
| 862 | */ |
||
| 863 | public function setSubProperty($path,$value) |
||
| 875 | |||
| 876 | /** |
||
| 877 | * Determines whether an event is defined. |
||
| 878 | * An event is defined if the class has a method whose name is the event name |
||
| 879 | * prefixed with 'on', 'fx', or 'dy'. |
||
| 880 | * Every object responds to every 'fx' and 'dy' event as they are in a universally |
||
| 881 | * accepted event space. 'on' event must be declared by the object. |
||
| 882 | * When enabled, this will loop through all active behaviors for 'on' events |
||
| 883 | * defined by the behavior. |
||
| 884 | * Note, event name is case-insensitive. |
||
| 885 | * @param string the event name |
||
| 886 | * @return boolean |
||
| 887 | */ |
||
| 888 | public function hasEvent($name) |
||
| 903 | |||
| 904 | /** |
||
| 905 | * Checks if an event has any handlers. This function also checks through all |
||
| 906 | * the behaviors for 'on' events when behaviors are enabled. |
||
| 907 | * 'dy' dynamic events are not handled by this function. |
||
| 908 | * @param string the event name |
||
| 909 | * @return boolean whether an event has been attached one or several handlers |
||
| 910 | */ |
||
| 911 | public function hasEventHandler($name) |
||
| 930 | |||
| 931 | /** |
||
| 932 | * Returns the list of attached event handlers for an 'on' or 'fx' event. This function also |
||
| 933 | * checks through all the behaviors for 'on' event lists when behaviors are enabled. |
||
| 934 | * @return TPriorityList list of attached event handlers for an event |
||
| 935 | * @throws TInvalidOperationException if the event is not defined |
||
| 936 | */ |
||
| 937 | public function getEventHandlers($name) |
||
| 963 | |||
| 964 | /** |
||
| 965 | * Attaches an event handler to an event. |
||
| 966 | * |
||
| 967 | * The handler must be a valid PHP callback, i.e., a string referring to |
||
| 968 | * a global function name, or an array containing two elements with |
||
| 969 | * the first element being an object and the second element a method name |
||
| 970 | * of the object. In Prado, you can also use method path to refer to |
||
| 971 | * an event handler. For example, array($object,'Parent.buttonClicked') |
||
| 972 | * uses a method path that refers to the method $object->Parent->buttonClicked(...). |
||
| 973 | * |
||
| 974 | * The event handler must be of the following signature, |
||
| 975 | * <code> |
||
| 976 | * function handlerName($sender, $param) {} |
||
| 977 | * function handlerName($sender, $param, $name) {} |
||
| 978 | * </code> |
||
| 979 | * where $sender represents the object that raises the event, |
||
| 980 | * and $param is the event parameter. $name refers to the event name |
||
| 981 | * being handled. |
||
| 982 | * |
||
| 983 | * This is a convenient method to add an event handler. |
||
| 984 | * It is equivalent to {@link getEventHandlers}($name)->add($handler). |
||
| 985 | * For complete management of event handlers, use {@link getEventHandlers} |
||
| 986 | * to get the event handler list first, and then do various |
||
| 987 | * {@link TPriorityList} operations to append, insert or remove |
||
| 988 | * event handlers. You may also do these operations like |
||
| 989 | * getting and setting properties, e.g., |
||
| 990 | * <code> |
||
| 991 | * $component->OnClick[]=array($object,'buttonClicked'); |
||
| 992 | * $component->OnClick->insertAt(0,array($object,'buttonClicked')); |
||
| 993 | * </code> |
||
| 994 | * which are equivalent to the following |
||
| 995 | * <code> |
||
| 996 | * $component->getEventHandlers('OnClick')->add(array($object,'buttonClicked')); |
||
| 997 | * $component->getEventHandlers('OnClick')->insertAt(0,array($object,'buttonClicked')); |
||
| 998 | * </code> |
||
| 999 | * |
||
| 1000 | * Due to the nature of {@link getEventHandlers}, any active behaviors defining |
||
| 1001 | * new 'on' events, this method will pass through to the behavior transparently. |
||
| 1002 | * |
||
| 1003 | * @param string the event name |
||
| 1004 | * @param callback the event handler |
||
| 1005 | * @param numeric|null the priority of the handler, defaults to null which translates into the |
||
| 1006 | * default priority of 10.0 within {@link TPriorityList} |
||
| 1007 | * @throws TInvalidOperationException if the event does not exist |
||
| 1008 | */ |
||
| 1009 | public function attachEventHandler($name,$handler,$priority=null) |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * Detaches an existing event handler. |
||
| 1016 | * This method is the opposite of {@link attachEventHandler}. It will detach |
||
| 1017 | * any 'on' events definedb by an objects active behaviors as well. |
||
| 1018 | * @param string event name |
||
| 1019 | * @param callback the event handler to be removed |
||
| 1020 | * @param numeric|false|null the priority of the handler, defaults to false which translates |
||
| 1021 | * to an item of any priority within {@link TPriorityList}; null means the default priority |
||
| 1022 | * @return boolean if the removal is successful |
||
| 1023 | */ |
||
| 1024 | public function detachEventHandler($name,$handler,$priority=false) |
||
| 1039 | |||
| 1040 | /** |
||
| 1041 | * Raises an event. This raises both inter-object 'on' events and global 'fx' events. |
||
| 1042 | * This method represents the happening of an event and will |
||
| 1043 | * invoke all attached event handlers for the event in {@link TPriorityList} order. |
||
| 1044 | * This method does not handle intra-object/behavior dynamic 'dy' events. |
||
| 1045 | * |
||
| 1046 | * There are ways to handle event responses. By defailt {@link EVENT_RESULT_FILTER}, |
||
| 1047 | * all event responses are stored in an array, filtered for null responses, and returned. |
||
| 1048 | * If {@link EVENT_RESULT_ALL} is specified, all returned results will be stored along |
||
| 1049 | * with the sender and param in an array |
||
| 1050 | * <code> |
||
| 1051 | * $result[] = array('sender'=>$sender,'param'=>$param,'response'=>$response); |
||
| 1052 | * </code> |
||
| 1053 | * |
||
| 1054 | * If {@link EVENT_RESULT_FEED_FORWARD} is specified, then each handler result is then |
||
| 1055 | * fed forward as the parameters for the next event. This allows for events to filter data |
||
| 1056 | * directly by affecting the event parameters |
||
| 1057 | * |
||
| 1058 | * If a callable function is set in the response type or the post function filter is specified then the |
||
| 1059 | * result of each called event handler is post processed by the callable function. Used in |
||
| 1060 | * combination with {@link EVENT_RESULT_FEED_FORWARD}, any event (and its result) can be chained. |
||
| 1061 | * |
||
| 1062 | * When raising a global 'fx' event, registered handlers in the global event list for |
||
| 1063 | * {@link GLOBAL_RAISE_EVENT_LISTENER} are always added into the set of event handlers. In this way, |
||
| 1064 | * these global events are always raised for every global 'fx' event. The registered handlers for global |
||
| 1065 | * raiseEvent events have priorities. Any registered global raiseEvent event handlers with a priority less than zero |
||
| 1066 | * are added before the main event handlers being raised and any registered global raiseEvent event handlers |
||
| 1067 | * with a priority equal or greater than zero are added after the main event handlers being raised. In this way |
||
| 1068 | * all {@link GLOBAL_RAISE_EVENT_LISTENER} handlers are always called for every raised 'fx' event. |
||
| 1069 | * |
||
| 1070 | * Behaviors may implement the following functions: |
||
| 1071 | * <code> |
||
| 1072 | * public function dyPreRaiseEvent($name,$sender,$param,$responsetype,$postfunction[, $chain]) { |
||
| 1073 | * return $name; //eg, the event name may be filtered/changed |
||
| 1074 | * } |
||
| 1075 | * public function dyIntraRaiseEventTestHandler($handler,$sender,$param,$name[, $chain]) { |
||
| 1076 | * return true; //should this particular handler be executed? true/false |
||
| 1077 | * } |
||
| 1078 | * public function dyIntraRaiseEventPostHandler($name,$sender,$param,$handler,$response[, $chain]) { |
||
| 1079 | * //contains the per handler response |
||
| 1080 | * } |
||
| 1081 | * public function dyPostRaiseEvent($responses,$name,$sender,$param,$responsetype,$postfunction[, $chain]) { |
||
| 1082 | * return $responses; |
||
| 1083 | * } |
||
| 1084 | * </code> |
||
| 1085 | * to be executed when raiseEvent is called. The 'intra' dynamic events are called per handler in |
||
| 1086 | * the handler loop. |
||
| 1087 | * |
||
| 1088 | * dyPreRaiseEvent has the effect of being able to change the event being raised. This intra |
||
| 1089 | * object/behavior event returns the name of the desired event to be raised. It will pass through |
||
| 1090 | * if no dynamic event is specified, or if the original event name is returned. |
||
| 1091 | * dyIntraRaiseEventTestHandler returns true or false as to whether a specific handler should be |
||
| 1092 | * called for a specific raised event (and associated event arguments) |
||
| 1093 | * dyIntraRaiseEventPostHandler does not return anything. This allows behaviors to access the results |
||
| 1094 | * of an event handler in the per handler loop. |
||
| 1095 | * dyPostRaiseEvent returns the responses. This allows for any post processing of the event |
||
| 1096 | * results from the sum of all event handlers |
||
| 1097 | * |
||
| 1098 | * When handling a catch-all {@link __dycall}, the method name is the name of the event |
||
| 1099 | * and the parameters are the sender, the param, and then the name of the event. |
||
| 1100 | * |
||
| 1101 | * @param string the event name |
||
| 1102 | * @param mixed the event sender object |
||
| 1103 | * @param TEventParameter the event parameter |
||
| 1104 | * @param numeric how the results of the event are tabulated. default: {@link EVENT_RESULT_FILTER} The default filters out |
||
| 1105 | * null responses. optional |
||
| 1106 | * @param function any per handler filtering of the response result needed is passed through |
||
| 1107 | * this if not null. default: null. optional |
||
| 1108 | * @return mixed the results of the event |
||
| 1109 | * @throws TInvalidOperationException if the event is undefined |
||
| 1110 | * @throws TInvalidDataValueException If an event handler is invalid |
||
| 1111 | */ |
||
| 1112 | public function raiseEvent($name,$sender,$param,$responsetype=null,$postfunction=null) |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Evaluates a PHP expression in the context of this control. |
||
| 1217 | * |
||
| 1218 | * Behaviors may implement the function: |
||
| 1219 | * <code> |
||
| 1220 | * public function dyEvaluateExpressionFilter($expression, $chain) { |
||
| 1221 | * return $chain->dyEvaluateExpressionFilter(str_replace('foo', 'bar', $expression)); //example |
||
| 1222 | * } |
||
| 1223 | * </code> |
||
| 1224 | * to be executed when evaluateExpression is called. All attached behaviors are notified through |
||
| 1225 | * dyEvaluateExpressionFilter. The chaining is important in this function due to the filtering |
||
| 1226 | * pass-through effect. |
||
| 1227 | * |
||
| 1228 | * @param string PHP expression |
||
| 1229 | * @return mixed the expression result |
||
| 1230 | * @throws TInvalidOperationException if the expression is invalid |
||
| 1231 | */ |
||
| 1232 | public function evaluateExpression($expression) |
||
| 1246 | |||
| 1247 | /** |
||
| 1248 | * Evaluates a list of PHP statements. |
||
| 1249 | * |
||
| 1250 | * Behaviors may implement the function: |
||
| 1251 | * <code> |
||
| 1252 | * public function dyEvaluateStatementsFilter($statements, $chain) { |
||
| 1253 | * return $chain->dyEvaluateStatementsFilter(str_replace('foo', 'bar', $statements)); //example |
||
| 1254 | * } |
||
| 1255 | * </code> |
||
| 1256 | * to be executed when evaluateStatements is called. All attached behaviors are notified through |
||
| 1257 | * dyEvaluateStatementsFilter. The chaining is important in this function due to the filtering |
||
| 1258 | * pass-through effect. |
||
| 1259 | * |
||
| 1260 | * @param string PHP statements |
||
| 1261 | * @return string content echoed or printed by the PHP statements |
||
| 1262 | * @throws TInvalidOperationException if the statements are invalid |
||
| 1263 | */ |
||
| 1264 | public function evaluateStatements($statements) |
||
| 1281 | |||
| 1282 | /** |
||
| 1283 | * This method is invoked after the component is instantiated by a template. |
||
| 1284 | * When this method is invoked, the component's properties have been initialized. |
||
| 1285 | * The default implementation of this method will invoke |
||
| 1286 | * the potential parent component's {@link addParsedObject}. |
||
| 1287 | * This method can be overridden. |
||
| 1288 | * |
||
| 1289 | * Behaviors may implement the function: |
||
| 1290 | * <code> |
||
| 1291 | * public function dyCreatedOnTemplate($parent, $chain) { |
||
| 1292 | * return $chain->dyCreatedOnTemplate($parent); //example |
||
| 1293 | * } |
||
| 1294 | * </code> |
||
| 1295 | * to be executed when createdOnTemplate is called. All attached behaviors are notified through |
||
| 1296 | * dyCreatedOnTemplate. |
||
| 1297 | * |
||
| 1298 | * @param TComponent potential parent of this control |
||
| 1299 | * @see addParsedObject |
||
| 1300 | */ |
||
| 1301 | public function createdOnTemplate($parent) |
||
| 1306 | |||
| 1307 | /** |
||
| 1308 | * Processes an object that is created during parsing template. |
||
| 1309 | * The object can be either a component or a static text string. |
||
| 1310 | * This method can be overridden to customize the handling of newly created objects in template. |
||
| 1311 | * Only framework developers and control developers should use this method. |
||
| 1312 | * |
||
| 1313 | * Behaviors may implement the function: |
||
| 1314 | * <code> |
||
| 1315 | * public function dyAddParsedObject($object[, $chain]) { |
||
| 1316 | * } |
||
| 1317 | * </code> |
||
| 1318 | * to be executed when addParsedObject is called. All attached behaviors are notified through |
||
| 1319 | * dyAddParsedObject. |
||
| 1320 | * |
||
| 1321 | * @param string|TComponent text string or component parsed and instantiated in template |
||
| 1322 | * @see createdOnTemplate |
||
| 1323 | */ |
||
| 1324 | public function addParsedObject($object) |
||
| 1328 | |||
| 1329 | |||
| 1330 | /** |
||
| 1331 | * This is the method registered for all instanced objects should a class behavior be added after |
||
| 1332 | * the class is instanced. Only when the class to which the behavior is being added is in this |
||
| 1333 | * object's class hierarchy, via {@link getClassHierarchy}, is the behavior added to this instance. |
||
| 1334 | * @param $sender the application |
||
| 1335 | * @param $param TClassBehaviorEventParameter |
||
| 1336 | * @since 3.2.3 |
||
| 1337 | */ |
||
| 1338 | public function fxAttachClassBehavior($sender,$param) { |
||
| 1342 | |||
| 1343 | |||
| 1344 | /** |
||
| 1345 | * This is the method registered for all instanced objects should a class behavior be removed after |
||
| 1346 | * the class is instanced. Only when the class to which the behavior is being added is in this |
||
| 1347 | * object's class hierarchy, via {@link getClassHierarchy}, is the behavior removed from this instance. |
||
| 1348 | * @param $sender the application |
||
| 1349 | * @param $param TClassBehaviorEventParameter |
||
| 1350 | * @since 3.2.3 |
||
| 1351 | */ |
||
| 1352 | public function fxDetachClassBehavior($sender,$param) { |
||
| 1356 | |||
| 1357 | |||
| 1358 | /** |
||
| 1359 | * This will add a class behavior to all classes instanced (that are listening) and future newly instanced objects. |
||
| 1360 | * This registers the behavior for future instances and pushes the changes to all the instances that are listening as well. |
||
| 1361 | * The universal class behaviors are stored in an inverted stack with the latest class behavior being at the first position in the array. |
||
| 1362 | * This is done so class behaviors are added last first. |
||
| 1363 | * @param string name the key of the class behavior |
||
| 1364 | * @param object|string class behavior or name of the object behavior per instance |
||
| 1365 | * @param string|class string of class or class on which to attach this behavior. Defaults to null which will error |
||
| 1366 | * but more important, if this is on PHP 5.3 it will use Late Static Binding to derive the class |
||
| 1367 | * it should extend. |
||
| 1368 | * <code> |
||
| 1369 | * TPanel::attachClassBehavior('javascripts', (new TJsPanelBehavior())->init($this)); |
||
| 1370 | * </code> |
||
| 1371 | * @param numeric|null priority of behavior, default: null the default priority of the {@link TPriorityList} Optional. |
||
| 1372 | * @throws TInvalidOperationException if the class behavior is being added to a {@link TComponent}; due to recursion. |
||
| 1373 | * @throws TInvalidOperationException if the class behavior is already defined |
||
| 1374 | * @since 3.2.3 |
||
| 1375 | */ |
||
| 1376 | public static function attachClassBehavior($name,$behavior,$class=null,$priority=null) { |
||
| 1396 | |||
| 1397 | |||
| 1398 | /** |
||
| 1399 | * This will remove a behavior from a class. It unregisters it from future instances and |
||
| 1400 | * pulls the changes from all the instances that are listening as well. |
||
| 1401 | * PHP 5.3 uses Late Static Binding to derive the static class upon which this method is called. |
||
| 1402 | * @param $name the key of the class behavior |
||
| 1403 | * @param $class string class on which to attach this behavior. Defaults to null. |
||
| 1404 | * @param $priority numeric|null|false priority. false is any priority, null is default |
||
| 1405 | * {@link TPriorityList} priority, and numeric is a specific priority. |
||
| 1406 | * @throws Exception if the the class cannot be derived from Late Static Binding and is not |
||
| 1407 | * not supplied as a parameter. |
||
| 1408 | * @since 3.2.3 |
||
| 1409 | */ |
||
| 1410 | public static function detachClassBehavior($name,$class=null,$priority=false) { |
||
| 1427 | |||
| 1428 | /** |
||
| 1429 | * Returns the named behavior object. |
||
| 1430 | * The name 'asa' stands for 'as a'. |
||
| 1431 | * @param string the behavior name |
||
| 1432 | * @return IBehavior the behavior object, or null if the behavior does not exist |
||
| 1433 | * @since 3.2.3 |
||
| 1434 | */ |
||
| 1435 | public function asa($behaviorname) |
||
| 1439 | |||
| 1440 | /** |
||
| 1441 | * Returns whether or not the object or any of the behaviors are of a particular class. |
||
| 1442 | * The name 'isa' stands for 'is a'. This first checks if $this is an instanceof the class. |
||
| 1443 | * It then checks each Behavior. If a behavior implements {@link IInstanceCheck}, |
||
| 1444 | * then the behavior can determine what it is an instanceof. If this behavior function returns true, |
||
| 1445 | * then this method returns true. If the behavior instance checking function returns false, |
||
| 1446 | * then no further checking is performed as it is assumed to be correct. |
||
| 1447 | * |
||
| 1448 | * If the behavior instance check function returns nothing or null or the behavior |
||
| 1449 | * doesn't implement the {@link IInstanceCheck} interface, then the default instanceof occurs. |
||
| 1450 | * The default isa behavior is to check if the behavior is an instanceof the class. |
||
| 1451 | * |
||
| 1452 | * The behavior {@link IInstanceCheck} is to allow a behavior to have the host object |
||
| 1453 | * act as a completely different object. |
||
| 1454 | * |
||
| 1455 | * @param class or string |
||
| 1456 | * @return boolean whether or not the object or a behavior is an instance of a particular class |
||
| 1457 | * @since 3.2.3 |
||
| 1458 | */ |
||
| 1459 | public function isa($class) |
||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * Attaches a list of behaviors to the component. |
||
| 1479 | * Each behavior is indexed by its name and should be an instance of |
||
| 1480 | * {@link IBehavior}, a string specifying the behavior class, or a |
||
| 1481 | * {@link TClassBehaviorEventParameter}. |
||
| 1482 | * @param array list of behaviors to be attached to the component |
||
| 1483 | * @since 3.2.3 |
||
| 1484 | */ |
||
| 1485 | public function attachBehaviors($behaviors) |
||
| 1493 | |||
| 1494 | /** |
||
| 1495 | * Detaches select behaviors from the component. |
||
| 1496 | * Each behavior is indexed by its name and should be an instance of |
||
| 1497 | * {@link IBehavior}, a string specifying the behavior class, or a |
||
| 1498 | * {@link TClassBehaviorEventParameter}. |
||
| 1499 | * @param array list of behaviors to be detached from the component |
||
| 1500 | * @since 3.2.3 |
||
| 1501 | */ |
||
| 1502 | public function detachBehaviors($behaviors) |
||
| 1513 | |||
| 1514 | /** |
||
| 1515 | * Detaches all behaviors from the component. |
||
| 1516 | * @since 3.2.3 |
||
| 1517 | */ |
||
| 1518 | public function clearBehaviors() |
||
| 1527 | |||
| 1528 | /** |
||
| 1529 | * Attaches a behavior to this component. |
||
| 1530 | * This method will create the behavior object based on the given |
||
| 1531 | * configuration. After that, the behavior object will be initialized |
||
| 1532 | * by calling its {@link IBehavior::attach} method. |
||
| 1533 | * |
||
| 1534 | * Already attached behaviors may implement the function: |
||
| 1535 | * <code> |
||
| 1536 | * public function dyAttachBehavior($name,$behavior[, $chain]) { |
||
| 1537 | * } |
||
| 1538 | * </code> |
||
| 1539 | * to be executed when attachBehavior is called. All attached behaviors are notified through |
||
| 1540 | * dyAttachBehavior. |
||
| 1541 | * |
||
| 1542 | * @param string the behavior's name. It should uniquely identify this behavior. |
||
| 1543 | * @param mixed the behavior configuration. This is passed as the first |
||
| 1544 | * parameter to {@link YiiBase::createComponent} to create the behavior object. |
||
| 1545 | * @return IBehavior the behavior object |
||
| 1546 | * @since 3.2.3 |
||
| 1547 | */ |
||
| 1548 | public function attachBehavior($name,$behavior,$priority=null) |
||
| 1563 | |||
| 1564 | /** |
||
| 1565 | * Detaches a behavior from the component. |
||
| 1566 | * The behavior's {@link IBehavior::detach} method will be invoked. |
||
| 1567 | * |
||
| 1568 | * Behaviors may implement the function: |
||
| 1569 | * <code> |
||
| 1570 | * public function dyDetachBehavior($name,$behavior[, $chain]) { |
||
| 1571 | * } |
||
| 1572 | * </code> |
||
| 1573 | * to be executed when detachBehavior is called. All attached behaviors are notified through |
||
| 1574 | * dyDetachBehavior. |
||
| 1575 | * |
||
| 1576 | * @param string the behavior's name. It uniquely identifies the behavior. |
||
| 1577 | * @param numeric the behavior's priority. This defaults to false, aka any priority. |
||
| 1578 | * @return IBehavior the detached behavior. Null if the behavior does not exist. |
||
| 1579 | * @since 3.2.3 |
||
| 1580 | */ |
||
| 1581 | public function detachBehavior($name,$priority=false) |
||
| 1592 | |||
| 1593 | /** |
||
| 1594 | * Enables all behaviors attached to this component independent of the behaviors |
||
| 1595 | * |
||
| 1596 | * Behaviors may implement the function: |
||
| 1597 | * <code> |
||
| 1598 | * public function dyEnableBehaviors($name,$behavior[, $chain]) { |
||
| 1599 | * } |
||
| 1600 | * </code> |
||
| 1601 | * to be executed when enableBehaviors is called. All attached behaviors are notified through |
||
| 1602 | * dyEnableBehaviors. |
||
| 1603 | * @since 3.2.3 |
||
| 1604 | */ |
||
| 1605 | public function enableBehaviors() |
||
| 1613 | |||
| 1614 | /** |
||
| 1615 | * Disables all behaviors attached to this component independent of the behaviors |
||
| 1616 | * |
||
| 1617 | * Behaviors may implement the function: |
||
| 1618 | * <code> |
||
| 1619 | * public function dyDisableBehaviors($name,$behavior[, $chain]) { |
||
| 1620 | * } |
||
| 1621 | * </code> |
||
| 1622 | * to be executed when disableBehaviors is called. All attached behaviors are notified through |
||
| 1623 | * dyDisableBehaviors. |
||
| 1624 | * @since 3.2.3 |
||
| 1625 | */ |
||
| 1626 | public function disableBehaviors() |
||
| 1634 | |||
| 1635 | |||
| 1636 | /** |
||
| 1637 | * Returns if all the behaviors are turned on or off for the object. |
||
| 1638 | * @return boolean whether or not all behaviors are enabled (true) or not (false) |
||
| 1639 | * @since 3.2.3 |
||
| 1640 | */ |
||
| 1641 | public function getBehaviorsEnabled() |
||
| 1645 | |||
| 1646 | /** |
||
| 1647 | * Enables an attached object behavior. This cannot enable or disable whole class behaviors. |
||
| 1648 | * A behavior is only effective when it is enabled. |
||
| 1649 | * A behavior is enabled when first attached. |
||
| 1650 | * |
||
| 1651 | * Behaviors may implement the function: |
||
| 1652 | * <code> |
||
| 1653 | * public function dyEnableBehavior($name,$behavior[, $chain]) { |
||
| 1654 | * } |
||
| 1655 | * </code> |
||
| 1656 | * to be executed when enableBehavior is called. All attached behaviors are notified through |
||
| 1657 | * dyEnableBehavior. |
||
| 1658 | * |
||
| 1659 | * @param string the behavior's name. It uniquely identifies the behavior. |
||
| 1660 | * @since 3.2.3 |
||
| 1661 | */ |
||
| 1662 | public function enableBehavior($name) |
||
| 1674 | |||
| 1675 | /** |
||
| 1676 | * Disables an attached behavior. This cannot enable or disable whole class behaviors. |
||
| 1677 | * A behavior is only effective when it is enabled. |
||
| 1678 | * |
||
| 1679 | * Behaviors may implement the function: |
||
| 1680 | * <code> |
||
| 1681 | * public function dyDisableBehavior($name,$behavior[, $chain]) { |
||
| 1682 | * } |
||
| 1683 | * </code> |
||
| 1684 | * to be executed when disableBehavior is called. All attached behaviors are notified through |
||
| 1685 | * dyDisableBehavior. |
||
| 1686 | * |
||
| 1687 | * @param string the behavior's name. It uniquely identifies the behavior. |
||
| 1688 | * @since 3.2.3 |
||
| 1689 | */ |
||
| 1690 | public function disableBehavior($name) |
||
| 1702 | |||
| 1703 | /** |
||
| 1704 | * Returns an array with the names of all variables of that object that should be serialized. |
||
| 1705 | * Do not call this method. This is a PHP magic method that will be called automatically |
||
| 1706 | * prior to any serialization. |
||
| 1707 | */ |
||
| 1708 | public function __sleep() |
||
| 1716 | |||
| 1717 | /** |
||
| 1718 | * Returns an array with the names of all variables of this object that should NOT be serialized |
||
| 1719 | * because their value is the default one or useless to be cached for the next page loads. |
||
| 1720 | * Reimplement in derived classes to add new variables, but remember to also to call the parent |
||
| 1721 | * implementation first. |
||
| 1722 | */ |
||
| 1723 | protected function _getZappableSleepProps(&$exprops) |
||
| 1734 | } |
||
| 1735 | |||
| 2410 |
This check looks for method names that are not written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes
databaseConnectionSeeker.