本文整理汇总了PHP中sfToolkit::replaceConstants方法的典型用法代码示例。如果您正苦于以下问题:PHP sfToolkit::replaceConstants方法的具体用法?PHP sfToolkit::replaceConstants怎么用?PHP sfToolkit::replaceConstants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfToolkit
的用法示例。
在下文中一共展示了sfToolkit::replaceConstants方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: replaceConstants
/**
* 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;
}
示例2: sprintf
{
$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
示例3: getLinkToAction
/**
* 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";
}
示例4: array
<?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));
}