Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F94057010
AlmanacNames.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Dec 3, 13:50
Size
1 KB
Mime Type
text/x-php
Expires
Thu, Dec 5, 13:50 (2 d)
Engine
blob
Format
Raw Data
Handle
22725735
Attached To
rPH Phabricator
AlmanacNames.php
View Options
<?php
final
class
AlmanacNames
extends
Phobject
{
public
static
function
validateServiceOrDeviceName
(
$name
)
{
if
(
strlen
(
$name
)
<
3
)
{
throw
new
Exception
(
pht
(
'Almanac service and device names must be at least 3 '
.
'characters long.'
));
}
if
(!
preg_match
(
'/^[a-z0-9.-]+
\z
/'
,
$name
))
{
throw
new
Exception
(
pht
(
'Almanac service and device names may only contain lowercase '
.
'letters, numbers, hyphens, and periods.'
));
}
if
(
preg_match
(
'/(^|
\\
.)
\d
+(
\z
|
\\
.)/'
,
$name
))
{
throw
new
Exception
(
pht
(
'Almanac service and device names may not have any segments '
.
'containing only digits.'
));
}
if
(
preg_match
(
'/
\.\.
/'
,
$name
))
{
throw
new
Exception
(
pht
(
'Almanac service and device names may not contain multiple '
.
'consecutive periods.'
));
}
if
(
preg_match
(
'/
\\
.-|-
\\
./'
,
$name
))
{
throw
new
Exception
(
pht
(
'Amanac service and device names may not contain hyphens adjacent '
.
'to periods.'
));
}
if
(
preg_match
(
'/--/'
,
$name
))
{
throw
new
Exception
(
pht
(
'Almanac service and device names may not contain multiple '
.
'consecutive hyphens.'
));
}
if
(!
preg_match
(
'/^[a-z0-9].*[a-z0-9]
\z
/'
,
$name
))
{
throw
new
Exception
(
pht
(
'Almanac service and device names must begin and end with a letter '
.
'or number.'
));
}
}
}
Event Timeline
Log In to Comment