Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like View 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 View, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 56 | class View extends Object { |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Helpers collection |
||
| 60 | * |
||
| 61 | * @var HelperCollection |
||
| 62 | */ |
||
| 63 | public $Helpers; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * ViewBlock instance. |
||
| 67 | * |
||
| 68 | * @var ViewBlock |
||
| 69 | */ |
||
| 70 | public $Blocks; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Name of the plugin. |
||
| 74 | * |
||
| 75 | * @link http://manual.cakephp.org/chapter/plugins |
||
| 76 | * @var string |
||
| 77 | */ |
||
| 78 | public $plugin = null; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Name of the controller. |
||
| 82 | * |
||
| 83 | * @var string Name of controller |
||
| 84 | */ |
||
| 85 | public $name = null; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Current passed params |
||
| 89 | * |
||
| 90 | * @var mixed |
||
| 91 | */ |
||
| 92 | public $passedArgs = array(); |
||
| 93 | |||
| 94 | /** |
||
| 95 | * An array of names of built-in helpers to include. |
||
| 96 | * |
||
| 97 | * @var mixed A single name as a string or a list of names as an array. |
||
| 98 | */ |
||
| 99 | public $helpers = array(); |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Path to View. |
||
| 103 | * |
||
| 104 | * @var string Path to View |
||
| 105 | */ |
||
| 106 | public $viewPath = null; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Variables for the view |
||
| 110 | * |
||
| 111 | * @var array |
||
| 112 | */ |
||
| 113 | public $viewVars = array(); |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Name of view to use with this View. |
||
| 117 | * |
||
| 118 | * @var string |
||
| 119 | */ |
||
| 120 | public $view = null; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Name of layout to use with this View. |
||
| 124 | * |
||
| 125 | * @var string |
||
| 126 | */ |
||
| 127 | public $layout = 'default'; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Path to Layout. |
||
| 131 | * |
||
| 132 | * @var string Path to Layout |
||
| 133 | */ |
||
| 134 | public $layoutPath = null; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Turns on or off CakePHP's conventional mode of applying layout files. On by default. |
||
| 138 | * Setting to off means that layouts will not be automatically applied to rendered views. |
||
| 139 | * |
||
| 140 | * @var boolean |
||
| 141 | */ |
||
| 142 | public $autoLayout = true; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * File extension. Defaults to CakePHP's template ".ctp". |
||
| 146 | * |
||
| 147 | * @var string |
||
| 148 | */ |
||
| 149 | public $ext = '.ctp'; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Sub-directory for this view file. This is often used for extension based routing. |
||
| 153 | * Eg. With an `xml` extension, $subDir would be `xml/` |
||
| 154 | * |
||
| 155 | * @var string |
||
| 156 | */ |
||
| 157 | public $subDir = null; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Theme name. |
||
| 161 | * |
||
| 162 | * @var string |
||
| 163 | */ |
||
| 164 | public $theme = null; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Used to define methods a controller that will be cached. |
||
| 168 | * |
||
| 169 | * @see Controller::$cacheAction |
||
| 170 | * @var mixed |
||
| 171 | */ |
||
| 172 | public $cacheAction = false; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Holds current errors for the model validation. |
||
| 176 | * |
||
| 177 | * @var array |
||
| 178 | */ |
||
| 179 | public $validationErrors = array(); |
||
| 180 | |||
| 181 | /** |
||
| 182 | * True when the view has been rendered. |
||
| 183 | * |
||
| 184 | * @var boolean |
||
| 185 | */ |
||
| 186 | public $hasRendered = false; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * List of generated DOM UUIDs. |
||
| 190 | * |
||
| 191 | * @var array |
||
| 192 | */ |
||
| 193 | public $uuids = array(); |
||
| 194 | |||
| 195 | /** |
||
| 196 | * An instance of a CakeRequest object that contains information about the current request. |
||
| 197 | * This object contains all the information about a request and several methods for reading |
||
| 198 | * additional information about the request. |
||
| 199 | * |
||
| 200 | * @var CakeRequest |
||
| 201 | */ |
||
| 202 | public $request; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Reference to the Response object |
||
| 206 | * |
||
| 207 | * @var CakeResponse |
||
| 208 | */ |
||
| 209 | public $response; |
||
| 210 | |||
| 211 | /** |
||
| 212 | * The Cache configuration View will use to store cached elements. Changing this will change |
||
| 213 | * the default configuration elements are stored under. You can also choose a cache config |
||
| 214 | * per element. |
||
| 215 | * |
||
| 216 | * @var string |
||
| 217 | * @see View::element() |
||
| 218 | */ |
||
| 219 | public $elementCache = 'default'; |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Element cache settings |
||
| 223 | * |
||
| 224 | * @var array |
||
| 225 | * @see View::_elementCache(); |
||
| 226 | * @see View::_renderElement |
||
| 227 | */ |
||
| 228 | public $elementCacheSettings = array(); |
||
| 229 | |||
| 230 | /** |
||
| 231 | * List of variables to collect from the associated controller. |
||
| 232 | * |
||
| 233 | * @var array |
||
| 234 | */ |
||
| 235 | protected $_passedVars = array( |
||
| 236 | 'viewVars', 'autoLayout', 'ext', 'helpers', 'view', 'layout', 'name', 'theme', |
||
| 237 | 'layoutPath', 'viewPath', 'request', 'plugin', 'passedArgs', 'cacheAction' |
||
| 238 | ); |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Scripts (and/or other <head /> tags) for the layout. |
||
| 242 | * |
||
| 243 | * @var array |
||
| 244 | */ |
||
| 245 | protected $_scripts = array(); |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Holds an array of paths. |
||
| 249 | * |
||
| 250 | * @var array |
||
| 251 | */ |
||
| 252 | protected $_paths = array(); |
||
| 253 | |||
| 254 | /** |
||
| 255 | * The names of views and their parents used with View::extend(); |
||
| 256 | * |
||
| 257 | * @var array |
||
| 258 | */ |
||
| 259 | protected $_parents = array(); |
||
| 260 | |||
| 261 | /** |
||
| 262 | * The currently rendering view file. Used for resolving parent files. |
||
| 263 | * |
||
| 264 | * @var string |
||
| 265 | */ |
||
| 266 | protected $_current = null; |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Currently rendering an element. Used for finding parent fragments |
||
| 270 | * for elements. |
||
| 271 | * |
||
| 272 | * @var string |
||
| 273 | */ |
||
| 274 | protected $_currentType = ''; |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Content stack, used for nested templates that all use View::extend(); |
||
| 278 | * |
||
| 279 | * @var array |
||
| 280 | */ |
||
| 281 | protected $_stack = array(); |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Instance of the CakeEventManager this View object is using |
||
| 285 | * to dispatch inner events. Usually the manager is shared with |
||
| 286 | * the controller, so it it possible to register view events in |
||
| 287 | * the controller layer. |
||
| 288 | * |
||
| 289 | * @var CakeEventManager |
||
| 290 | */ |
||
| 291 | protected $_eventManager = null; |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Whether the event manager was already configured for this object |
||
| 295 | * |
||
| 296 | * @var boolean |
||
| 297 | */ |
||
| 298 | protected $_eventManagerConfigured = false; |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Constant for view file type 'view' |
||
| 302 | * |
||
| 303 | * @var string |
||
| 304 | */ |
||
| 305 | const TYPE_VIEW = 'view'; |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Constant for view file type 'element' |
||
| 309 | * |
||
| 310 | * @var string |
||
| 311 | */ |
||
| 312 | const TYPE_ELEMENT = 'element'; |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Constant for view file type 'layout' |
||
| 316 | * |
||
| 317 | * @var string |
||
| 318 | */ |
||
| 319 | const TYPE_LAYOUT = 'layout'; |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Constructor |
||
| 323 | * |
||
| 324 | * @param Controller $controller A controller object to pull View::_passedVars from. |
||
| 325 | */ |
||
| 326 | public function __construct(Controller $controller = null) { |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Returns the CakeEventManager manager instance that is handling any callbacks. |
||
| 353 | * You can use this instance to register any new listeners or callbacks to the |
||
| 354 | * controller events, or create your own events and trigger them at will. |
||
| 355 | * |
||
| 356 | * @return CakeEventManager |
||
| 357 | */ |
||
| 358 | View Code Duplication | public function getEventManager() { |
|
| 368 | |||
| 369 | /** |
||
| 370 | * Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string. |
||
| 371 | * |
||
| 372 | * This realizes the concept of Elements, (or "partial layouts") and the $params array is used to send |
||
| 373 | * data to be used in the element. Elements can be cached improving performance by using the `cache` option. |
||
| 374 | * |
||
| 375 | * @param string $name Name of template file in the/app/View/Elements/ folder, |
||
| 376 | * or `MyPlugin.template` to use the template element from MyPlugin. If the element |
||
| 377 | * is not found in the plugin, the normal view path cascade will be searched. |
||
| 378 | * @param array $data Array of data to be made available to the rendered view (i.e. the Element) |
||
| 379 | * @param array $options Array of options. Possible keys are: |
||
| 380 | * - `cache` - Can either be `true`, to enable caching using the config in View::$elementCache. Or an array |
||
| 381 | * If an array, the following keys can be used: |
||
| 382 | * - `config` - Used to store the cached element in a custom cache configuration. |
||
| 383 | * - `key` - Used to define the key used in the Cache::write(). It will be prefixed with `element_` |
||
| 384 | * - `plugin` - Load an element from a specific plugin. This option is deprecated, see below. |
||
| 385 | * - `callbacks` - Set to true to fire beforeRender and afterRender helper callbacks for this element. |
||
| 386 | * Defaults to false. |
||
| 387 | * - `ignoreMissing` - Used to allow missing elements. Set to true to not trigger notices. |
||
| 388 | * @return string Rendered Element |
||
| 389 | * @deprecated The `$options['plugin']` is deprecated and will be removed in CakePHP 3.0. Use |
||
| 390 | * `Plugin.element_name` instead. |
||
| 391 | */ |
||
| 392 | public function element($name, $data = array(), $options = array()) { |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Checks if an element exists |
||
| 425 | * |
||
| 426 | * @param string $name Name of template file in the /app/View/Elements/ folder, |
||
| 427 | * or `MyPlugin.template` to check the template element from MyPlugin. If the element |
||
| 428 | * is not found in the plugin, the normal view path cascade will be searched. |
||
| 429 | * @return boolean Success |
||
| 430 | */ |
||
| 431 | public function elementExists($name) { |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Renders view for given view file and layout. |
||
| 437 | * |
||
| 438 | * Render triggers helper callbacks, which are fired before and after the view are rendered, |
||
| 439 | * as well as before and after the layout. The helper callbacks are called: |
||
| 440 | * |
||
| 441 | * - `beforeRender` |
||
| 442 | * - `afterRender` |
||
| 443 | * - `beforeLayout` |
||
| 444 | * - `afterLayout` |
||
| 445 | * |
||
| 446 | * If View::$autoRender is false and no `$layout` is provided, the view will be returned bare. |
||
| 447 | * |
||
| 448 | * View and layout names can point to plugin views/layouts. Using the `Plugin.view` syntax |
||
| 449 | * a plugin view/layout can be used instead of the app ones. If the chosen plugin is not found |
||
| 450 | * the view will be located along the regular view path cascade. |
||
| 451 | * |
||
| 452 | * @param string $view Name of view file to use |
||
| 453 | * @param string $layout Layout to use. |
||
| 454 | * @return string|null Rendered content or null if content already rendered and returned earlier. |
||
| 455 | * @throws CakeException If there is an error in the view. |
||
| 456 | */ |
||
| 457 | public function render($view = null, $layout = null) { |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Renders a layout. Returns output from _render(). Returns false on error. |
||
| 482 | * Several variables are created for use in layout. |
||
| 483 | * |
||
| 484 | * - `title_for_layout` - A backwards compatible place holder, you should set this value if you want more control. |
||
| 485 | * - `content_for_layout` - contains rendered view file |
||
| 486 | * - `scripts_for_layout` - Contains content added with addScript() as well as any content in |
||
| 487 | * the 'meta', 'css', and 'script' blocks. They are appended in that order. |
||
| 488 | * |
||
| 489 | * Deprecated features: |
||
| 490 | * |
||
| 491 | * - `$scripts_for_layout` is deprecated and will be removed in CakePHP 3.0. |
||
| 492 | * Use the block features instead. `meta`, `css` and `script` will be populated |
||
| 493 | * by the matching methods on HtmlHelper. |
||
| 494 | * - `$title_for_layout` is deprecated and will be removed in CakePHP 3.0 |
||
| 495 | * - `$content_for_layout` is deprecated and will be removed in CakePHP 3.0. |
||
| 496 | * Use the `content` block instead. |
||
| 497 | * |
||
| 498 | * @param string $content Content to render in a view, wrapped by the surrounding layout. |
||
| 499 | * @param string $layout Layout name |
||
| 500 | * @return mixed Rendered output, or false on error |
||
| 501 | * @throws CakeException if there is an error in the view. |
||
| 502 | */ |
||
| 503 | public function renderLayout($content, $layout = null) { |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Render cached view. Works in concert with CacheHelper and Dispatcher to |
||
| 537 | * render cached view files. |
||
| 538 | * |
||
| 539 | * @param string $filename the cache file to include |
||
| 540 | * @param string $timeStart the page render start time |
||
| 541 | * @return boolean Success of rendering the cached file. |
||
| 542 | */ |
||
| 543 | public function renderCache($filename, $timeStart) { |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Returns a list of variables available in the current View context |
||
| 568 | * |
||
| 569 | * @return array Array of the set view variable names. |
||
| 570 | */ |
||
| 571 | public function getVars() { |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Returns the contents of the given View variable(s) |
||
| 577 | * |
||
| 578 | * @param string $var The view var you want the contents of. |
||
| 579 | * @return mixed The content of the named var if its set, otherwise null. |
||
| 580 | * @deprecated Will be removed in 3.0. Use View::get() instead. |
||
| 581 | */ |
||
| 582 | public function getVar($var) { |
||
| 585 | |||
| 586 | /** |
||
| 587 | * Returns the contents of the given View variable or a block. |
||
| 588 | * Blocks are checked before view variables. |
||
| 589 | * |
||
| 590 | * @param string $var The view var you want the contents of. |
||
| 591 | * @return mixed The content of the named var if its set, otherwise null. |
||
| 592 | */ |
||
| 593 | public function get($var) { |
||
| 599 | |||
| 600 | /** |
||
| 601 | * Get the names of all the existing blocks. |
||
| 602 | * |
||
| 603 | * @return array An array containing the blocks. |
||
| 604 | * @see ViewBlock::keys() |
||
| 605 | */ |
||
| 606 | public function blocks() { |
||
| 609 | |||
| 610 | /** |
||
| 611 | * Start capturing output for a 'block' |
||
| 612 | * |
||
| 613 | * @param string $name The name of the block to capture for. |
||
| 614 | * @return void |
||
| 615 | * @see ViewBlock::start() |
||
| 616 | */ |
||
| 617 | public function start($name) { |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Start capturing output for a 'block' if it has no content |
||
| 623 | * |
||
| 624 | * @param string $name The name of the block to capture for. |
||
| 625 | * @return void |
||
| 626 | * @see ViewBlock::startIfEmpty() |
||
| 627 | */ |
||
| 628 | public function startIfEmpty($name) { |
||
| 631 | |||
| 632 | /** |
||
| 633 | * Append to an existing or new block. Appending to a new |
||
| 634 | * block will create the block. |
||
| 635 | * |
||
| 636 | * @param string $name Name of the block |
||
| 637 | * @param mixed $value The content for the block. |
||
| 638 | * @return void |
||
| 639 | * @see ViewBlock::concat() |
||
| 640 | */ |
||
| 641 | public function append($name, $value = null) { |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Prepend to an existing or new block. Prepending to a new |
||
| 647 | * block will create the block. |
||
| 648 | * |
||
| 649 | * @param string $name Name of the block |
||
| 650 | * @param mixed $value The content for the block. |
||
| 651 | * @return void |
||
| 652 | * @see ViewBlock::concat() |
||
| 653 | */ |
||
| 654 | public function prepend($name, $value = null) { |
||
| 657 | |||
| 658 | /** |
||
| 659 | * Set the content for a block. This will overwrite any |
||
| 660 | * existing content. |
||
| 661 | * |
||
| 662 | * @param string $name Name of the block |
||
| 663 | * @param mixed $value The content for the block. |
||
| 664 | * @return void |
||
| 665 | * @see ViewBlock::set() |
||
| 666 | */ |
||
| 667 | public function assign($name, $value) { |
||
| 670 | |||
| 671 | /** |
||
| 672 | * Fetch the content for a block. If a block is |
||
| 673 | * empty or undefined '' will be returned. |
||
| 674 | * |
||
| 675 | * @param string $name Name of the block |
||
| 676 | * @param string $default Default text |
||
| 677 | * @return string $default The block content or $default if the block does not exist. |
||
| 678 | * @see ViewBlock::get() |
||
| 679 | */ |
||
| 680 | public function fetch($name, $default = '') { |
||
| 683 | |||
| 684 | /** |
||
| 685 | * End a capturing block. The compliment to View::start() |
||
| 686 | * |
||
| 687 | * @return void |
||
| 688 | * @see ViewBlock::end() |
||
| 689 | */ |
||
| 690 | public function end() { |
||
| 693 | |||
| 694 | /** |
||
| 695 | * Provides view or element extension/inheritance. Views can extends a |
||
| 696 | * parent view and populate blocks in the parent template. |
||
| 697 | * |
||
| 698 | * @param string $name The view or element to 'extend' the current one with. |
||
| 699 | * @return void |
||
| 700 | * @throws LogicException when you extend a view with itself or make extend loops. |
||
| 701 | * @throws LogicException when you extend an element which doesn't exist |
||
| 702 | */ |
||
| 703 | public function extend($name) { |
||
| 737 | |||
| 738 | /** |
||
| 739 | * Adds a script block or other element to be inserted in $scripts_for_layout in |
||
| 740 | * the `<head />` of a document layout |
||
| 741 | * |
||
| 742 | * @param string $name Either the key name for the script, or the script content. Name can be used to |
||
| 743 | * update/replace a script element. |
||
| 744 | * @param string $content The content of the script being added, optional. |
||
| 745 | * @return void |
||
| 746 | * @deprecated Will be removed in 3.0. Superseded by blocks functionality. |
||
| 747 | * @see View::start() |
||
| 748 | */ |
||
| 749 | public function addScript($name, $content = null) { |
||
| 758 | |||
| 759 | /** |
||
| 760 | * Generates a unique, non-random DOM ID for an object, based on the object type and the target URL. |
||
| 761 | * |
||
| 762 | * @param string $object Type of object, i.e. 'form' or 'link' |
||
| 763 | * @param string $url The object's target URL |
||
| 764 | * @return string |
||
| 765 | */ |
||
| 766 | public function uuid($object, $url) { |
||
| 777 | |||
| 778 | /** |
||
| 779 | * Allows a template or element to set a variable that will be available in |
||
| 780 | * a layout or other element. Analogous to Controller::set(). |
||
| 781 | * |
||
| 782 | * @param string|array $one A string or an array of data. |
||
| 783 | * @param string|array $two Value in case $one is a string (which then works as the key). |
||
| 784 | * Unused if $one is an associative array, otherwise serves as the values to $one's keys. |
||
| 785 | * @return void |
||
| 786 | */ |
||
| 787 | View Code Duplication | public function set($one, $two = null) { |
|
| 803 | |||
| 804 | /** |
||
| 805 | * Magic accessor for helpers. Provides access to attributes that were deprecated. |
||
| 806 | * |
||
| 807 | * @param string $name Name of the attribute to get. |
||
| 808 | * @return mixed |
||
| 809 | */ |
||
| 810 | public function __get($name) { |
||
| 830 | |||
| 831 | /** |
||
| 832 | * Magic accessor for deprecated attributes. |
||
| 833 | * |
||
| 834 | * @param string $name Name of the attribute to set. |
||
| 835 | * @param mixed $value Value of the attribute to set. |
||
| 836 | * @return mixed |
||
| 837 | */ |
||
| 838 | public function __set($name, $value) { |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Magic isset check for deprecated attributes. |
||
| 849 | * |
||
| 850 | * @param string $name Name of the attribute to check. |
||
| 851 | * @return boolean |
||
| 852 | */ |
||
| 853 | public function __isset($name) { |
||
| 863 | |||
| 864 | /** |
||
| 865 | * Interact with the HelperCollection to load all the helpers. |
||
| 866 | * |
||
| 867 | * @return void |
||
| 868 | */ |
||
| 869 | public function loadHelpers() { |
||
| 876 | |||
| 877 | /** |
||
| 878 | * Renders and returns output for given view filename with its |
||
| 879 | * array of data. Handles parent/extended views. |
||
| 880 | * |
||
| 881 | * @param string $viewFile Filename of the view |
||
| 882 | * @param array $data Data to include in rendered view. If empty the current View::$viewVars will be used. |
||
| 883 | * @return string Rendered output |
||
| 884 | * @throws CakeException when a block is left open. |
||
| 885 | */ |
||
| 886 | protected function _render($viewFile, $data = array()) { |
||
| 921 | |||
| 922 | /** |
||
| 923 | * Sandbox method to evaluate a template / view script in. |
||
| 924 | * |
||
| 925 | * @param string $viewFn Filename of the view |
||
| 926 | * @param array $dataForView Data to include in rendered view. |
||
| 927 | * If empty the current View::$viewVars will be used. |
||
| 928 | * @return string Rendered output |
||
| 929 | */ |
||
| 930 | protected function _evaluate($viewFile, $dataForView) { |
||
| 940 | |||
| 941 | /** |
||
| 942 | * Loads a helper. Delegates to the `HelperCollection::load()` to load the helper |
||
| 943 | * |
||
| 944 | * @param string $helperName Name of the helper to load. |
||
| 945 | * @param array $settings Settings for the helper |
||
| 946 | * @return Helper a constructed helper object. |
||
| 947 | * @see HelperCollection::load() |
||
| 948 | */ |
||
| 949 | public function loadHelper($helperName, $settings = array()) { |
||
| 952 | |||
| 953 | /** |
||
| 954 | * Returns filename of given action's template file (.ctp) as a string. |
||
| 955 | * CamelCased action names will be under_scored! This means that you can have |
||
| 956 | * LongActionNames that refer to long_action_names.ctp views. |
||
| 957 | * |
||
| 958 | * @param string $name Controller action to find template filename for |
||
| 959 | * @return string Template filename |
||
| 960 | * @throws MissingViewException when a view file could not be found. |
||
| 961 | */ |
||
| 962 | protected function _getViewFileName($name = null) { |
||
| 1011 | |||
| 1012 | /** |
||
| 1013 | * Splits a dot syntax plugin name into its plugin and filename. |
||
| 1014 | * If $name does not have a dot, then index 0 will be null. |
||
| 1015 | * It checks if the plugin is loaded, else filename will stay unchanged for filenames containing dot |
||
| 1016 | * |
||
| 1017 | * @param string $name The name you want to plugin split. |
||
| 1018 | * @param boolean $fallback If true uses the plugin set in the current CakeRequest when parsed plugin is not loaded |
||
| 1019 | * @return array Array with 2 indexes. 0 => plugin name, 1 => filename |
||
| 1020 | */ |
||
| 1021 | public function pluginSplit($name, $fallback = true) { |
||
| 1033 | |||
| 1034 | /** |
||
| 1035 | * Returns layout filename for this template as a string. |
||
| 1036 | * |
||
| 1037 | * @param string $name The name of the layout to find. |
||
| 1038 | * @return string Filename for layout file (.ctp). |
||
| 1039 | * @throws MissingLayoutException when a layout cannot be located |
||
| 1040 | */ |
||
| 1041 | protected function _getLayoutFileName($name = null) { |
||
| 1064 | |||
| 1065 | /** |
||
| 1066 | * Get the extensions that view files can use. |
||
| 1067 | * |
||
| 1068 | * @return array Array of extensions view files use. |
||
| 1069 | */ |
||
| 1070 | protected function _getExtensions() { |
||
| 1077 | |||
| 1078 | /** |
||
| 1079 | * Finds an element filename, returns false on failure. |
||
| 1080 | * |
||
| 1081 | * @param string $name The name of the element to find. |
||
| 1082 | * @return mixed Either a string to the element filename or false when one can't be found. |
||
| 1083 | */ |
||
| 1084 | protected function _getElementFileName($name) { |
||
| 1098 | |||
| 1099 | /** |
||
| 1100 | * Return all possible paths to find view files in order |
||
| 1101 | * |
||
| 1102 | * @param string $plugin Optional plugin name to scan for view files. |
||
| 1103 | * @param boolean $cached Set to false to force a refresh of view paths. Default true. |
||
| 1104 | * @return array paths |
||
| 1105 | */ |
||
| 1106 | protected function _paths($plugin = null, $cached = true) { |
||
| 1144 | |||
| 1145 | /** |
||
| 1146 | * Checks if an element is cached and returns the cached data if present |
||
| 1147 | * |
||
| 1148 | * @param string $name Element name |
||
| 1149 | * @param string $data Data |
||
| 1150 | * @param array $options Element options |
||
| 1151 | * @return string|null |
||
| 1152 | */ |
||
| 1153 | protected function _elementCache($name, $data, $options) { |
||
| 1176 | |||
| 1177 | /** |
||
| 1178 | * Renders an element and fires the before and afterRender callbacks for it |
||
| 1179 | * and writes to the cache if a cache is used |
||
| 1180 | * |
||
| 1181 | * @param string $file Element file path |
||
| 1182 | * @param array $data Data to render |
||
| 1183 | * @param array $options Element options |
||
| 1184 | * @return string |
||
| 1185 | */ |
||
| 1186 | protected function _renderElement($file, $data, $options) { |
||
| 1208 | } |
||
| 1209 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: