Complex classes like BasicEditorConfig 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 BasicEditorConfig, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class BasicEditorConfig |
||
| 14 | { |
||
| 15 | public static $configs = array(); |
||
| 16 | public static $current = null; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Get the HtmlEditorConfig object for the given identifier. This is a correct way to get an HtmlEditorConfig instance - do not call 'new' |
||
| 20 | * @param $identifier string - the identifier for the config set |
||
| 21 | * @return HtmlEditorConfig - the configuration object. This will be created if it does not yet exist for that identifier |
||
| 22 | */ |
||
| 23 | public static function get($identifier = 'default') |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Set the currently active configuration object |
||
| 33 | * @param $identifier string - the identifier for the config set |
||
| 34 | * @return null |
||
| 35 | */ |
||
| 36 | public static function set_active($identifier = null) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Get the currently active configuration object |
||
| 43 | * @return HtmlEditorConfig - the active configuration object |
||
| 44 | */ |
||
| 45 | public static function get_active() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Get the available configurations as a map of friendly_name to |
||
| 53 | * configuration name. |
||
| 54 | * @return array |
||
| 55 | */ |
||
| 56 | public static function get_available_configs_map() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Holder for all TinyMCE settings _except_ plugins and buttons |
||
| 69 | */ |
||
| 70 | protected $settings = array( |
||
| 71 | 'friendly_name' => '(Please set a friendly name for this config)', |
||
| 72 | 'priority' => 0, |
||
| 73 | 'mode' => "specific_textareas", |
||
| 74 | 'editor_selector' => "htmleditor", |
||
| 75 | 'width' => "100%", |
||
| 76 | 'auto_resize' => false, |
||
| 77 | 'theme' => "advanced", |
||
| 78 | |||
| 79 | 'theme_advanced_layout_manager' => "SimpleLayout", |
||
| 80 | 'theme_advanced_toolbar_location' => "top", |
||
| 81 | 'theme_advanced_toolbar_align' => "left", |
||
| 82 | 'theme_advanced_toolbar_parent' => "right", |
||
| 83 | |||
| 84 | 'blockquote_clear_tag' => "p", |
||
| 85 | 'table_inline_editing' => true, |
||
| 86 | |||
| 87 | 'safari_warning' => false, |
||
| 88 | 'relative_urls' => true, |
||
| 89 | 'verify_html' => true, |
||
| 90 | |||
| 91 | ); |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Holder list of enabled plugins |
||
| 95 | */ |
||
| 96 | protected $plugins = array( |
||
| 97 | 'contextmenu' => null, |
||
| 98 | 'table' => null, |
||
| 99 | 'emotions' => null, |
||
| 100 | 'paste' => null, |
||
| 101 | 'advcode' => '../../../sapphire/thirdparty/tinymce-advcode/editor_plugin_src.js', |
||
| 102 | 'spellchecker' => null |
||
| 103 | ); |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Holder list of buttons, organised by line |
||
| 107 | */ |
||
| 108 | protected $buttons = array( |
||
| 109 | 1 => array('bold','italic','underline','strikethrough','separator','justifyleft','justifycenter','justifyright','justifyfull','formatselect','separator','bullist','numlist','outdent','indent','blockquote','hr','charmap'), |
||
| 110 | 2 => array('undo','redo','separator','cut','copy','paste','pastetext','pasteword','spellchecker','separator','advcode','search','replace','selectall','visualaid','separator','tablecontrols'), |
||
| 111 | 3 => array() |
||
| 112 | ); |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Get the current value of an option |
||
| 116 | * @param $k string - The key of the option to get |
||
| 117 | * @return mixed - The value of the specified option |
||
| 118 | */ |
||
| 119 | public function getOption($k) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Set the value of one option |
||
| 128 | * @param $k string - The key of the option to set |
||
| 129 | * @param $v mixed - The value of the option to set |
||
| 130 | * @return mixed - $v returned for chaining |
||
| 131 | */ |
||
| 132 | public function setOption($k, $v) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Set multiple options |
||
| 139 | * @param $a array - The options to set, as keys and values of the array |
||
| 140 | * @return null |
||
| 141 | */ |
||
| 142 | public function setOptions($a) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Enable one or several plugins. Will maintain unique list if already |
||
| 151 | * enabled plugin is re-passed. If passed in as a map of plugin-name to path, |
||
| 152 | * the plugin will be loaded by tinymce.PluginManager.load() instead of through tinyMCE.init(). |
||
| 153 | * Keep in mind that these externals plugins require a dash-prefix in their name. |
||
| 154 | * |
||
| 155 | * @see http://wiki.moxiecode.com/index.php/TinyMCE:API/tinymce.PluginManager/load |
||
| 156 | * |
||
| 157 | * @param String [0..] a string, or several strings, or a single array of strings - The plugins to enable |
||
| 158 | * @return null |
||
| 159 | */ |
||
| 160 | public function enablePlugins() |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Enable one or several plugins. Will properly handle being passed a plugin that is already disabled |
||
| 180 | * @param String [0..] a string, or several strings, or a single array of strings - The plugins to disable |
||
| 181 | * @return null |
||
| 182 | */ |
||
| 183 | public function disablePlugins() |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return Array |
||
| 199 | */ |
||
| 200 | public function getPlugins() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Totally re-set the buttons on a given line |
||
| 207 | * |
||
| 208 | * @param integer from 1..3 - The line number to redefine |
||
| 209 | * @param string a string or several strings, or a single array of strings - The button names to make this line contain |
||
| 210 | * @return null |
||
| 211 | */ |
||
| 212 | public function setButtonsForLine() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Add buttons to the end of a line |
||
| 225 | * @param integer from 1..3 |
||
| 226 | * @param string a string, or several strings, or a single array of strings - The button names to add to the end of this line |
||
| 227 | * @return null |
||
| 228 | */ |
||
| 229 | public function addButtonsToLine() |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Internal function for adding and removing buttons related to another button |
||
| 244 | * @param $name string - the name of the button to modify |
||
| 245 | * @param $offset integer - the offset relative to that button to perform an array_splice at - 0 for before $name, 1 for after |
||
| 246 | * @param $del integer - the number of buttons to remove at the position given by index(string) + offset |
||
| 247 | * @param $add mixed - an array or single item to insert at the position given by index(string) + offset, or null for no insertion |
||
| 248 | * @return boolean - true if $name matched a button, false otherwise |
||
| 249 | */ |
||
| 250 | protected function modifyButtons($name, $offset, $del=0, $add=null) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Insert buttons before the first occurance of another button |
||
| 267 | * @param string - the name of the button to insert other buttons before |
||
| 268 | * @param string a string, or several strings, or a single array of strings - the button names to insert before that button |
||
| 269 | * @return boolean - true if insertion occured, false if it did not (because the given button name was not found) |
||
| 270 | */ |
||
| 271 | public function insertButtonsBefore() |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Insert buttons after the first occurance of another button |
||
| 280 | * @param string - the name of the button to insert other buttons after |
||
| 281 | * @param string a string, or several strings, or a single array of strings - the button names to insert after that button |
||
| 282 | * @return boolean - true if insertion occured, false if it did not (because the given button name was not found) |
||
| 283 | */ |
||
| 284 | public function insertButtonsAfter() |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Remove the first occurance of buttons |
||
| 293 | * @param string one or more strings - the name of the buttons to remove |
||
| 294 | * @return null |
||
| 295 | */ |
||
| 296 | public function removeButtons() |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Generate the javascript that will set tinyMCE's configuration to that of the current settings of this object |
||
| 306 | * @return string - the javascript |
||
| 307 | */ |
||
| 308 | public function generateJS() |
||
| 340 | } |
||
| 341 |