Skip to content

Commit 8339034

Browse files
committed
use data object for image preview
1 parent 85242ff commit 8339034

3 files changed

Lines changed: 74 additions & 10 deletions

File tree

src/Core/ImagePreview.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of littleredbutton/bigbluebutton-api-php.
7+
*
8+
* littleredbutton/bigbluebutton-api-php is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* littleredbutton/bigbluebutton-api-php is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with littleredbutton/bigbluebutton-api-php. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
namespace BigBlueButton\Core;
22+
23+
class ImagePreview
24+
{
25+
/** @var int */
26+
private $width;
27+
28+
/** @var int */
29+
private $height;
30+
31+
/** @var string */
32+
private $alt;
33+
34+
/** @var string */
35+
private $url;
36+
37+
public function __construct(int $width, int $height, string $alt, string $url)
38+
{
39+
$this->width = $width;
40+
$this->height = $height;
41+
$this->alt = $alt;
42+
$this->url = $url;
43+
}
44+
45+
public function getWidth(): int
46+
{
47+
return $this->width;
48+
}
49+
50+
public function getHeight(): int
51+
{
52+
return $this->height;
53+
}
54+
55+
public function getAlt(): string
56+
{
57+
return $this->alt;
58+
}
59+
60+
public function getUrl(): string
61+
{
62+
return $this->url;
63+
}
64+
}

src/Core/PlaybackFormat.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class PlaybackFormat
3535
/** @var int */
3636
private $length;
3737

38-
/** @var array */
38+
/** @var ImagePreview[] */
3939
private $imagePreviews;
4040

4141
/** @var \SimpleXMLElement */
@@ -78,7 +78,7 @@ public function hasImagePreviews(): bool
7878

7979
/**
8080
*
81-
* @return array<int, array{width: int, height: int, alt: string, url: string}>
81+
* @return ImagePreview[]
8282
*/
8383
public function getImagePreviews(): array
8484
{
@@ -91,12 +91,12 @@ public function getImagePreviews(): array
9191
foreach ($this->imagePreviewsRaw->children() as $image) {
9292
$attributes = $image->attributes();
9393

94-
$this->imagePreviews[] = [
95-
'width' => (int) $attributes->width->__toString(),
96-
'height' => (int) $attributes->height->__toString(),
97-
'alt' => $attributes->alt->__toString(),
98-
'url' => $image->__toString(),
99-
];
94+
$this->imagePreviews[] = new ImagePreview(
95+
(int) $attributes->width->__toString(),
96+
(int) $attributes->height->__toString(),
97+
$attributes->alt->__toString(),
98+
$image->__toString()
99+
);
100100
}
101101
}
102102

tests/unit/Responses/GetRecordingsResponseTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function testImagePreviews()
112112

113113
$this->assertCount(3, $previews);
114114

115-
$this->assertEquals('Welcome to', $previews[0]['alt']);
116-
$this->assertEquals('https://demo.bigbluebutton.org/presentation/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1530718721134/thumbnails/thumb-1.png', $previews[0]['url']);
115+
$this->assertEquals('Welcome to', $previews[0]->getAlt());
116+
$this->assertEquals('https://demo.bigbluebutton.org/presentation/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1530718721134/thumbnails/thumb-1.png', $previews[0]->getUrl());
117117
}
118118
}

0 commit comments

Comments
 (0)