2017 © Pedro PelĂĄez
 

library php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

image

wnx/php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

  • Wednesday, May 9, 2018
  • by stefanzweifel
  • Repository
  • 1 Watchers
  • 3 Stars
  • 795 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 15 % Grown

The README.md

🇹🇭 PHP Swiss Cantons

tests codecov Latest Stable Version Total Downloads License, (*1)

Using Javascript? Check out @stefanzweifel/js-swiss-cantons., (*2)

Installation

The easiest way to install the package is by using composer. The package requires PHP 8.2., (*3)

composer require "wnx/php-swiss-cantons"

Usage

Use the CantonManager Class to interact with this package. Below you find an example how you can use with in the Laravel Framework. Further you find all public API methods for CantonManager and Canton., (*4)

<?php 

use Wnx\SwissCantons\CantonManager;

$cantonManager = new CantonManager();

/** @var \Wnx\SwissCantons\Canton $canton */
$canton = $cantonManager->getByAbbreviation('zh');
$canton = $cantonManager->getByName('Zurigo');
$canton = $cantonManager->getByZipcode(8000);

// "ZĂŒrich"
$cantonName = $canton->setLanguage('de')->getName();

CantonManager

Use the CantonManager to find a Canton. It will return a new Instance of Canton or throws an Exception if no Canton could be found for the abbreviation, name or zipcode., (*5)

getByAbbreviation()

Find a Canton by its abbreviation. See this list for available abbreviations., (*6)

$cantonManager = new Wnx\SwissCantons\CantonManager();

/** @var \Wnx\SwissCantons\Canton $canton */
$canton = $cantonManager->getByAbbreviation('GR');

getByName()

Search for a Canton by it's name. The name must exactly match one of the translations of the Canton (German, French, Italian, Romansh or English)., (*7)

$cantonManager = new Wnx\SwissCantons\CantonManager();

/** @var \Wnx\SwissCantons\Canton $canton */
$canton = $cantonManager->getByName('ZĂŒrich');

getByZipcode()

Search for a Canton by a zipcode., (*8)

$cantonManager = new Wnx\SwissCantons\CantonManager();

/** @var \Wnx\SwissCantons\Canton $canton */
$canton = $cantonManager->getByZipcode(3005);

Canton

setLanguage($string = 'en')

Set the language, which should be used to display the name of the canton. The following languages are currently supported., (*9)

  • German (de)
  • French (fr)
  • Italian (it)
  • Romansh (rm)
  • English (en, default)

The method returns the current instance of Canton for easier method chaining., (*10)

$canton->setLanguage('rm');
$canton->setLanguage('fr')->getName();

getName()

Return the Name for the given Canton. If the method is used without calling the setLanguage() method first, it will return the name in English., (*11)

$canton->getName(); // Grisons
$canton->setLanguage('de')->getName(); // GraubĂŒnden

getAbbreviation()

Return the offical abbreviation for the given Canton., (*12)

$canton->getAbbreviation(); // e.g. ZH

Cantons

This class is used internally but can also be used in your own project if you need a list of all cantons, (*13)

getAll()

Returns an array containg Wnx\SwissCantons\Canton objects., (*14)

use Wnx\SwissCantons\Cantons;

$cantons = (new Cantons)->getAll();

getAllAsArray($defaultLanguage = 'en')

Returns a one dimensionl array of all Cantons. The key is the abbreviation. The value will be the translated name of the Canton. The default language is English. Pass one of the valid languages to the method, to localize the names., (*15)

use Wnx\SwissCantons\Cantons;

$cantons = (new Cantons)->getAllAsArray('en');

$cantonsAsArray = $cantons->getAllAsArray(); 

// var_dump($cantonsAsArray);
// [
//     'ZH' => 'Zurich', 
//     'GE' => 'Geneva',
//     // ...
// ]

Security

If you discover a security vulnerability within this package, please send an e-mail to stefan@stefanzweifel.dev. All security vulnerabilities will be promptly addressed., (*16)

Data Sources

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository., (*17)

Credits

License

This project is licensed under the MIT License - see the LICENSE file for details., (*18)

The Versions

09/05 2018

dev-master

9999999-dev https://github.com/stefanzweifel/php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

swiss cantons canton

01/11 2017

2.0.1

2.0.1.0 https://github.com/stefanzweifel/php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

swiss cantons canton

31/10 2017

2.0.0

2.0.0.0 https://github.com/stefanzweifel/php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

swiss cantons canton

26/07 2017

1.4.0

1.4.0.0 https://github.com/stefanzweifel/php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

  Sources   Download

MIT

The Development Requires

swiss cantons canton

03/05 2017

1.3.0

1.3.0.0 https://github.com/stefanzweifel/php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

  Sources   Download

MIT

The Development Requires

swiss cantons canton

04/10 2016

1.2.1

1.2.1.0 https://github.com/stefanzweifel/php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

  Sources   Download

MIT

The Development Requires

swiss cantons canton

16/09 2016

1.2.0

1.2.0.0 https://github.com/stefanzweifel/php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

  Sources   Download

MIT

The Development Requires

swiss cantons canton

16/09 2016

1.1.0

1.1.0.0 https://github.com/stefanzweifel/php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

  Sources   Download

MIT

The Requires

 

The Development Requires

swiss cantons canton

14/07 2016

1.0.0

1.0.0.0 https://github.com/stefanzweifel/php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

  Sources   Download

MIT

The Requires

 

The Development Requires

swiss cantons canton

29/06 2016

0.0.1

0.0.1.0 https://github.com/stefanzweifel/php-swiss-cantons

Search for Swiss Cantons by name or abbreviation.

  Sources   Download

MIT

The Requires

 

The Development Requires

swiss cantons canton