summaryrefslogtreecommitdiff
path: root/vendor/gregwar/captcha/PhraseBuilder.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gregwar/captcha/PhraseBuilder.php')
-rw-r--r--vendor/gregwar/captcha/PhraseBuilder.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/vendor/gregwar/captcha/PhraseBuilder.php b/vendor/gregwar/captcha/PhraseBuilder.php
new file mode 100644
index 00000000..b94bd61c
--- /dev/null
+++ b/vendor/gregwar/captcha/PhraseBuilder.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Gregwar\Captcha;
+
+/**
+ * Generates random phrase
+ *
+ * @author Gregwar <g.passault@gmail.com>
+ */
+class PhraseBuilder implements PhraseBuilderInterface
+{
+ /**
+ * Generates random phrase of given length with given charset
+ */
+ public function build($length = 5, $charset = 'abcdefghijklmnpqrstuvwxyz123456789')
+ {
+ $phrase = '';
+ $chars = str_split($charset);
+
+ for ($i = 0; $i < $length; $i++) {
+ $phrase .= $chars[array_rand($chars)];
+ }
+
+ return $phrase;
+ }
+
+ /**
+ * "Niceize" a code
+ */
+ public function niceize($str)
+ {
+ return strtr(strtolower($str), '01', 'ol');
+ }
+}