-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInFileSystemPersistence.php
58 lines (49 loc) · 2.63 KB
/
InFileSystemPersistence.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace App\Infrastructure\Persistence;
use App\Domain\Ad;
use App\Domain\Picture;
final class InFileSystemPersistence
{
private array $ads = [];
private array $pictures = [];
public function __construct()
{
array_push($this->ads, new Ad(1, 'CHALET', 'Este piso es una ganga, compra, compra, COMPRA!!!!!', [], 300, null, null, null));
array_push($this->ads, new Ad(2, 'FLAT', 'Nuevo ático céntrico recién reformado. No deje pasar la oportunidad y adquiera este ático de lujo', [4], 300, null, null, null));
array_push($this->ads, new Ad(3, 'CHALET', '', [2], 300, null, null, null));
array_push($this->ads, new Ad(4, 'FLAT', 'Ático céntrico muy luminoso y recién reformado, parece nuevo', [5], 300, null, null, null));
array_push($this->ads, new Ad(5, 'FLAT', 'Pisazo,', [3, 8], 300, null, null, null));
array_push($this->ads, new Ad(6, 'GARAGE', '', [6], 300, null, null, null));
array_push($this->ads, new Ad(7, 'GARAGE', 'Garaje en el centro de Albacete', [], 300, null, null, null));
array_push($this->ads, new Ad(8, 'CHALET', 'Maravilloso chalet situado en lAs afueras de un pequeño pueblo rural. El entorno es espectacular, las vistas magníficas. ¡Cómprelo ahora!', [1, 7], 300, null, null, null));
array_push($this->pictures, new Picture(1, 'https://www.idealista.com/pictures/1', 'SD'));
array_push($this->pictures, new Picture(2, 'https://www.idealista.com/pictures/2', 'HD'));
array_push($this->pictures, new Picture(3, 'https://www.idealista.com/pictures/3', 'SD'));
array_push($this->pictures, new Picture(4, 'https://www.idealista.com/pictures/4', 'HD'));
array_push($this->pictures, new Picture(5, 'https://www.idealista.com/pictures/5', 'SD'));
array_push($this->pictures, new Picture(6, 'https://www.idealista.com/pictures/6', 'SD'));
array_push($this->pictures, new Picture(7, 'https://www.idealista.com/pictures/7', 'SD'));
array_push($this->pictures, new Picture(8, 'https://www.idealista.com/pictures/8', 'HD'));
}
public function getAds(): array
{
return $this->ads;
}
/**
* Retrieves a picture by its unique identifier.
*
* @param int $pictureId The ID of the picture to retrieve.
*
* @return Picture|null The Picture object if found, or null if not found.
*/
public function getPictureById(int $pictureId): ?Picture
{
foreach ($this->pictures as $picture) {
if ($picture->getId() === $pictureId) {
return $picture;
}
}
return null;
}
}