Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
illegalUrl example
public
function
fetchFileFromURL
(
Request
$request
, string
$fileName
)
: MediaFile
{
if
(
!
$this
->enableUrlUploadFeature
)
{
throw
MediaException::
disableUrlUploadFeature
(
)
;
}
$url
=
$this
->
getUrlFromRequest
(
$request
)
;
if
(
$this
->enableUrlValidation && !
$this
->fileUrlValidator->
isValid
(
$url
)
)
{
throw
MediaException::
illegalUrl
(
$url
)
;
}
$extension
=
$this
->
getExtensionFromRequest
(
$request
)
;
$inputStream
=
$this
->
openSourceFromUrl
(
$url
)
;
$destStream
=
$this
->
openDestinationStream
(
$fileName
)
;
try
{
$writtenBytes
=
$this
->
copyStreams
(
$inputStream
,
$destStream
,
$this
->maxFileSize
)
;
}
finally
{
fclose
(
$inputStream
)
;
static
::
assertEquals
(
Response::HTTP_BAD_REQUEST,
$exception
->
getStatusCode
(
)
)
;
static
::
assertEquals
(
MediaException::MEDIA_INVALID_URL,
$exception
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'Provided URL "http://invalid-url" is invalid.',
$exception
->
getMessage
(
)
)
;
static
::
assertEquals
(
[
'url' =>
$url
]
,
$exception
->
getParameters
(
)
)
;
}
public
function
testIllegalUrl
(
)
: void
{
$url
= 'http://illegal-url';
$exception
= MediaException::
illegalUrl
(
$url
)
;
static
::
assertEquals
(
Response::HTTP_BAD_REQUEST,
$exception
->
getStatusCode
(
)
)
;
static
::
assertEquals
(
MediaException::MEDIA_ILLEGAL_URL,
$exception
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'Provided URL "http://illegal-url" is not allowed.',
$exception
->
getMessage
(
)
)
;
static
::
assertEquals
(
[
'url' =>
$url
]
,
$exception
->
getParameters
(
)
)
;
}
public
function
testDisableUrlUploadFeature
(
)
: void
{
$exception
= MediaException::
disableUrlUploadFeature
(
)
;