Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
c50246c6
Commit
c50246c6
authored
Jul 07, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring Str class.
parent
607b23b7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
21 deletions
+23
-21
str.php
system/str.php
+23
-21
No files found.
system/str.php
View file @
c50246c6
...
@@ -70,28 +70,8 @@ class Str {
...
@@ -70,28 +70,8 @@ class Str {
{
{
$value
=
''
;
$value
=
''
;
// -----------------------------------------------------
$pool_length
=
strlen
(
$pool
=
static
::
pool
(
$type
))
-
1
;
// Get the proper character pool for the type.
// -----------------------------------------------------
switch
(
$type
)
{
case
'alpha'
:
$pool
=
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
break
;
default
:
$pool
=
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
}
// -----------------------------------------------------
// Get the pool length and split the pool into an array.
// -----------------------------------------------------
$pool_length
=
strlen
(
$pool
)
-
1
;
$pool
=
str_split
(
$pool
,
1
);
// -----------------------------------------------------
// Build the random string to the specified length.
// -----------------------------------------------------
for
(
$i
=
0
;
$i
<
$length
;
$i
++
)
for
(
$i
=
0
;
$i
<
$length
;
$i
++
)
{
{
$value
.=
$pool
[
mt_rand
(
0
,
$pool_length
)];
$value
.=
$pool
[
mt_rand
(
0
,
$pool_length
)];
...
@@ -100,4 +80,26 @@ class Str {
...
@@ -100,4 +80,26 @@ class Str {
return
$value
;
return
$value
;
}
}
/**
* Get a chracter pool.
*
* @param string $type
* @return string
*/
private
static
function
pool
(
$type
=
'alnum'
)
{
if
(
$type
==
'alnum'
)
{
return
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
}
elseif
(
$type
==
'alpha'
)
{
return
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
}
else
{
throw
new
\Exception
(
"Unrecognized random pool [
$type
]."
);
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment