PHP code example of feft / address-bundle
1. Go to this page and download the library: Download feft/address-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
feft / address-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new \Feft\AddressBundle\FeftAddressBundle(),
);
}
$factory = new AddressFactory();
$addressData = array(
"countryName" => "Poland",
"countryAlpha2Code" => "PL",
"countryLocalShortName" => "Polska",
"localityName" => "Tychy",
"regionName" => "śląskie",
"streetName" => "Freedom",
"postalCode" => "43-100",
"streetNumber" => "20 m. 21",
);
$address = $factory->getAddressObject($addressData);
return array(
'address' => $address,
);
use Feft\AddressBundle\Entity\Address;
use Feft\AddressBundle\Entity\Country;
use Feft\AddressBundle\Entity\Locality;
use Feft\AddressBundle\Entity\PostalCode;
use Feft\AddressBundle\Entity\Region;
use Feft\AddressBundle\Entity\Street;
use Feft\AddressBundle\Model\PostalValidator\Factory;
$country = new Country("Poland","PL");
$country->setLocalShortName("Polska");
$locality = new Locality();
$locality->setName("Tychy");
$region = new Region();
$region->setName("śląskie");
$locality->setRegion($region);
$country->addRegion($locality->getRegion());
$locality->getRegion()->setCountry($country);
$street = new Street();
$street->setName("Wolności");
$code = new PostalCode();
$code->setCode("43-100");
$code->setValidator(Factory::getInstance($code,$country->getCode()));
$address = new Address();
$address->setCountry($country);
$address->setRegion($region);
$address->setLocality($locality);
$address->setStreet($street);
$address->setNumber("20 m. 21");
$address->setPostalCode($code);
$codeValidatingResult = $code->validate();
$options = array("showCountryName" => true);
return array(
'address' => $address,
"options" => $options
);
sh
$ php composer.phar install