Skip to content
Permalink
Browse files

Remove protected methods that no longer have callers.

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 5b93532e31e2c73b8b51cb7f904d2dd7099ff810
Showing with 6 additions and 80 deletions.
  1. +0 −78 src/View/Helper.php
  2. +1 −1 src/View/Helper/HtmlHelper.php
  3. +5 −1 src/View/Helper/TimeHelper.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.
*
@@ -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);
@@ -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</%s>',
$element['tag'],
$this->_parseAttributes($element, array('tag')),
$this->_templater->formatAttributes($element, array('tag')),
$relativeDate,
$element['tag']
);

0 comments on commit 5b93532

Please sign in to comment.
You can’t perform that action at this time.