Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
validateFileNameDoesNotEndOrStartWithDot example
/** * @throws MediaException */
public
function
validateFileName
(
string
$fileName
)
: void
{
if
(
empty
(
$fileName
)
)
{
throw
MediaException::
emptyMediaFilename
(
)
;
}
$this
->
validateFileNameDoesNotEndWithSpaces
(
$fileName
)
;
$this
->
validateFileNameDoesNotEndOrStartWithDot
(
$fileName
)
;
$this
->
validateFileNameDoesNotContainForbiddenCharacter
(
$fileName
)
;
$this
->
validateFileNameDoesNotContainC0Character
(
$fileName
)
;
}
private
function
validateFileNameDoesNotEndOrStartWithDot
(
string
$fileName
)
: void
{
if
(
mb_substr
(
$fileName
, 0, 1
)
=== '.'
)
{
throw
MediaException::
illegalFileName
(
$fileName
, 'Filename must not start with a "." (dot).'
)
;
}
if
(
mb_substr
(
$fileName
,
mb_strlen
(
$fileName
)
- 1
)
=== '.'
)
{