From f8e5b951a56d2fbce76dde7b2fb3e99f63f06d92 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 12 Apr 2011 18:30:57 -0600 Subject: [PATCH] flattens array for better looking cache if the array is associative --- lib/generator/sfThemeGenerator.class.php | 4 +-- lib/util/sfThemeTokenParser.class.php | 46 ++++++++++++++++++------ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/lib/generator/sfThemeGenerator.class.php b/lib/generator/sfThemeGenerator.class.php index 6527b7e..a8929d8 100644 --- a/lib/generator/sfThemeGenerator.class.php +++ b/lib/generator/sfThemeGenerator.class.php @@ -116,8 +116,6 @@ public function configToOptions($configs, $prefix = '') public function linkTo($action, $params) { - $action = strpos($action, '_') === 0 ? substr($action, 1) : $action; - $forObject = isset($params['object_link']) && $params['object_link']; $params = array_merge(array('class' => $action), $params); @@ -312,7 +310,7 @@ protected function renderCredentials($credentials) $credentials = $credentials[0]; } - return $this->asPhp($credentials); + return is_array($credentials) ? $this->parser->renderArray($credentials) : $this->asPhp($credentials); } // Provides a hook to change generated files diff --git a/lib/util/sfThemeTokenParser.class.php b/lib/util/sfThemeTokenParser.class.php index a701c16..733230b 100644 --- a/lib/util/sfThemeTokenParser.class.php +++ b/lib/util/sfThemeTokenParser.class.php @@ -31,17 +31,22 @@ public function renderArray($array) $arrayLines = array(); foreach ($array as $key => $value) { $line = ' '; - if (is_int($key)) { - $line .= $key; - } - elseif (is_bool($key)) { - $line .= $this->asPhp($key); - } - else { - $line .= $this->renderPhpText($key); - } - $line .= ' => '; + $isAssociative = $this->arrayKeyIsAssociative($key, $array); + + if (!$isAssociative) { + if (is_int($key)) { + $line .= $key; + } + elseif (is_bool($key)) { + $line .= $this->asPhp($key); + } + else { + $line .= $this->renderPhpText($key); + } + + $line .= ' => '; + } if (is_int($value)) { $line .= $value; @@ -200,4 +205,25 @@ public function getTokenMatches($tokenMatches) { return $this->tokenMatches; } + + protected function arrayKeyIsAssociative($key, $array) + { + if (!is_int($key) || !isset($array[$key]) || count($array) < $key) { + return false; + } + + $i = 0; + foreach ($array as $value) { + if ($i == $key) { + return true; + } + + if ($i > $key) { + return false; + } + $i++; + } + + return false; + } }