feft/address-bundle
最新稳定版本:1.0
Composer 安装命令:
composer require feft/address-bundle
包简介
This is a Symfony2 bundle that lets using international mailing address.
README 文档
README
Address
International mailing address created in Symfony2. Format examples on http://www.bitboost.com/ref/international-address-formats.html#Formats
The code is compatible with php 7.1 and 5.6 versions.
Installation
Install the library using composer. Add the new line to your composer.json file:
{
"require": {
"feft/address-bundle": "dev-master"
},
}
Now run the install command.
$ php composer.phar install
or use Makefile (only if you are using Docker):
make composer
PhpUnit
To run unittests use command (only if you are using Docker):
make php5.6-phpunit5
Enable the bundle
Enable the bundle in the kernel:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new \Feft\AddressBundle\FeftAddressBundle(), ); }
Update doctrine schema
$ php app/console doctrine:schema:update --force
CRUD operations
Every entity has CRUD Controller to show/add/edit/delete operation, eg. to manage countries use link like this: http://localhost/address/web/app.php/country/
Usage
Simple use:
$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, );
For more examples see unit tests folder.
Controller file:
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 );
Twig file:
<p> {{ address_formatter(address,options)|raw }} </p> <p>or inline format: {{ address_inline_formatter(address,options) }} </p>
Html result:
Wolności 20 m. 21
43-100 Tychy
Poland
or inline format: Wolności 20 m. 21, 43-100 Tychy, Poland
Authors
The bundle was created by Piotr Pikuła. See the list of contributors.
统计信息
- 总下载量: 41
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-29