mero / correios-bundle
此包已被废弃且不再维护。未建议替代包。
Symfony Bundle 包含 Correios 集成
dev-master / 0.1.x-dev
2017-06-03 19:31 UTC
Requires
- php: >=5.4.9
- mero/correios: ^0.1
- symfony/framework-bundle: ~2.8|~3.0|~4.0
Requires (Dev)
- phpunit/phpunit: ~4.4
- satooshi/php-coveralls: ~1.0
- symfony/symfony: ~2.8
Suggests
- mero/base-bundle: Bundle for Symfony with Correios integration
- mero/br-validator-bundle: Bundle for Symfony with validators for Brazilian location
- mero/telegram-handler: Monolog handler to send log via Telegram
This package is auto-updated.
Last update: 2023-04-17 02:43:17 UTC
README
Symfony Bundle 包含 Correios 集成
要求
- PHP 5.4.9 或更高版本
- SOAP 扩展
- Symfony 2.8 或更高版本
使用 composer 安装
- 打开您的项目目录;
- 运行
composer require mero/correios-bundle
以将 MeroCorreiosBundle 添加到您的项目 vendor 中; - 打开 my/project/dir/app/AppKernel.php;
- 添加
Mero\Bundle\CorreiosBundle\MeroCorreiosBundle()
。
Correios 客户端
此包仅是使用 MeroCorreios 的别名。
服务 | MeroCorreios 类 |
---|---|
mero_correios.client | 客户端 |
使用示例
namespace Acme\Bundle\ApiBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; /** * @Route("/correios") */ class CorreiosController extends Controller { /** * @Route("/{zipCode}/address", name="search_zipcode") */ public function searchAction(string $zipCode) { $client = $this->get('mero_correios.client'); // Return the Mero\Correios\Client try { $address = $client->findAddressByZipCode($zipCode); return new JsonResponse([ 'zip_code' => $zipCode, 'address' => $address->getAddress(), 'neighborhood' => $address->getNeighborhood(), 'city' => $address->getCity(), 'state' => $address->getState(), ]); } catch (AddressNotFoundException $e) { return new JsonResponse([ 'message' => $e->getMessage(), ], 404); } catch (InvalidZipCodeException $e) { return new JsonResponse([ 'message' => $e->getMessage(), ], 404); } } }