lyssal/simple-location-bundle

The simple location bundle permits create dynamic typed locations (countries, cities, etc).

0.3 2024-10-15 15:09 UTC

This package is auto-updated.

Last update: 2024-10-15 15:10:59 UTC


README

The simple location bundle permits create dynamic typed locations.

Installation

composer require lyssal/simple-location-bundle

Usage

Create your Location entity

namespace App\Entity\Location;

use Doctrine\ORM\Mapping as ORM;
use Lyssal\SimpleLocationBundle\Doctrine\Repository\LocationRepository;
use Lyssal\SimpleLocationBundle\Entity\Location as LyssalLocation;

#[ORM\Entity(repositoryClass: LocationRepository::class)]
class Location extends LyssalLocation
{
    // If you want to add properties
}

Exemples of use

$continent = (new LocationType())->setName('Continent');
$country = (new LocationType())->setName('Country')->addParent($continent);
$city = (new LocationType())->setName('City')->addParent($country);

$europa = (new Location())->setName('Europe')->setType($continent);
$america = (new Location())->setName('America')->setType($continent);
$asia = (new Location())->setName('Asia')->setType($continent);

$france = (new Location())->setName('France')->setType($country)->addParent($europa);
$italy = (new Location())->setName('Italy')->setType($country)->addParent($europa);
$sovietUnion = (new Location())->setName('Soviet Union')->setType($country)->addParent($europa)->addParent($asia);

$paris = (new Location())->setName('Paris')->setType($city)->addParent($france);

$countrySet = (new LocationType())->setName('Country set')->addChild($country);

$northAmerica = (new Location())->setName('North America')->setType($countrySet)->addParent($america);
$usa = (new Location())->setName('United States of America')->setType($country)->addParent($america)->addParent($northAmerica);

$europeanUnion = (new Location())->setName('European Union')->setType($countrySet)->addParent($europa)->addChild($france)->addChild($italy);

$germany = (new Location())->setName('Germany')->setType($country)->addParent($europa)->addParent($europeanUnion);
$westGermany = (new Location())->setName('Federal Republic of Germany')->setType($country)->addParent($germany)->addParent($europa)->addParent($europeanUnion);
$eastGermany = (new Location())->setName('German Democratic Republic')->setType($country)->addParent($sovietUnion)->addParent($germany)->addParent($europa);