本文整理汇总了PHP中fGrammar::humanize方法的典型用法代码示例。如果您正苦于以下问题:PHP fGrammar::humanize方法的具体用法?PHP fGrammar::humanize怎么用?PHP fGrammar::humanize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fGrammar
的用法示例。
在下文中一共展示了fGrammar::humanize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkURLFields
/**
* Validates the URL fields, requiring that any URL fields that have a value are valid URLs
*
* @param array &$messages The messages to display to the user
* @return void
*/
private function checkURLFields(&$messages)
{
foreach ($this->url_fields as $url_field) {
$value = trim(fRequest::get($url_field));
if (self::stringlike($value) && !preg_match('#^https?://[^ ]+$#iD', $value)) {
$messages[] = self::compose('%sPlease enter a URL in the form http://www.example.com/page', fValidationException::formatField(fGrammar::humanize($url_field)));
}
}
}
示例2: makeFieldName
/**
* Creates the name for a field taking into account custom field names
*
* @param string $field The field to get the name for
* @return string The field name
*/
private function makeFieldName($field)
{
if (isset($this->field_names[$field])) {
return $this->field_names[$field];
}
$suffix = '';
$bracket_pos = strpos($field, '[');
if ($bracket_pos !== FALSE) {
$array_dereference = substr($field, $bracket_pos);
$field = substr($field, 0, $bracket_pos);
preg_match_all('#(?<=\\[)[^\\[\\]]+(?=\\])#', $array_dereference, $array_keys, PREG_SET_ORDER);
$array_keys = array_map('current', $array_keys);
foreach ($array_keys as $array_key) {
if (is_numeric($array_key)) {
$suffix .= ' #' . ($array_key + 1);
} else {
$suffix .= ' ' . fGrammar::humanize($array_key);
}
}
}
return fGrammar::humanize($field) . $suffix;
}
示例3: printSortableColumn
/**
* Prints a sortable column header `a` tag
*
* The a tag will include the CSS class `'sortable_column'` and the
* direction being sorted, `'asc'` or `'desc'`.
*
* {{{
* #!php
* fCRUD::printSortableColumn('name', 'Name');
* }}}
*
* would create the following HTML based on the page context
*
* {{{
* #!html
* <!-- If name is the current sort column in the asc direction, the output would be -->
* <a href="?sort=name&dir=desc" class="sorted_column asc">Name</a>
*
* <!-- If name is not the current sort column, the output would be -->
* <a href="?sort-name&dir=asc" class="sorted_column">Name</a>
* }}}
*
* @param string $column The column to create the sortable header for
* @param string $column_name This will override the humanized version of the column
* @return void
*/
public static function printSortableColumn($column, $column_name = NULL)
{
if ($column_name === NULL) {
$column_name = fGrammar::humanize($column);
}
if (self::$sort_column == $column) {
$sort = $column;
$direction = self::$sort_direction == 'asc' ? 'desc' : 'asc';
} else {
$sort = $column;
$direction = 'asc';
}
$columns = array_merge(array('sort', 'dir'), array_keys(self::$search_values));
$values = array_merge(array($sort, $direction), array_values(self::$search_values));
$url = fHTML::encode(fURL::get() . fURL::replaceInQueryString($columns, $values));
$css_class = self::$sort_column == $column ? ' ' . self::$sort_direction : '';
$column_name = fHTML::prepare($column_name);
echo '<a href="' . $url . '" class="sortable_column' . $css_class . '">' . $column_name . '</a>';
}
示例4: printPiece
/**
* Prints out a piece of a template
*
* @param string $template The name of the template to print
* @param string $piece The piece of the template to print
* @param array $data The data to replace the variables with
* @return void
*/
private static function printPiece($template, $name, $data)
{
if (!isset(self::$templates[$template]['pieces'][$name])) {
throw new fProgrammerException('The template piece, %s, was not specified when defining the %s template', $name, $template);
}
$piece = self::$templates[$template]['pieces'][$name];
preg_match_all('#\\{\\{ (\\w+)((?:\\|\\w+)+)? \\}\\}#', $piece, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$variable = $match[1];
$value = !isset($data[$variable]) ? NULL : $data[$variable];
if (isset($match[2])) {
$filters = array_slice(explode('|', $match[2]), 1);
foreach ($filters as $filter) {
if (!in_array($filter, self::$filters)) {
throw new fProgrammerException('The filter specified, %1$s, is invalid. Must be one of: %2$s.', $filter, join(', ', self::$filters));
}
if (!strlen($value)) {
continue;
}
if ($filter == 'inflect') {
$value = fGrammar::inflectOnQuantity($data['total_records'], $value);
} elseif ($filter == 'lower') {
$value = fUTF8::lower($value);
} elseif ($filter == 'url_encode') {
$value = urlencode($value);
} elseif ($filter == 'humanize') {
$value = fGrammar::humanize($value);
}
}
}
$piece = preg_replace('#' . preg_quote($match[0], '#') . '#', fHTML::encode($value), $piece, 1);
}
echo $piece;
}
示例5: placeRSS
/**
* Prints an RSS `link` HTML tag to the output
*
* @param mixed $info The path or array containing the `'path'` to the RSS xml file. May also contain a `'title'` key for the title of the RSS feed.
* @return void
*/
protected function placeRSS($info)
{
if (!is_array($info)) {
$info = array('path' => $info, 'title' => fGrammar::humanize(preg_replace('#.*?([^/]+).(rss|xml)$#iD', '\\1', $info)));
}
if (!isset($info['title'])) {
throw new fProgrammerException('The RSS value %s is missing the title key', $info);
}
echo '<link rel="alternate" type="application/rss+xml" href="' . $info['path'] . '" title="' . $info['title'] . '" />' . "\n";
}
示例6: getRecordName
/**
* Returns the record name for a class
*
* The default record name is the result of calling fGrammar::humanize()
* on the class.
*
* @internal
*
* @param string $class The class name to get the record name of
* @return string The record name for the class specified
*/
public static function getRecordName($class)
{
if (!isset(self::$record_names[$class])) {
self::$record_names[$class] = fGrammar::humanize(preg_replace('#^.*\\\\#', '', $class));
}
// If fText is loaded, use it
if (class_exists('fText', FALSE)) {
return call_user_func(array('fText', 'compose'), str_replace('%', '%%', self::$record_names[$class]));
}
return self::$record_names[$class];
}
示例7: getRecordName
/**
* Returns the record name for a class
*
* The default record name is the result of calling fGrammar::humanize()
* on the class.
*
* @internal
*
* @param string $class The class name to get the record name of
* @return string The record name for the class specified
*/
public static function getRecordName($class)
{
if (!isset(self::$record_names[$class])) {
self::$record_names[$class] = fGrammar::humanize(preg_replace('#^.*\\\\#', '', $class));
}
return self::$record_names[$class];
}
示例8: getRecordName
/**
* Returns the record name for a class
*
* The default record name is the result of calling fGrammar::humanize()
* on the class.
*
* @internal
*
* @param string $class The class name to get the record name of
* @return string The record name for the class specified
*/
public static function getRecordName($class)
{
if (!isset(self::$record_names[$class])) {
self::$record_names[$class] = fGrammar::humanize($class);
}
return self::$record_names[$class];
}