承接 oselya/ip-geolocation-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

oselya/ip-geolocation-bundle

最新稳定版本:0.0.5

Composer 安装命令:

composer require oselya/ip-geolocation-bundle

包简介

Symfony IP geolocation bundle

README 文档

README

License workflow

Install

composer req oselya/ip-geolocation-bundle

Before we get started, there is a small amount of configuration needed

# app/config/ip_geolocation.yaml

ip_geolocation:
  cache_ttl: -1
  maxmind:
    city_path: 'GeoLite2-City.mmdb'
  ip_api_com:
    access_key: 'qwerty'

Cli command

$ bin/console app:ip:location 92.253.204.162
+----------------+-----------+---------+-----------------+-----------------+
| IP             | Continent | Country | Latitude        | Longitude       |
+----------------+-----------+---------+-----------------+-----------------+
| 92.253.204.162 | EU        | UA      | 48.342449188232 | 24.575370788574 |
+----------------+-----------+---------+-----------------+-----------------+

Service

<?php

declare(strict_types=1);

namespace Oselya\IpGeolocationBundle\Command;

use Oselya\IpGeolocationBundle\GeoIpProvider\GeoIpProviderInterface;
use Oselya\IpGeolocationBundle\ValueObject\Ip;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class IpGeolocationCommand extends Command
{
    public function __construct(private readonly GeoIpProviderInterface $provider)
    {
        parent::__construct();
    }

    protected function configure(): void
    {
        $this
            ->setName('app:ip:location')
            ->addArgument('ip', InputArgument::REQUIRED, 'The IP address.')
            ->setDescription('This command allows you to lookup location of IP addresses.');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $location = $this->provider->ipLookup(new Ip($input->getArgument('ip')));

        $table = new Table($output);
        $table
            ->setHeaders(['IP', 'Continent', 'Country', 'Latitude', 'Longitude'])
            ->setRows([
                [
                    $input->getArgument('ip'),
                    $location->getContinent(),
                    $location->getCountry(),
                    $location->getLatitude(),
                    $location->getLongitude(),
                ],
            ]);
        $table->render();

        return Command::SUCCESS;
    }
}

统计信息

  • 总下载量: 2.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-25