Complex classes like AdminPageFramework_Resource_Base 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 AdminPageFramework_Resource_Base, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | abstract class AdminPageFramework_Resource_Base extends AdminPageFramework_FrameworkUtility { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Represents the structure of the array for enqueuing scripts and styles. |
||
| 29 | * |
||
| 30 | * @since 2.1.2 |
||
| 31 | * @since 2.1.5 Moved to the base class. |
||
| 32 | * @since 3.0.0 Moved from the property class. |
||
| 33 | * @since 3.3.0 Changed the name to `$_aStructure_EnqueuingResources` from `$_aStructure_EnqueuingScriptsAndStyles`. |
||
| 34 | * @internal |
||
| 35 | */ |
||
| 36 | protected static $_aStructure_EnqueuingResources = array( |
||
| 37 | |||
| 38 | /* The system internal keys. */ |
||
| 39 | 'sSRC' => null, |
||
| 40 | 'aPostTypes' => array(), // for meta box class |
||
| 41 | 'sPageSlug' => null, |
||
| 42 | 'sTabSlug' => null, |
||
| 43 | 'sType' => null, // script or style |
||
| 44 | |||
| 45 | /* The below keys are for users. */ |
||
| 46 | 'handle_id' => null, |
||
| 47 | 'dependencies' => array(), |
||
| 48 | 'version' => false, // although the type should be string, the wp_enqueue_...() functions want false as the default value. |
||
| 49 | 'translation' => array(), // only for scripts |
||
| 50 | 'in_footer' => false, // only for scripts |
||
| 51 | 'media' => 'all', // only for styles |
||
| 52 | 'attributes' => array(), // 3.3.0+ - the attribute array |
||
| 53 | |||
| 54 | ); |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Stores the class selector used for the class-specific style. |
||
| 58 | * |
||
| 59 | * @since 3.2.0 |
||
| 60 | * @remark This value should be overridden in an extended class. |
||
| 61 | * @internal |
||
| 62 | */ |
||
| 63 | protected $_sClassSelector_Style = 'admin-page-framework-style'; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Stores the class selector used to the class-specific script. |
||
| 67 | * |
||
| 68 | * @since 3.2.0 |
||
| 69 | * @remark This value should be overridden in an extended class. |
||
| 70 | * @internal |
||
| 71 | */ |
||
| 72 | protected $_sClassSelector_Script = 'admin-page-framework-script'; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Stores hand IDs by resource url to look up handle id and add custom arguments. |
||
| 76 | * @since 3.3.0 |
||
| 77 | * @internal |
||
| 78 | */ |
||
| 79 | protected $_aHandleIDs = array(); |
||
| 80 | |||
| 81 | /** |
||
| 82 | * A property object. |
||
| 83 | * |
||
| 84 | * @remark Set in the constructor. |
||
| 85 | */ |
||
| 86 | public $oProp; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * A utility object. |
||
| 90 | * |
||
| 91 | * @remark Set in the constructor. |
||
| 92 | * @deprecated 3.6.3 |
||
| 93 | * @remark kept for backward compatibility. |
||
| 94 | */ |
||
| 95 | public $oUtil; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Sets up properties and hooks. |
||
| 99 | * @internal |
||
| 100 | */ |
||
| 101 | public function __construct( $oProp ) { |
||
| 140 | |||
| 141 | /* |
||
| 142 | * Methods that should be overridden in extended classes. |
||
| 143 | * @internal |
||
| 144 | */ |
||
| 145 | |||
| 146 | public function _forceToEnqueueStyle( $sSRC, $aCustomArgs=array() ) {} |
||
| 148 | |||
| 149 | /** |
||
| 150 | * A helper function for the _replyToEnqueueScripts() and the `_replyToEnqueueStyle()` methods. |
||
| 151 | * |
||
| 152 | * @since 2.1.5 |
||
| 153 | * @since 3.7.0 Fixed a typo in the method name. |
||
| 154 | * @internal |
||
| 155 | * @remark The widget fields type does not have conditions unlike the meta-box type that requires to check currently loaded post type. |
||
| 156 | * @remark This method should be redefined in the extended class. |
||
| 157 | */ |
||
| 158 | protected function _enqueueSRCByCondition( $aEnqueueItem ) { |
||
| 161 | |||
| 162 | /* |
||
| 163 | * Shared methods |
||
| 164 | */ |
||
| 165 | /** |
||
| 166 | * Checks the src url of the enqueued script/style to determine whether or not to set up a attribute modification callback. |
||
| 167 | * |
||
| 168 | * If it is one of the framework added item, the method sets up a hook to modify the url to add custom attributes. |
||
| 169 | * |
||
| 170 | * @since 3.3.0 |
||
| 171 | * @internal |
||
| 172 | * @callback action script_loader_src |
||
| 173 | * @callback action style_loader_src |
||
| 174 | */ |
||
| 175 | public function _replyToSetupArgumentCallback( $sSRC, $sHandleID ) { |
||
| 185 | /** |
||
| 186 | * Modifies the attributes of the enqueued script tag. |
||
| 187 | * |
||
| 188 | * @since 3.3.0 |
||
| 189 | * @internal |
||
| 190 | */ |
||
| 191 | public function _replyToModifyEnqueuedAttrbutes( $sSanitizedURL, $sOriginalURL, $sContext ) { |
||
| 217 | |||
| 218 | |||
| 219 | /** |
||
| 220 | * Flags whether the common styles are loaded or not. |
||
| 221 | * |
||
| 222 | * @since 3.2.0 |
||
| 223 | * @internal |
||
| 224 | */ |
||
| 225 | static private $_bCommonStyleLoaded = false; |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Prints the inline stylesheet of the meta-box common CSS rules with the style tag. |
||
| 229 | * |
||
| 230 | * @internal |
||
| 231 | * @since 3.0.0 |
||
| 232 | * @since 3.2.0 Moved to the base class from the meta box class. |
||
| 233 | * @remark The meta box class may be instantiated multiple times so prevent echoing the same styles multiple times. |
||
| 234 | * @parameter string $sIDPrefix The id selector embedded in the script tag. |
||
| 235 | * @parameter string $sClassName The class name that identify the call group. This is important for the meta-box class because it can be instantiated multiple times in one particular page. |
||
| 236 | */ |
||
| 237 | protected function _printCommonStyles( $sIDPrefix, $sClassName ) { |
||
| 249 | /** |
||
| 250 | * @internal |
||
| 251 | * @since 3.5.7 |
||
| 252 | * @return string |
||
| 253 | */ |
||
| 254 | private function _getStyleTag( $oCaller, $sIDPrefix ) { |
||
| 279 | /** |
||
| 280 | * @internal |
||
| 281 | * @since 3.5.7 |
||
| 282 | * @return string |
||
| 283 | */ |
||
| 284 | private function _getIEStyleTag( $oCaller, $sIDPrefix ) { |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Flags whether the common styles are loaded or not. |
||
| 309 | * |
||
| 310 | * @since 3.2.0 |
||
| 311 | * @internal |
||
| 312 | */ |
||
| 313 | static private $_bCommonScriptLoaded = false; |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Prints the inline scripts of the meta-box common scripts. |
||
| 317 | * |
||
| 318 | * @internal |
||
| 319 | * @since 3.0.0 |
||
| 320 | * @since 3.2.0 Moved to the base class from the meta box class. |
||
| 321 | * @remark The meta box class may be instantiated multiple times so prevent echoing the same styles multiple times. |
||
| 322 | * @parametr string $sIDPrefix The id selector embedded in the script tag. |
||
| 323 | * @parametr string $sClassName The class name that identify the call group. This is important for the meta-box class because it can be instantiated multiple times in one particular page. |
||
| 324 | */ |
||
| 325 | protected function _printCommonScripts( $sIDPrefix, $sClassName ) { |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Prints the inline stylesheet of this class stored in this class property. |
||
| 351 | * |
||
| 352 | * @since 3.0.0 |
||
| 353 | * @since 3.2.0 Made the properties storing styles empty. Moved to the base class. |
||
| 354 | * @internal |
||
| 355 | * @return void |
||
| 356 | */ |
||
| 357 | protected function _printClassSpecificStyles( $sIDPrefix ) { |
||
| 369 | /** |
||
| 370 | * |
||
| 371 | * @internal |
||
| 372 | * @since 3.5.7 |
||
| 373 | * @return string |
||
| 374 | */ |
||
| 375 | private function _getClassSpecificStyleTag( $_oCaller, $sIDPrefix ) { |
||
| 397 | /** |
||
| 398 | * |
||
| 399 | * @internal |
||
| 400 | * @since 3.5.7 |
||
| 401 | * @return string |
||
| 402 | */ |
||
| 403 | private function _getClassSpecificIEStyleTag( $_oCaller, $sIDPrefix ) { |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Prints the inline scripts of this class stored in this class property. |
||
| 428 | * |
||
| 429 | * @since 3.0.0 |
||
| 430 | * @since 3.2.0 Made the property empty that stores scripts. Moved to the base class. |
||
| 431 | * @internal |
||
| 432 | */ |
||
| 433 | protected function _printClassSpecificScripts( $sIDPrefix ) { |
||
| 458 | |||
| 459 | |||
| 460 | /** |
||
| 461 | * Appends the CSS rules of the framework in the head tag. |
||
| 462 | * |
||
| 463 | * @since 2.0.0 |
||
| 464 | * @since 2.1.5 Moved from `AdminPageFramework_MetaBox`. Changed the name from `addAtyle()` to `replyToAddStyle()`. |
||
| 465 | * @callback action admin_head |
||
| 466 | * @internal |
||
| 467 | */ |
||
| 468 | public function _replyToAddStyle() { |
||
| 479 | /** |
||
| 480 | * Appends the JavaScript script of the framework in the head tag. |
||
| 481 | * |
||
| 482 | * @callback action admin_head |
||
| 483 | * @since 2.0.0 |
||
| 484 | * @since 2.1.5 Moved from AdminPageFramework_MetaBox. Changed the name from `addScript()` to `replyToAddScript()`. |
||
| 485 | * @since 3.2.0 Moved from AdminPageFramework_Resource_post_meta_box. |
||
| 486 | * @internal |
||
| 487 | */ |
||
| 488 | public function _replyToAddScript() { |
||
| 499 | |||
| 500 | |||
| 501 | /** |
||
| 502 | * Performs actual enqueuing items. |
||
| 503 | * |
||
| 504 | * @since 2.1.2 |
||
| 505 | * @since 2.1.5 Moved from the main class. |
||
| 506 | * @internal |
||
| 507 | */ |
||
| 508 | protected function _enqueueSRC( $aEnqueueItem ) { |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Takes care of added enqueuing scripts by checking the currently loading page. |
||
| 539 | * |
||
| 540 | * @remark A callback for the admin_enqueue_scripts hook. |
||
| 541 | * @since 2.1.2 |
||
| 542 | * @since 2.1.5 Moved from the main class. Changed the name from `enqueueStylesCalback` to `replyToEnqueueStyles()`. |
||
| 543 | * @since 3.0.0 Changed the name to `_replyToEnqueueStyles()`. |
||
| 544 | * @since 3.2.0 Changed it unset the enqueued item so that the method can be called multiple times. |
||
| 545 | * @internal |
||
| 546 | */ |
||
| 547 | public function _replyToEnqueueStyles() { |
||
| 553 | |||
| 554 | /** |
||
| 555 | * Takes care of added enqueuing scripts by page slug and tab slug. |
||
| 556 | * |
||
| 557 | * @remark A callback for the admin_enqueue_scripts hook. |
||
| 558 | * @since 2.1.2 |
||
| 559 | * @since 2.1.5 Moved from the main class. Changed the name from `enqueueScriptsCallback` to `callbackEnqueueScripts()`. |
||
| 560 | * @since 3.0.0 Changed the name to `_replyToEnqueueScripts()`. |
||
| 561 | * @since 3.2.0 Changed it unset the enqueued item so that the method can be called multiple times. |
||
| 562 | * @internal |
||
| 563 | */ |
||
| 564 | public function _replyToEnqueueScripts() { |
||
| 570 | |||
| 571 | } |
||
| 572 |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.