Complex classes like Controller 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 Controller, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 68 | abstract class Controller |
||
| 69 | { |
||
| 70 | /** |
||
| 71 | * The name of the controller. |
||
| 72 | * |
||
| 73 | * @var string |
||
| 74 | * |
||
| 75 | * @since 1.0 |
||
| 76 | */ |
||
| 77 | protected $name; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Used to set access privileages for the controller to the name of the rights group |
||
| 81 | * allowed to access it. 'Public' by default. |
||
| 82 | * |
||
| 83 | * @var string |
||
| 84 | * |
||
| 85 | * @since 1.0 |
||
| 86 | */ |
||
| 87 | protected $visibility = 'Public'; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Optionally, the main record object that this controller is currently working with. |
||
| 91 | * |
||
| 92 | * @var \Alpha\Model\ActiveRecord |
||
| 93 | * |
||
| 94 | * @since 1.0 |
||
| 95 | */ |
||
| 96 | protected $record = null; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Used to determine if the controller is part of a unit of work sequence |
||
| 100 | * (either empty or the name of the unit). |
||
| 101 | * |
||
| 102 | * @var string |
||
| 103 | * |
||
| 104 | * @since 1.0 |
||
| 105 | */ |
||
| 106 | protected $unitOfWork; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Stores the start time of a unit of work transaction. |
||
| 110 | * |
||
| 111 | * @var \Alpha\Model\Type\Timestamp |
||
| 112 | * |
||
| 113 | * @since 1.0 |
||
| 114 | */ |
||
| 115 | protected $unitStartTime; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Stores the end time of a unit of work transaction. |
||
| 119 | * |
||
| 120 | * @var \Alpha\Model\Type\Timestamp |
||
| 121 | * |
||
| 122 | * @since 1.0 |
||
| 123 | */ |
||
| 124 | protected $unitEndTime; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Stores the maximum allowed time duration (in seconds) of the unit of work. |
||
| 128 | * |
||
| 129 | * @var \Alpha\Model\Type\Integer |
||
| 130 | * |
||
| 131 | * @since 1.0 |
||
| 132 | */ |
||
| 133 | protected $unitMAXDuration; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * The name of the first controller that is used in this unit of work. |
||
| 137 | * |
||
| 138 | * @var string |
||
| 139 | * |
||
| 140 | * @since 1.0 |
||
| 141 | */ |
||
| 142 | protected $firstJob; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * The name of the next controller that is used in this unit of work. |
||
| 146 | * |
||
| 147 | * @var string |
||
| 148 | * |
||
| 149 | * @since 1.0 |
||
| 150 | */ |
||
| 151 | protected $nextJob; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * The name of the previous controller that is used in this unit of work. |
||
| 155 | * |
||
| 156 | * @var string |
||
| 157 | * |
||
| 158 | * @since 1.0 |
||
| 159 | */ |
||
| 160 | protected $previousJob; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * The name of the last controller that is used in this unit of work. |
||
| 164 | * |
||
| 165 | * @var string |
||
| 166 | * |
||
| 167 | * @since 1.0 |
||
| 168 | */ |
||
| 169 | protected $lastJob; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * An array for storing dirty record objects in a session (i.e. persistent business |
||
| 173 | * objects that have not been updated in the database yet). |
||
| 174 | * |
||
| 175 | * @var array |
||
| 176 | * |
||
| 177 | * @since 1.0 |
||
| 178 | */ |
||
| 179 | protected $dirtyObjects = array(); |
||
| 180 | |||
| 181 | /** |
||
| 182 | * An array for storing new reord objects in a session (transient business objects that |
||
| 183 | * have no ID yet). |
||
| 184 | * |
||
| 185 | * @var array |
||
| 186 | * |
||
| 187 | * @since 1.0 |
||
| 188 | */ |
||
| 189 | protected $newObjects = array(); |
||
| 190 | |||
| 191 | /** |
||
| 192 | * The title to be displayed on the controller page. |
||
| 193 | * |
||
| 194 | * @var string |
||
| 195 | * |
||
| 196 | * @since 1.0 |
||
| 197 | */ |
||
| 198 | protected $title; |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Meta keywords for the controller page, generally populated from tags. |
||
| 202 | * |
||
| 203 | * @var string |
||
| 204 | * |
||
| 205 | * @since 1.0 |
||
| 206 | */ |
||
| 207 | protected $keywords; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Meta description for the controller page. |
||
| 211 | * |
||
| 212 | * @var string |
||
| 213 | * |
||
| 214 | * @since 1.0 |
||
| 215 | */ |
||
| 216 | protected $description; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Used to set status update messages to display to the user (messages stored between requests |
||
| 220 | * in session). Useful for when you want to display a message to a user after POSTing a request, |
||
| 221 | * or when moving from one page to the next. |
||
| 222 | * |
||
| 223 | * @var string |
||
| 224 | * |
||
| 225 | * @since 1.0 |
||
| 226 | */ |
||
| 227 | protected $statusMessage; |
||
| 228 | |||
| 229 | /** |
||
| 230 | * The request that has been passed to this controller for processing. |
||
| 231 | * |
||
| 232 | * @var \Alpha\Util\Http\Request |
||
| 233 | * |
||
| 234 | * @since 2.0 |
||
| 235 | */ |
||
| 236 | protected $request; |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Trace logger. |
||
| 240 | * |
||
| 241 | * @var \Alpha\Util\Logging\Logger |
||
| 242 | * |
||
| 243 | * @since 1.0 |
||
| 244 | */ |
||
| 245 | private static $logger = null; |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Constructor for the Controller that starts a new session if required, and handles |
||
| 249 | * the population of new/dirty objects from the session when available. Accepts the name |
||
| 250 | * of the rights group that has access to this controller, 'Public' by default. |
||
| 251 | * |
||
| 252 | * @param string $visibility The name of the rights group that can access this controller. |
||
| 253 | * |
||
| 254 | * @since 1.0 |
||
| 255 | */ |
||
| 256 | public function __construct($visibility = 'Public') |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Get the record for this controller (if any). |
||
| 299 | * |
||
| 300 | * @return ActiveRecord |
||
| 301 | * |
||
| 302 | * @since 1.0 |
||
| 303 | */ |
||
| 304 | public function getRecord() |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Setter for the record for this controller. |
||
| 314 | * |
||
| 315 | * @param \Alpha\Model\ActiveRecord $record |
||
| 316 | * |
||
| 317 | * @since 1.0 |
||
| 318 | */ |
||
| 319 | public function setRecord($record) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Get the name of the unit of work job. |
||
| 344 | * |
||
| 345 | * @return string |
||
| 346 | * |
||
| 347 | * @since 1.0 |
||
| 348 | */ |
||
| 349 | public function getName() |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Setter for the unit of work job name. |
||
| 359 | * |
||
| 360 | * @param string $name The fully-qualified controller class name, or an absolute URL. |
||
| 361 | * |
||
| 362 | * @since 1.0 |
||
| 363 | */ |
||
| 364 | public function setName($name) |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Get the name of the rights group that has access to this controller. |
||
| 373 | * |
||
| 374 | * @return string |
||
| 375 | * |
||
| 376 | * @since 1.0 |
||
| 377 | */ |
||
| 378 | public function getVisibility() |
||
| 385 | |||
| 386 | /** |
||
| 387 | * Setter for the name of the rights group that has access to this controller. |
||
| 388 | * |
||
| 389 | * @param string $visibility |
||
| 390 | * |
||
| 391 | * @since 1.0 |
||
| 392 | */ |
||
| 393 | public function setVisibility($visibility) |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Gets the name of the first job in this unit of work. |
||
| 402 | * |
||
| 403 | * @return string The fully-qualified controller class name, or an absolute URL. |
||
| 404 | * |
||
| 405 | * @since 1.0 |
||
| 406 | */ |
||
| 407 | public function getFirstJob() |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Gets the name of the next job in this unit of work. |
||
| 417 | * |
||
| 418 | * @return string The fully-qualified controller class name, or an absolute URL. |
||
| 419 | * |
||
| 420 | * @since 1.0 |
||
| 421 | */ |
||
| 422 | public function getNextJob() |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Gets the name of the previous job in this unit of work. |
||
| 432 | * |
||
| 433 | * @return string The fully-qualified controller class name, or an absolute URL. |
||
| 434 | * |
||
| 435 | * @since 1.0 |
||
| 436 | */ |
||
| 437 | public function getPreviousJob() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Gets the name of the last job in this unit of work. |
||
| 447 | * |
||
| 448 | * @return string The fully-qualified controller class name, or an absolute URL. |
||
| 449 | * |
||
| 450 | * @since 1.0 |
||
| 451 | */ |
||
| 452 | public function getLastJob() |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Sets the name of the controller job sequence to the values in the supplied |
||
| 462 | * array (and stores the array in the session). |
||
| 463 | * |
||
| 464 | * @param array $jobs The names of the controllers in this unit of work sequence. Will accept fully-qualified controller class name, or an absolute URL. |
||
| 465 | * |
||
| 466 | * @throws \Alpha\Exception\IllegalArguementException |
||
| 467 | * |
||
| 468 | * @since 1.0 |
||
| 469 | */ |
||
| 470 | public function setUnitOfWork($jobs) |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Getter for the unit start time. |
||
| 548 | * |
||
| 549 | * @return Timestamp |
||
| 550 | * |
||
| 551 | * @since 1.0 |
||
| 552 | */ |
||
| 553 | public function getStartTime() |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Setter for the unit start time (value will be stored in the session as key unitStartTime). |
||
| 563 | * |
||
| 564 | * @param int $year |
||
| 565 | * @param int $month |
||
| 566 | * @param int $day |
||
| 567 | * @param int $hour |
||
| 568 | * @param int $minute |
||
| 569 | * @param int $second |
||
| 570 | * |
||
| 571 | * @since 1.0 |
||
| 572 | */ |
||
| 573 | public function setUnitStartTime($year, $month, $day, $hour, $minute, $second) |
||
| 587 | |||
| 588 | /** |
||
| 589 | * Getter for the unit end time. |
||
| 590 | * |
||
| 591 | * @return \Alpha\Model\Type\Timestamp |
||
| 592 | * |
||
| 593 | * @since 1.0 |
||
| 594 | */ |
||
| 595 | public function getEndTime() |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Setter for the unit end time (value will be stored in the session as key unitEndTime). |
||
| 605 | * |
||
| 606 | * @param int $year |
||
| 607 | * @param int $month |
||
| 608 | * @param int $day |
||
| 609 | * @param int $hour |
||
| 610 | * @param int $minute |
||
| 611 | * @param int $second |
||
| 612 | * |
||
| 613 | * @since 1.0 |
||
| 614 | */ |
||
| 615 | public function setUnitEndTime($year, $month, $day, $hour, $minute, $second) |
||
| 629 | |||
| 630 | /** |
||
| 631 | * Getter for the unit of work MAX duration. |
||
| 632 | * |
||
| 633 | * @return Integer |
||
| 634 | * |
||
| 635 | * @since 1.0 |
||
| 636 | */ |
||
| 637 | public function getMAXDuration() |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Setter for the unit MAX duration. |
||
| 647 | * |
||
| 648 | * @param int $duration The desired duration in seconds. |
||
| 649 | * |
||
| 650 | * @since 1.0 |
||
| 651 | */ |
||
| 652 | public function setUnitMAXDuration($duration) |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Calculates and returns the unit of work current duration in seconds. |
||
| 661 | * |
||
| 662 | * @return int |
||
| 663 | * |
||
| 664 | * @since 1.0 |
||
| 665 | */ |
||
| 666 | public function getUnitDuration() |
||
| 667 | { |
||
| 668 | self::$logger->debug('>>getUnitDuration()'); |
||
| 669 | |||
| 670 | $intStartTime = mktime( |
||
| 671 | intval($this->unitStartTime->getHour()), |
||
| 672 | intval($this->unitStartTime->getMinute()), |
||
| 673 | intval($this->unitStartTime->getSecond()), |
||
| 674 | intval($this->unitStartTime->getMonth()), |
||
| 675 | intval($this->unitStartTime->getDay()), |
||
| 676 | intval($this->unitStartTime->getYear()) |
||
| 677 | ); |
||
| 678 | |||
| 679 | $intEndTime = mktime( |
||
| 680 | intval($this->unitEndTime->getHour()), |
||
| 681 | intval($this->unitEndTime->getMinute()), |
||
| 682 | intval($this->unitEndTime->getSecond()), |
||
| 683 | intval($this->unitEndTime->getMonth()), |
||
| 684 | intval($this->unitEndTime->getDay()), |
||
| 685 | intval($this->unitEndTime->getYear()) |
||
| 686 | ); |
||
| 687 | |||
| 688 | self::$logger->debug('<<getUnitDuration ['.($intEndTime-$intStartTime).']'); |
||
| 689 | |||
| 690 | return $intEndTime-$intStartTime; |
||
| 691 | } |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Adds the supplied business object to the dirtyObjects array in the session. |
||
| 695 | * |
||
| 696 | * @param \Alpha\Model\ActiveRecord $object |
||
| 697 | * |
||
| 698 | * @since 1.0 |
||
| 699 | */ |
||
| 700 | public function markDirty($object) |
||
| 722 | |||
| 723 | /** |
||
| 724 | * Getter for the dirty objects array. |
||
| 725 | * |
||
| 726 | * @return array |
||
| 727 | * |
||
| 728 | * @since 1.0 |
||
| 729 | */ |
||
| 730 | public function getDirtyObjects() |
||
| 737 | |||
| 738 | /** |
||
| 739 | * Adds a newly created business object to the newObjects array in the session. |
||
| 740 | * |
||
| 741 | * @param \Alpha\Model\ActiveRecord $object |
||
| 742 | * |
||
| 743 | * @since 1.0 |
||
| 744 | */ |
||
| 745 | public function markNew($object) |
||
| 767 | |||
| 768 | /** |
||
| 769 | * Getter for the new objects array. |
||
| 770 | * |
||
| 771 | * @return array |
||
| 772 | * |
||
| 773 | * @since 1.0 |
||
| 774 | */ |
||
| 775 | public function getNewObjects() |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Commits (saves) all of the new and modified (dirty) objects in the unit of work to the database. |
||
| 785 | * |
||
| 786 | * @throws \Alpha\Exception\FailedUnitCommitException |
||
| 787 | * |
||
| 788 | * @since 1.0 |
||
| 789 | */ |
||
| 790 | public function commit() |
||
| 855 | |||
| 856 | /** |
||
| 857 | * Method to clearup a cancelled unit of work. |
||
| 858 | * |
||
| 859 | * @throws \Alpha\Exception\AlphaException |
||
| 860 | * |
||
| 861 | * @since 1.0 |
||
| 862 | */ |
||
| 863 | public function abort() |
||
| 886 | |||
| 887 | /** |
||
| 888 | * Clears the session and object attributes related to unit of work sessions. |
||
| 889 | * |
||
| 890 | * @since 1.0 |
||
| 891 | */ |
||
| 892 | public function clearUnitOfWorkAttributes() |
||
| 905 | |||
| 906 | /** |
||
| 907 | * Getter for the page title. |
||
| 908 | * |
||
| 909 | * @return string |
||
| 910 | * |
||
| 911 | * @since 1.0 |
||
| 912 | */ |
||
| 913 | public function getTitle() |
||
| 920 | |||
| 921 | /** |
||
| 922 | * Setter for the page title. |
||
| 923 | * |
||
| 924 | * @param string $title |
||
| 925 | * |
||
| 926 | * @since 1.0 |
||
| 927 | */ |
||
| 928 | public function setTitle($title) |
||
| 934 | |||
| 935 | /** |
||
| 936 | * Getter for the page description. |
||
| 937 | * |
||
| 938 | * @return string |
||
| 939 | * |
||
| 940 | * @since 1.0 |
||
| 941 | */ |
||
| 942 | public function getDescription() |
||
| 949 | |||
| 950 | /** |
||
| 951 | * Setter for the page description. |
||
| 952 | * |
||
| 953 | * @param string $description |
||
| 954 | * |
||
| 955 | * @since 1.0 |
||
| 956 | */ |
||
| 957 | public function setDescription($description) |
||
| 963 | |||
| 964 | /** |
||
| 965 | * Getter for the page keywords. |
||
| 966 | * |
||
| 967 | * @return string |
||
| 968 | * |
||
| 969 | * @since 1.0 |
||
| 970 | */ |
||
| 971 | public function getKeywords() |
||
| 978 | |||
| 979 | /** |
||
| 980 | * Setter for the page keywords, should pass a comma-seperated list as a string. |
||
| 981 | * |
||
| 982 | * @param string $keywords |
||
| 983 | * |
||
| 984 | * @since 1.0 |
||
| 985 | */ |
||
| 986 | public function setKeywords($keywords) |
||
| 992 | |||
| 993 | /** |
||
| 994 | * Method to return an access error for trespassing users. HTTP response header code will be 403. |
||
| 995 | * |
||
| 996 | * @return \Alpha\Util\Http\Response |
||
| 997 | * |
||
| 998 | * @since 1.0 |
||
| 999 | */ |
||
| 1000 | public function accessError() |
||
| 1030 | |||
| 1031 | /** |
||
| 1032 | * Checks the user rights of the currently logged-in person against the page |
||
| 1033 | * visibility set for this controller. Will return false if the user has |
||
| 1034 | * not got the correct rights. |
||
| 1035 | * |
||
| 1036 | * @return bool |
||
| 1037 | * |
||
| 1038 | * @since 1.0 |
||
| 1039 | */ |
||
| 1040 | public function checkRights() |
||
| 1041 | { |
||
| 1042 | self::$logger->debug('>>checkRights()'); |
||
| 1043 | |||
| 1044 | $config = ConfigProvider::getInstance(); |
||
| 1045 | |||
| 1046 | $sessionProvider = $config->get('session.provider.name'); |
||
| 1047 | $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
||
| 1048 | |||
| 1049 | if (method_exists($this, 'before_checkRights_callback')) { |
||
| 1050 | $this->{'before_checkRights_callback'}(); |
||
| 1051 | } |
||
| 1052 | |||
| 1053 | // firstly if the page is Public then there is no issue |
||
| 1054 | if ($this->getVisibility() == 'Public') { |
||
| 1055 | if (method_exists($this, 'after_checkRights_callback')) { |
||
| 1056 | $this->{'after_checkRights_callback'}(); |
||
| 1057 | } |
||
| 1058 | |||
| 1059 | self::$logger->debug('<<checkRights [true]'); |
||
| 1060 | |||
| 1061 | return true; |
||
| 1062 | } else { |
||
| 1063 | // the person is logged in? |
||
| 1064 | if ($session->get('currentUser') !== false) { |
||
| 1065 | |||
| 1066 | // if the visibility is 'Session', just being logged in enough |
||
| 1067 | if ($this->getVisibility() == 'Session') { |
||
| 1068 | if (method_exists($this, 'after_checkRights_callback')) { |
||
| 1069 | $this->{'after_checkRights_callback'}(); |
||
| 1070 | } |
||
| 1071 | |||
| 1072 | self::$logger->debug('<<checkRights [true]'); |
||
| 1073 | |||
| 1074 | return true; |
||
| 1075 | } |
||
| 1076 | |||
| 1077 | // checking for admins (can access everything) |
||
| 1078 | if ($session->get('currentUser')->inGroup('Admin')) { |
||
| 1079 | if (method_exists($this, 'after_checkRights_callback')) { |
||
| 1080 | $this->{'after_checkRights_callback'}(); |
||
| 1081 | } |
||
| 1082 | |||
| 1083 | self::$logger->debug('<<checkRights [true]'); |
||
| 1084 | |||
| 1085 | return true; |
||
| 1086 | } elseif ($session->get('currentUser')->inGroup($this->getVisibility())) { |
||
| 1087 | if (method_exists($this, 'after_checkRights_callback')) { |
||
| 1088 | $this->{'after_checkRights_callback'}(); |
||
| 1089 | } |
||
| 1090 | |||
| 1091 | self::$logger->debug('<<checkRights [true]'); |
||
| 1092 | |||
| 1093 | return true; |
||
| 1094 | // the person is editing their own profile which is allowed |
||
| 1095 | } elseif ((isset($this->record) && get_class($this->record) == 'Alpha\Model\Person') && $session->get('currentUser')->getUsername() == $this->record->getUsername()) { |
||
| 1096 | if (method_exists($this, 'after_checkRights_callback')) { |
||
| 1097 | $this->{'after_checkRights_callback'}(); |
||
| 1098 | } |
||
| 1099 | |||
| 1100 | self::$logger->debug('<<checkRights [true]'); |
||
| 1101 | |||
| 1102 | return true; |
||
| 1103 | } else { |
||
| 1104 | self::$logger->debug('<<checkRights [false]'); |
||
| 1105 | |||
| 1106 | return false; |
||
| 1107 | } |
||
| 1108 | } else { // the person is NOT logged in |
||
| 1109 | self::$logger->debug('<<checkRights [false]'); |
||
| 1110 | |||
| 1111 | return false; |
||
| 1112 | } |
||
| 1113 | } |
||
| 1114 | } |
||
| 1115 | |||
| 1116 | /** |
||
| 1117 | * Method to check the validity of the two hidden form security |
||
| 1118 | * fields which aim to ensure that a post to the controller is being sent from |
||
| 1119 | * the same server that is hosting it. |
||
| 1120 | * |
||
| 1121 | * @return bool |
||
| 1122 | * |
||
| 1123 | * @since 1.0 |
||
| 1124 | */ |
||
| 1125 | public function checkSecurityFields() |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Generates the two security fields to prevent remote form processing. |
||
| 1175 | * |
||
| 1176 | * @return string[] An array containing the two fields |
||
| 1177 | * |
||
| 1178 | * @since 1.0 |
||
| 1179 | */ |
||
| 1180 | public static function generateSecurityFields() |
||
| 1201 | |||
| 1202 | /** |
||
| 1203 | * Returns the name of a custom controller if one is found, otherwise returns null. |
||
| 1204 | * |
||
| 1205 | * @param string $ActiveRecordType The classname of the active record |
||
| 1206 | * |
||
| 1207 | * @return string |
||
| 1208 | * |
||
| 1209 | * @since 1.0 |
||
| 1210 | */ |
||
| 1211 | public static function getCustomControllerName($ActiveRecordType) |
||
| 1247 | |||
| 1248 | /** |
||
| 1249 | * Set the status message in the session to the value provided. |
||
| 1250 | * |
||
| 1251 | * @param string $message |
||
| 1252 | * |
||
| 1253 | * @since 1.0 |
||
| 1254 | */ |
||
| 1255 | public function setStatusMessage($message) |
||
| 1264 | |||
| 1265 | /** |
||
| 1266 | * Gets the current status message for this controller. Note that by getting the current |
||
| 1267 | * status message, you clear out the value stored in the session so this method can only be used |
||
| 1268 | * to get the status message once for display purposes. |
||
| 1269 | * |
||
| 1270 | * @return string |
||
| 1271 | * |
||
| 1272 | * @since 1.0 |
||
| 1273 | */ |
||
| 1274 | public function getStatusMessage() |
||
| 1284 | |||
| 1285 | /** |
||
| 1286 | * Checks that the definition for the controller classname provided exists. Will also return true |
||
| 1287 | * if you pass "/" for the root of the web application. |
||
| 1288 | * |
||
| 1289 | * @param string $controllerName |
||
| 1290 | * |
||
| 1291 | * @return bool |
||
| 1292 | * |
||
| 1293 | * @since 1.0 |
||
| 1294 | * @deprecated |
||
| 1295 | */ |
||
| 1296 | public static function checkControllerDefExists($controllerName) |
||
| 1321 | |||
| 1322 | /** |
||
| 1323 | * Loads the definition for the controller classname provided. |
||
| 1324 | * |
||
| 1325 | * @param string $controllerName |
||
| 1326 | * |
||
| 1327 | * @throws \Alpha\Exception\IllegalArguementException |
||
| 1328 | * |
||
| 1329 | * @since 1.0 |
||
| 1330 | */ |
||
| 1331 | public static function loadControllerDef($controllerName) |
||
| 1350 | |||
| 1351 | /** |
||
| 1352 | * Method for determining if the current request URL is a secure one (has a tk string or not). |
||
| 1353 | * |
||
| 1354 | * @return bool True if the current URL contains a tk value, false otherwise |
||
| 1355 | * |
||
| 1356 | * @since 1.0 |
||
| 1357 | */ |
||
| 1358 | public function checkIfAccessingFromSecureURL() |
||
| 1366 | |||
| 1367 | /** |
||
| 1368 | * Descrypts the HTTP param fieldnames in the array provided and returns the plain version. |
||
| 1369 | * |
||
| 1370 | * @param $params array |
||
| 1371 | * |
||
| 1372 | * @return array |
||
| 1373 | * |
||
| 1374 | * @since 1.2.2 |
||
| 1375 | */ |
||
| 1376 | private function decryptFieldNames($params) |
||
| 1390 | |||
| 1391 | /** |
||
| 1392 | * Converts the supplied string to a "slug" that is URL safe and suitable for SEO. |
||
| 1393 | * |
||
| 1394 | * @param string $URLPart The part of the URL to use as the slug |
||
| 1395 | * @param string $seperator The URL seperator to use (default is -) |
||
| 1396 | * @param array $filter An optional array of charactors to filter out |
||
| 1397 | * @param bool $crc32Prefix Set to true if you want to prefix the slug with the CRC32 hash of the URLPart supplied |
||
| 1398 | * |
||
| 1399 | * @return string A URL slug |
||
| 1400 | * |
||
| 1401 | * @since 1.2.4 |
||
| 1402 | */ |
||
| 1403 | public static function generateURLSlug($URLPart, $seperator = '-', $filter = array(), $crc32Prefix = false) |
||
| 1422 | |||
| 1423 | /** |
||
| 1424 | * {@inheritdoc} |
||
| 1425 | * |
||
| 1426 | * @since 2.0 |
||
| 1427 | * |
||
| 1428 | * @throws \Alpha\Exception\NotImplementedException |
||
| 1429 | * @param Request $request |
||
| 1430 | */ |
||
| 1431 | public function doHEAD($request) |
||
| 1436 | |||
| 1437 | /** |
||
| 1438 | * {@inheritdoc} |
||
| 1439 | * |
||
| 1440 | * @since 2.0 |
||
| 1441 | * |
||
| 1442 | * @throws \Alpha\Exception\NotImplementedException |
||
| 1443 | * @param Request $request |
||
| 1444 | */ |
||
| 1445 | public function doGET($request) |
||
| 1450 | |||
| 1451 | /** |
||
| 1452 | * {@inheritdoc} |
||
| 1453 | * |
||
| 1454 | * @since 2.0 |
||
| 1455 | * |
||
| 1456 | * @throws \Alpha\Exception\NotImplementedException |
||
| 1457 | * @param Request $request |
||
| 1458 | */ |
||
| 1459 | public function doPOST($request) |
||
| 1464 | |||
| 1465 | /** |
||
| 1466 | * {@inheritdoc} |
||
| 1467 | * |
||
| 1468 | * @since 2.0 |
||
| 1469 | * |
||
| 1470 | * @throws \Alpha\Exception\NotImplementedException |
||
| 1471 | * @param Request $request |
||
| 1472 | */ |
||
| 1473 | public function doPUT($request) |
||
| 1478 | |||
| 1479 | /** |
||
| 1480 | * {@inheritdoc} |
||
| 1481 | * |
||
| 1482 | * @since 2.0 |
||
| 1483 | * |
||
| 1484 | * @throws \Alpha\Exception\NotImplementedException |
||
| 1485 | * @param Request $request |
||
| 1486 | */ |
||
| 1487 | public function doPATCH($request) |
||
| 1492 | |||
| 1493 | /** |
||
| 1494 | * {@inheritdoc} |
||
| 1495 | * |
||
| 1496 | * @since 2.0 |
||
| 1497 | * |
||
| 1498 | * @throws \Alpha\Exception\NotImplementedException |
||
| 1499 | * @param Request $request |
||
| 1500 | */ |
||
| 1501 | public function doDELETE($request) |
||
| 1506 | |||
| 1507 | /** |
||
| 1508 | * {@inheritdoc} |
||
| 1509 | * |
||
| 1510 | * @since 2.0 |
||
| 1511 | * @param Request $request |
||
| 1512 | */ |
||
| 1513 | public function doOPTIONS($request) |
||
| 1534 | |||
| 1535 | /** |
||
| 1536 | * {@inheritdoc} |
||
| 1537 | * |
||
| 1538 | * @since 2.0.2 |
||
| 1539 | * @param Request $request |
||
| 1540 | */ |
||
| 1541 | public function doTRACE($request) |
||
| 1562 | |||
| 1563 | /** |
||
| 1564 | * Maps the supplied request with the appropiate method to run on this controller, for example |
||
| 1565 | * GET to doGET(), POST to doPOST() etc. Returns the response generated by the method called. |
||
| 1566 | * |
||
| 1567 | * @param \Alpha\Util\Http\Request $request |
||
| 1568 | * |
||
| 1569 | * @return \Alpha\Util\Http\Response |
||
| 1570 | * |
||
| 1571 | * @since 2.0 |
||
| 1572 | */ |
||
| 1573 | public function process($request) |
||
| 1639 | |||
| 1640 | /** |
||
| 1641 | * Get the request this controller is processing (if any). |
||
| 1642 | * |
||
| 1643 | * @return \Alpha\Util\Http\Request |
||
| 1644 | * |
||
| 1645 | * @since 2.0 |
||
| 1646 | */ |
||
| 1647 | public function getRequest() |
||
| 1651 | |||
| 1652 | /** |
||
| 1653 | * Set the request this controller is processing. |
||
| 1654 | * |
||
| 1655 | * @param \Alpha\Util\Http\Request $request |
||
| 1656 | * |
||
| 1657 | * @since 2.0 |
||
| 1658 | */ |
||
| 1659 | public function setRequest($request) |
||
| 1667 | |||
| 1668 | /** |
||
| 1669 | * Use this callback to inject in the admin menu template fragment. |
||
| 1670 | * |
||
| 1671 | * @return string |
||
| 1672 | * |
||
| 1673 | * @since 1.2 |
||
| 1674 | */ |
||
| 1675 | public function after_displayPageHead_callback() |
||
| 1700 | } |
||
| 1701 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: