Resolve "Make command to test getClosestOpenHubs" #1575

Merged
korina.cordero merged 2 commits from 652-make-command-to-test-getclosestopenhubs into master 2022-03-24 08:20:53 +00:00

View file

@ -0,0 +1,54 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use App\Service\MapTools;
class TestClosestOpenHubsCommand extends Command
{
protected $maptools;
protected function configure()
{
$this->setName('test:closestopenhubs')
->setDescription('Test the get closest open hubs service.')
->setHelp('Test the get closese open hubs service.')
->addArgument('long', InputArgument::REQUIRED, 'Longitude')
->addArgument('lat', InputArgument::REQUIRED, 'Latitude');
}
public function __construct(MapTools $maptools)
{
$this->maptools = $maptools;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$long = $input->getArgument('long');
$lat = $input->getArgument('lat');
$point = new Point($long, $lat);
$hubs_with_distance = $this->maptools->getClosestOpenHubs($point, 10);
foreach($hubs_with_distance as $hub_dist)
{
$hub = $hub_dist['hub'];
$distance = $hub_dist['distance'];
error_log('Hub ID ' . $hub->getID() . ' - ' . $hub->getName() . ' = ' . $distance . ' kms away.');
}
return 0;
}
}