From 5b93532e31e2c73b8b51cb7f904d2dd7099ff810 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Thu, 6 Mar 2014 23:18:28 -0500 Subject: [PATCH] Remove protected methods that no longer have callers. Remove duplicated code from Helper that is now available in StringTemplate, and the StringTemplateTrait. --- src/View/Helper.php | 78 ---------------------------------- src/View/Helper/HtmlHelper.php | 2 +- src/View/Helper/TimeHelper.php | 6 ++- 3 files changed, 6 insertions(+), 80 deletions(-) diff --git a/src/View/Helper.php b/src/View/Helper.php index a7dd2ec2dff..e66ac14eda5 100644 --- a/src/View/Helper.php +++ b/src/View/Helper.php @@ -339,84 +339,6 @@ public function assetTimestamp($path) { return $path; } -/** - * Returns a space-delimited string with items of the $options array. If a key - * of $options array happens to be one of those listed in `Helper::$_minimizedAttributes` - * - * And its value is one of: - * - * - '1' (string) - * - 1 (integer) - * - true (boolean) - * - 'true' (string) - * - * Then the value will be reset to be identical with key's name. - * If the value is not one of these 3, the parameter is not output. - * - * 'escape' is a special option in that it controls the conversion of - * attributes to their html-entity encoded equivalents. Set to false to disable html-encoding. - * - * If value for any option key is set to `null` or `false`, that option will be excluded from output. - * - * @param array $options Array of options. - * @param array $exclude Array of options to be excluded, the options here will not be part of the return. - * @param string $insertBefore String to be inserted before options. - * @param string $insertAfter String to be inserted after options. - * @return string Composed attributes. - * @deprecated This method will be moved to HtmlHelper in 3.0 - */ - protected function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) { - if (!is_string($options)) { - $options = (array)$options + array('escape' => true); - - if (!is_array($exclude)) { - $exclude = array(); - } - - $exclude = array('escape' => true) + array_flip($exclude); - $escape = $options['escape']; - $attributes = array(); - - foreach ($options as $key => $value) { - if (!isset($exclude[$key]) && $value !== false && $value !== null) { - $attributes[] = $this->_formatAttribute($key, $value, $escape); - } - } - $out = implode(' ', $attributes); - } else { - $out = $options; - } - return $out ? $insertBefore . $out . $insertAfter : ''; - } - -/** - * Formats an individual attribute, and returns the string value of the composed attribute. - * Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked' - * - * @param string $key The name of the attribute to create - * @param string $value The value of the attribute to create. - * @param boolean $escape Define if the value must be escaped - * @return string The composed attribute. - * @deprecated This method will be moved to HtmlHelper in 3.0 - */ - protected function _formatAttribute($key, $value, $escape = true) { - if (is_array($value)) { - $value = implode(' ', $value); - } - if (is_numeric($key)) { - return sprintf($this->_minimizedAttributeFormat, $value, $value); - } - $truthy = array(1, '1', true, 'true', $key); - $isMinimized = in_array($key, $this->_minimizedAttributes); - if ($isMinimized && in_array($value, $truthy, true)) { - return sprintf($this->_minimizedAttributeFormat, $key, $key); - } - if ($isMinimized) { - return ''; - } - return sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value)); - } - /** * Returns a string to be used as onclick handler for confirm dialogs. * diff --git a/src/View/Helper/HtmlHelper.php b/src/View/Helper/HtmlHelper.php index 06a75b61ca2..540f8b35a03 100644 --- a/src/View/Helper/HtmlHelper.php +++ b/src/View/Helper/HtmlHelper.php @@ -984,7 +984,7 @@ public function useTag($tag) { array_shift($args); foreach ($args as &$arg) { if (is_array($arg)) { - $arg = $this->_parseAttributes($arg, null, ' ', ''); + $arg = $this->_templater->formatAttributes($arg); } } return vsprintf($this->_tags[$tag], $args); diff --git a/src/View/Helper/TimeHelper.php b/src/View/Helper/TimeHelper.php index 97eea481929..f17f5de5149 100644 --- a/src/View/Helper/TimeHelper.php +++ b/src/View/Helper/TimeHelper.php @@ -19,6 +19,7 @@ use Cake\Error; use Cake\Utility\Hash; use Cake\View\Helper; +use Cake\View\Helper\StringTemplateTrait; use Cake\View\View; /** @@ -31,6 +32,8 @@ */ class TimeHelper extends Helper { + use StringTemplateTrait; + /** * Cake\Utility\Time instance * @@ -59,6 +62,7 @@ public function __construct(View $View, $settings = array()) { } else { throw new Error\Exception(sprintf('Class for %s could not be found', $settings['engine'])); } + $this->initStringTemplates(); } /** @@ -345,7 +349,7 @@ public function timeAgoInWords($dateTime, $options = array()) { $relativeDate = sprintf( '<%s%s>%s', $element['tag'], - $this->_parseAttributes($element, array('tag')), + $this->_templater->formatAttributes($element, array('tag')), $relativeDate, $element['tag'] );