PHP code example of oselya / ip-geolocation-bundle
1. Go to this page and download the library: Download oselya/ip-geolocation-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/ */
oselya / ip-geolocation-bundle example snippets
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;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.