/** * Replaces constant identifiers in a value. * * If the value is an array replacements are made recursively. * * @param mixed The value on which to run the replacement procedure * * @return string The new value */ public static function replaceConstants($value) { if (is_array($value)) { array_walk_recursive($value, create_function('&$value', '$value = sfToolkit::replaceConstants($value);')); } else { $value = sfToolkit::replaceConstants($value); } return $value; }
{ $t->is(sfToolkit::literalize(strtoupper($param)), null, sprintf('::literalize() returns null with "%s"', strtoupper($param))); } $t->is(sfToolkit::literalize(' '.$param.' '), null, sprintf('::literalize() returns null with "%s"', ' '.$param.' ')); } // ::replaceConstants() $t->diag('::replaceConstants()'); sfConfig::set('foo', 'bar'); $t->is(sfToolkit::replaceConstants('my value with a %foo% constant'), 'my value with a bar constant', '::replaceConstantsCallback() replaces constants enclosed in %'); $t->is(sfToolkit::replaceConstants('%Y/%m/%d %H:%M'), '%Y/%m/%d %H:%M', '::replaceConstantsCallback() does not replace unknown constants'); sfConfig::set('bar', null); $t->is(sfToolkit::replaceConstants('my value with a %bar% constant'), 'my value with a constant', '::replaceConstantsCallback() replaces constants enclosed in % even if value is null'); $t->is(sfToolkit::replaceConstants('my value with a %foobar% constant'), 'my value with a %foobar% constant', '::replaceConstantsCallback() returns the original string if the constant is not defined'); $t->is(sfToolkit::replaceConstants('my value with a %foo\'bar% constant'), 'my value with a %foo\'bar% constant', '::replaceConstantsCallback() returns the original string if the constant is not defined'); $t->is(sfToolkit::replaceConstants('my value with a %foo"bar% constant'), 'my value with a %foo"bar% constant', '::replaceConstantsCallback() returns the original string if the constant is not defined'); // ::isPathAbsolute() $t->diag('::isPathAbsolute()'); $t->is(sfToolkit::isPathAbsolute('/test'), true, '::isPathAbsolute() returns true if path is absolute'); $t->is(sfToolkit::isPathAbsolute('\\test'), true, '::isPathAbsolute() returns true if path is absolute'); $t->is(sfToolkit::isPathAbsolute('C:\\test'), true, '::isPathAbsolute() returns true if path is absolute'); $t->is(sfToolkit::isPathAbsolute('d:/test'), true, '::isPathAbsolute() returns true if path is absolute'); $t->is(sfToolkit::isPathAbsolute('test'), false, '::isPathAbsolute() returns false if path is relative'); $t->is(sfToolkit::isPathAbsolute('../test'), false, '::isPathAbsolute() returns false if path is relative'); $t->is(sfToolkit::isPathAbsolute('..\\test'), false, '::isPathAbsolute() returns false if path is relative'); // ::stripComments() $t->diag('::stripComments()'); $php = <<<EOF
/** * Returns HTML code for an action link. * * @param string The action name * @param array The parameters * @param boolean Whether to add a primary key link or not * * @return string HTML code */ public function getLinkToAction($actionName, $params, $pk_link = false) { $options = isset($params['params']) ? sfToolkit::stringToArray($params['params']) : array(); // default values if ($actionName[0] == '_') { $actionName = substr($actionName, 1); $name = $actionName; $icon = sfConfig::get('sf_admin_web_dir') . '/images/' . $actionName . '_icon.png'; $action = $actionName; if ($actionName == 'delete') { $options['post'] = true; if (!isset($options['confirm'])) { $options['confirm'] = 'Are you sure?'; } } } else { $name = isset($params['name']) ? $params['name'] : $actionName; $icon = isset($params['icon']) ? sfToolkit::replaceConstants($params['icon']) : sfConfig::get('sf_admin_web_dir') . '/images/default_icon.png'; $action = isset($params['action']) ? $params['action'] : 'List' . sfInflector::camelize($actionName); } $url_params = $pk_link ? '?' . $this->getPrimaryKeyUrlParams() : '\''; $phpOptions = var_export($options, true); // little hack $phpOptions = preg_replace("/'confirm' => '(.+?)(?<!\\\\)'/", '\'confirm\' => __(\'$1\')', $phpOptions); return '<li>[?php echo link_to(image_tag(\'' . $icon . '\', array(\'alt\' => __(\'' . $name . '\'), \'title\' => __(\'' . $name . '\'))), \'' . $this->getModuleName() . '/' . $action . $url_params . ($options ? ', ' . $phpOptions : '') . ') ?]</li>' . "\n"; }
<?php $this->configCache->registerConfigHandler('config/include_path.yml', 'sfSimpleYamlConfigHandler'); $data = $this->configCache->checkConfig('config/include_path.yml', true); if ($data) { $data = (include $data); $paths = array(); foreach ($data['include_path'] as $name => $include_path) { $include_path = sfToolkit::replaceConstants($include_path); $paths[] = $include_path; } set_include_path(get_include_path() . PATH_SEPARATOR . implode(PATH_SEPARATOR, $paths)); }