Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6075595
CharacterGenerator.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
CharacterGenerator.php
View Options
<?php
namespace
Eris\Generator
;
use
Eris\Generator
;
use
Eris\Generators
;
use
Eris\Random\RandomRange
;
/**
* Generates character in the ASCII 0-127 range.
*
* @param array $characterSets Only supported charset: "basic-latin"
* @param string $encoding Only supported encoding: "utf-8"
* @return Generator\CharacterGenerator
*/
function
char
(
array
$characterSets
=
[
'basic-latin'
],
$encoding
=
'utf-8'
)
{
return
Generators
::
char
(
$characterSets
,
$encoding
);
}
/**
* Generates character in the ASCII 32-127 range, excluding non-printable ones
* or modifiers such as CR, LF and Tab.
*
* @return Generator\CharacterGenerator
*/
function
charPrintableAscii
()
{
return
Generators
::
charPrintableAscii
();
}
/**
* @template-implements Generator<string>
*/
class
CharacterGenerator
implements
Generator
{
private
$lowerLimit
;
private
$upperLimit
;
private
$shrinkingProgression
;
public
static
function
ascii
()
{
return
new
self
(
$lowerLimit
=
0
,
$upperLimit
=
127
);
}
public
static
function
printableAscii
()
{
return
new
self
(
$lowerLimit
=
32
,
$upperLimit
=
126
);
}
public
function
__construct
(
$lowerLimit
,
$upperLimit
)
{
$this
->
lowerLimit
=
$lowerLimit
;
$this
->
upperLimit
=
$upperLimit
;
$this
->
shrinkingProgression
=
ArithmeticProgression
::
discrete
(
$this
->
lowerLimit
);
}
public
function
__invoke
(
$_size
,
RandomRange
$rand
)
{
return
GeneratedValueSingle
::
fromJustValue
(
chr
(
$rand
->
rand
(
$this
->
lowerLimit
,
$this
->
upperLimit
)),
'character'
);
}
public
function
shrink
(
GeneratedValue
$element
)
{
$shrinkedValue
=
chr
(
$this
->
shrinkingProgression
->
next
(
ord
(
$element
->
unbox
())));
return
GeneratedValueSingle
::
fromJustValue
(
$shrinkedValue
,
'character'
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 5 2026, 08:55 (6 w, 2 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
8f/ac/4c4e12f2c13cf2c97b496dc6a6b1
Default Alt Text
CharacterGenerator.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment