Select Git revision
-
Reiter, Christoph authored
This adds one config entry and injects the value into a service when the bundle gets loaded. See the README changes for how to set the config in the symfony app. Fixes #2
Reiter, Christoph authoredThis adds one config entry and injects the value into a service when the bundle gets loaded. See the README changes for how to set the config in the symfony app. Fixes #2
ExternalApi.php 944 B
<?php
declare(strict_types=1);
namespace DBP\API\StarterBundle\Service;
use DBP\API\StarterBundle\Entity\Place;
class ExternalApi implements PlaceProviderInterface
{
private $places;
public function __construct(MyCustomService $service)
{
$service = $service;
$this->places = [];
$place1 = new Place();
$place1->setIdentifier('graz');
$place1->setName('Graz');
$place2 = new Place();
$place2->setIdentifier('vienna');
$place2->setName('Vienna');
$this->places[] = $place1;
$this->places[] = $place2;
}
public function getPlaceById(string $identifier): ?Place
{
foreach ($this->places as $place) {
if ($place->getIdentifier() === $identifier) {
return $place;
}
}
return null;
}
public function getPlaces(): array
{
return $this->places;
}
}