aboutsummaryrefslogtreecommitdiff
path: root/lib/trails/Inflector.php
diff options
context:
space:
mode:
authorPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
committerPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
commit4459dd7917f4d1c34f40bb68f0e991e9c3d53e4c (patch)
tree5c07151ae61276d334e88f6309c30d439a85c12e /lib/trails/Inflector.php
parentda0022e5c1abbf9825ae76debaabdff7e8623bb4 (diff)
parent97a188592c679890a25c37ab78463add76a52ff7 (diff)
Merge branch 'main' into issue-3911issue-3911
Diffstat (limited to 'lib/trails/Inflector.php')
-rw-r--r--lib/trails/Inflector.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/trails/Inflector.php b/lib/trails/Inflector.php
new file mode 100644
index 0000000..bbc6b58
--- /dev/null
+++ b/lib/trails/Inflector.php
@@ -0,0 +1,44 @@
+<?php
+namespace Trails;
+
+/**
+ * The Inflector class is a namespace for inflections methods.
+ *
+ * @package trails
+ *
+ * @author mlunzena
+ * @copyright (c) Authors
+ * @version $Id: trails.php 7001 2008-04-04 11:20:27Z mlunzena $
+ */
+class Inflector
+{
+ /**
+ * Returns a camelized string from a lower case and underscored string by
+ * replacing slash with underscore and upper-casing each letter preceded
+ * by an underscore.
+ *
+ * @param string $word String to camelize.
+ * @return string Camelized string.
+ */
+ public static function camelize(string $word): string
+ {
+ $parts = explode('/', $word);
+ foreach ($parts as $key => $part) {
+ $parts[$key] = strtopascalcase($part);
+ }
+ return implode('_', $parts);
+ }
+
+ /**
+ * @param string $word
+ * @return string
+ */
+ public static function underscore(string $word): string
+ {
+ $parts = explode('_', $word);
+ foreach ($parts as $key => $part) {
+ $parts[$key] = strtosnakecase($part);
+ }
+ return implode('/', $parts);
+ }
+}