Framework  3.9
StringTypeRenderer Class Reference
+ Inheritance diagram for StringTypeRenderer:
+ Collaboration diagram for StringTypeRenderer:

Public Member Functions

 StringTypeRenderer ()
 
- Public Member Functions inherited from AbstractTypeRenderer
 AbstractTypeRenderer ()
 

Static Public Member Functions

static format ($value, $template="")
 
static phone ($phone)
 
- Static Public Member Functions inherited from AbstractTypeRenderer
static translationDateTemplate ($template, $includeTime=true)
 

Detailed Description

Definition at line 40 of file string_type_renderer.inc.

Member Function Documentation

◆ format()

static StringTypeRenderer::format (   $value,
  $template = "" 
)
static

Reimplemented from AbstractTypeRenderer.

Definition at line 46 of file string_type_renderer.inc.

47  {
48  if (!$template) return $value;
49 
50  if ($template[0] == '/')
51  {
52  $clauses = array();
53  if (preg_match("/(\\/.*?\\/)(.*?)\\//", $template, $clauses))
54  {
55  return preg_replace($clauses[1], $clauses[2], $value);
56  }
57  }
58 
59  if ($template[0] == '|')
60  {
61  $clauses = array();
62  if (preg_match("/(|.*?|)(.*?)|/", $template, $clauses))
63  {
64  return preg_replace($clauses[1], $clauses[2], $value);
65  }
66  }
67 
68  switch($template)
69  {
70  case "codify":
71  return codify($value);
72 
73  case "prettify":
74  return prettify($value);
75 
76  case "upper":
77  return strtoupper($value);
78 
79  case "lower":
80  return strtolower($value);
81 
82  case "ucfirst":
83  return ucfirst($value);
84 
85  case "lcfirst":
86  return lcfirst($value);
87 
88  case "ucwords":
89  return ucwords(strtolower($value));
90 
91  case "stripHTML":
92  return stripHTML($value);
93 
94  case "jsSafe":
95  return jsSafe($value);
96 
97  case "html":
98  return formatAsHTML($value);
99 
100  case "htmlSafe":
101  return htmlsafe($value);
102 
103  case "xml":
104  return xmlEntities($value);
105 
106  case "xmlSafe":
107  return xmlEntities(stripHTML($value));
108 
109  case "url":
110  return urlencode($value);
111 
112  case "phone":
113  return StringTypeRenderer::phone($value);
114 
115  case "firstSentence":
116  return firstSentence($value);
117 
118  case "pluralize":
119  return pluralize($value);
120  default:
121 
122  if (is_numeric($template))
123  {
124  return ellipsis(stripHTML($value), $template, true);
125  }
126  else if (strpos($template, "|") !== false)
127  {
128  $options = explode("|", $template);
129  return $value ? $options[0] : $options[1];
130  }
131  }
132 
133  return $value;
134  }
codify($name)
Takes a text string and converts it into a code-compliant format, suitable for use as a variable name...
Definition: functions.inc:1399
xmlEntities($string)
Function to provide html to XML entity renaming.
Definition: functions.inc:1903
pluralize($text, $count=0)
Takes a singular string and makes it plural.
Definition: functions.inc:1428
stripHTML($text)
Definition: functions.inc:847
firstSentence($text)
Returns the first sentence of the supplied text.
Definition: functions.inc:839
jsSafe($str, $escapeEntities=false)
Utility function to escape a string correctly for use in a Javascript client-side call.
Definition: functions.inc:434
formatAsHTML($text)
Takes a string and formats it for display as HTML, removing any HTML tags it contains,...
Definition: functions.inc:1456
ellipsis($txt, $max, $wholeWord=false)
Truncate the supplied text at the given maximum length.
Definition: functions.inc:779
prettify($name)
Takes a variable or field name and converts it into a human-readable version (assuming that the origi...
Definition: functions.inc:1413
htmlsafe($str)
Definition: functions.inc:451

◆ phone()

static StringTypeRenderer::phone (   $phone)
static

Definition at line 146 of file string_type_renderer.inc.

147  {
148  $phone = preg_replace("/[^0-9]/", "", $phone);
149 
150  if(strlen($phone) == 7)
151  return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
152  elseif(strlen($phone) == 10)
153  return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
154  else
155  return $phone;
156  }

◆ StringTypeRenderer()

StringTypeRenderer::StringTypeRenderer ( )

Definition at line 42 of file string_type_renderer.inc.

43  {
44  }

The documentation for this class was generated from the following file: