Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getAbsoluteThumbnailUrl example
$mediaThumbnailEntity
=
new
MediaThumbnailEntity
(
)
;
$mediaThumbnailEntity
->
assign
(
[
'width' => 100,
'height' => 100,
]
)
;
$urlGenerator
=
new
UrlGenerator
(
new
FilenamePathnameStrategy
(
)
,
new
Filesystem
(
new
InMemoryFilesystemAdapter
(
)
,
[
'public_url' => 'http://localhost:8000'
]
)
)
;
static
::
assertSame
(
'http://localhost:8000/thumbnail/d0/b3/24/file.jpg_100x100',
$urlGenerator
->
getAbsoluteThumbnailUrl
(
$mediaEntity
,
$mediaThumbnailEntity
)
)
;
}
public
function
testRelativeMediaUrl
(
)
: void
{
$mediaEntity
=
new
MediaEntity
(
)
;
$mediaEntity
->
assign
(
[
'id' => Uuid::
randomHex
(
)
,
'fileName' => 'file.jpg',
]
)
;
$media
->
setThumbnails
(
unserialize
(
$media
->
getThumbnailsRo
(
)
)
)
;
}
else
{
$media
->
setThumbnails
(
new
MediaThumbnailCollection
(
)
)
;
}
}
}
}
private
function
addThumbnailUrl
(
MediaThumbnailEntity
$thumbnail
, MediaEntity
$media
)
: void
{
$thumbnail
->
setUrl
(
$this
->urlGenerator->
getAbsoluteThumbnailUrl
(
$media
,
$thumbnail
)
)
;
}
}
$mediaThumbnailEntity
=
new
MediaThumbnailEntity
(
)
;
$mediaThumbnailEntity
->
assign
(
[
'width' => 100,
'height' => 100,
]
)
;
$urlGenerator
=
new
UrlGenerator
(
new
FilenamePathnameStrategy
(
)
,
new
Filesystem
(
new
InMemoryFilesystemAdapter
(
)
,
[
'public_url' => 'http://localhost:8000'
]
)
)
;
static
::
assertSame
(
'http://localhost:8000/thumbnail/d0/b3/24/file.jpg_100x100',
$urlGenerator
->
getAbsoluteThumbnailUrl
(
$mediaEntity
,
$mediaThumbnailEntity
)
)
;
}
public
function
testRelativeMediaUrl
(
)
: void
{
$mediaEntity
=
new
MediaEntity
(
)
;
$mediaEntity
->
assign
(
[
'id' => Uuid::
randomHex
(
)
,
'fileName' => 'file.jpg',
]
)
;