Skip to content

Commit

Permalink
Remove protected methods that no longer have callers.
Browse files Browse the repository at this point in the history
Remove duplicated code from Helper that is now available in
StringTemplate, and the StringTemplateTrait.
  • Loading branch information
markstory committed Mar 7, 2014
1 parent 87a6be0 commit 5b93532
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 80 deletions.
78 changes: 0 additions & 78 deletions src/View/Helper.php
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/HtmlHelper.php
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/View/Helper/TimeHelper.php
Expand Up @@ -19,6 +19,7 @@
use Cake\Error;
use Cake\Utility\Hash;
use Cake\View\Helper;
use Cake\View\Helper\StringTemplateTrait;
use Cake\View\View;

/**
Expand All @@ -31,6 +32,8 @@
*/
class TimeHelper extends Helper {

use StringTemplateTrait;

/**
* Cake\Utility\Time instance
*
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -345,7 +349,7 @@ public function timeAgoInWords($dateTime, $options = array()) {
$relativeDate = sprintf(
'<%s%s>%s</%s>',
$element['tag'],
$this->_parseAttributes($element, array('tag')),
$this->_templater->formatAttributes($element, array('tag')),
$relativeDate,
$element['tag']
);
Expand Down

0 comments on commit 5b93532

Please sign in to comment.