| @@ -183,7 +183,7 @@ | ||
| 183 | 183 |              $data['destination'.$i] = str_replace(' ', '', $this->destinations[$i]); | 
| 184 | 184 | } | 
| 185 | 185 | |
| 186 | -        $data = array_filter($data, static function ($value) { | |
| 186 | +        $data = array_filter($data, static function($value) { | |
| 187 | 187 | return null !== $value; | 
| 188 | 188 | }); | 
| 189 | 189 | |
| @@ -171,7 +171,7 @@ | ||
| 171 | 171 |              $data['waypoint'.$i] = str_replace(' ', '', $this->waypoints[$i]); | 
| 172 | 172 | } | 
| 173 | 173 | |
| 174 | -        $data = array_filter($data, static function ($value) { | |
| 174 | +        $data = array_filter($data, static function($value) { | |
| 175 | 175 | return null !== $value; | 
| 176 | 176 | }); | 
| 177 | 177 | |
| @@ -257,7 +257,7 @@ | ||
| 257 | 257 | $data['departure_time'] = $this->getDepartureTime()->getTimestamp(); | 
| 258 | 258 | } | 
| 259 | 259 | |
| 260 | -        $data = array_filter($data, function ($value) { | |
| 260 | +        $data = array_filter($data, function($value) { | |
| 261 | 261 | return null !== $value; | 
| 262 | 262 | }); | 
| 263 | 263 | |
| @@ -54,136 +54,3 @@ | ||
| 54 | 54 |              ->addOption('language', null, InputOption::VALUE_REQUIRED, 'Language (fr-FR, en-US, etc.)') | 
| 55 | 55 | ->setHelp( | 
| 56 | 56 | <<<'HELP' | 
| 57 | - The <info>navigation:routing</info> command will compute a route from the given addresses. | |
| 58 | - | |
| 59 | - You can choose a provider with the "provider" option. | |
| 60 | - | |
| 61 | - <info>php bin/console navigation:routing --waypoint="45.834278,1.260816" --waypoint="44.830109,-0.603649" --provider=here</info> | |
| 62 | - HELP | |
| 63 | - ) | |
| 64 | - ; | |
| 65 | - } | |
| 66 | - | |
| 67 | - /** | |
| 68 | -     * {@inheritdoc} | |
| 69 | - */ | |
| 70 | - protected function execute(InputInterface $input, OutputInterface $output) | |
| 71 | -    { | |
| 72 | -        if (\count($input->getOption('waypoint')) < 2) { | |
| 73 | -            throw new InvalidArgumentException('A route needs at least two waypoints (start and end locations).'); | |
| 74 | - } | |
| 75 | - | |
| 76 | -        if ($input->getOption('provider')) { | |
| 77 | -            $this->manager->using($input->getOption('provider')); | |
| 78 | - } | |
| 79 | - | |
| 80 | - $query = $this->manager->createRoutingQuery(); | |
| 81 | - | |
| 82 | -        foreach ($input->getOption('waypoint') as $waypoint) { | |
| 83 | - $query->addWaypoint($waypoint); | |
| 84 | - } | |
| 85 | - | |
| 86 | -        if ($input->getOption('departure')) { | |
| 87 | -            $query->setDepartureTime(new \DateTime($input->getOption('departure'))); | |
| 88 | - } | |
| 89 | - | |
| 90 | -        if ($input->getOption('arrival')) { | |
| 91 | -            $query->setArrivalTime(new \DateTime($input->getOption('arrival'))); | |
| 92 | - } | |
| 93 | - | |
| 94 | -        if ($input->getOption('traffic')) { | |
| 95 | -            $query->setTrafficMode($input->getOption('traffic')); | |
| 96 | - } | |
| 97 | - | |
| 98 | -        if ($input->getOption('language')) { | |
| 99 | -            $query->setLanguage($input->getOption('language')); | |
| 100 | - } | |
| 101 | - | |
| 102 | - $response = $query->execute(); | |
| 103 | - | |
| 104 | - $io = new SymfonyStyle($input, $output); | |
| 105 | - | |
| 106 | - $routes = $response->getRoutes(); | |
| 107 | - | |
| 108 | -        $io->section('Summary'); | |
| 109 | - | |
| 110 | - $data = []; | |
| 111 | -        foreach ($routes as $index => $route) { | |
| 112 | - /** | |
| 113 | - * @var Summary | |
| 114 | - */ | |
| 115 | - $summary = $route->getSummary(); | |
| 116 | - $data[] = [ | |
| 117 | - $index + 1, | |
| 118 | - $summary->getDistance()->getFormattedValue(2), | |
| 119 | - $summary->getTravelTime()->getFormattedValue(2), | |
| 120 | - ]; | |
| 121 | - } | |
| 122 | - | |
| 123 | - $table = new Table($output); | |
| 124 | - $table | |
| 125 | - ->setHeaders(['route', 'distance', 'duration']) | |
| 126 | - ->setRows($data) | |
| 127 | - ; | |
| 128 | - $table->render(); | |
| 129 | - | |
| 130 | - $io->newLine(); | |
| 131 | - | |
| 132 | -        foreach ($routes as $routeIndex => $route) { | |
| 133 | -            $io->section('Route #'.($routeIndex + 1)); | |
| 134 | - | |
| 135 | - $legs = $route->getLegs(); | |
| 136 | -            foreach ($legs as $legIndex => $leg) { | |
| 137 | - $steps = $leg->getSteps(); | |
| 138 | -                $io->writeln(sprintf('<comment>Leg #%d</comment> - %d steps.', $legIndex + 1, \count($steps))); | |
| 139 | - | |
| 140 | - $data = []; | |
| 141 | -                foreach ($steps as $stepIndex => $step) { | |
| 142 | - $data[] = [ | |
| 143 | - $stepIndex + 1, | |
| 144 | -                        implode(', ', $step->getPosition()), | |
| 145 | - $step->getDistance()->getFormattedValue(2), | |
| 146 | - $step->getDuration()->getFormattedValue(2), | |
| 147 | - $step->getInstruction(), | |
| 148 | - ]; | |
| 149 | - } | |
| 150 | - | |
| 151 | - $table = new Table($output); | |
| 152 | - $table | |
| 153 | - ->setHeaders(['step', 'position', 'distance', 'duration', 'instruction']) | |
| 154 | - ->setRows($data) | |
| 155 | - ->setColumnMaxWidth(4, 100) | |
| 156 | - ; | |
| 157 | - $table->render(); | |
| 158 | - $io->newLine(); | |
| 159 | - } | |
| 160 | - } | |
| 161 | - } | |
| 162 | - | |
| 163 | - /** | |
| 164 | - * @throws \LogicException | |
| 165 | - * | |
| 166 | - * @return ContainerInterface | |
| 167 | - */ | |
| 168 | - protected function getContainer(): ContainerInterface | |
| 169 | -    { | |
| 170 | -        if (null === $this->container) { | |
| 171 | - $application = $this->getApplication(); | |
| 172 | -            if (null === $application) { | |
| 173 | -                throw new \LogicException('The container cannot be retrieved as the application instance is not yet set.'); | |
| 174 | - } | |
| 175 | - | |
| 176 | - $this->container = $application->getKernel()->getContainer(); | |
| 177 | - } | |
| 178 | - | |
| 179 | - return $this->container; | |
| 180 | - } | |
| 181 | - | |
| 182 | - /** | |
| 183 | -     * {@inheritdoc} | |
| 184 | - */ | |
| 185 | - public function setContainer(ContainerInterface $container = null): void | |
| 186 | -    { | |
| 187 | - $this->container = $container; | |
| 188 | - } | |
| 189 | -} | |
| @@ -50,92 +50,3 @@ | ||
| 50 | 50 |              ->addOption('to', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Destination') | 
| 51 | 51 | ->setHelp( | 
| 52 | 52 | <<<'HELP' | 
| 53 | - The <info>navigation:distance-matrix</info> command will compute a distance matrix from the given addresses. | |
| 54 | - | |
| 55 | - You can choose a provider with the "provider" option. | |
| 56 | - | |
| 57 | - <info>php bin/console navigation:distance-matrix --from="45.834278,1.260816" --to="44.830109,-0.603649" --provider=here</info> | |
| 58 | - HELP | |
| 59 | - ) | |
| 60 | - ; | |
| 61 | - } | |
| 62 | - | |
| 63 | - /** | |
| 64 | -     * {@inheritdoc} | |
| 65 | - */ | |
| 66 | - protected function execute(InputInterface $input, OutputInterface $output) | |
| 67 | -    { | |
| 68 | -        if (empty($input->getOption('from'))) { | |
| 69 | -            throw new InvalidArgumentException('Mission required "from" option.'); | |
| 70 | - } | |
| 71 | - | |
| 72 | -        if (empty($input->getOption('to'))) { | |
| 73 | -            throw new InvalidArgumentException('Mission required "to" option.'); | |
| 74 | - } | |
| 75 | - | |
| 76 | -        if ($input->getOption('provider')) { | |
| 77 | -            $this->manager->using($input->getOption('provider')); | |
| 78 | - } | |
| 79 | - | |
| 80 | - $query = $this->manager->createDistanceMatrixQuery(); | |
| 81 | - | |
| 82 | -        foreach ($input->getOption('from') as $from) { | |
| 83 | - $query->addOrigin($from); | |
| 84 | - } | |
| 85 | -        foreach ($input->getOption('to') as $to) { | |
| 86 | - $query->addDestination($to); | |
| 87 | - } | |
| 88 | - $response = $query->execute(); | |
| 89 | - | |
| 90 | - $origins = $query->getOrigins(); | |
| 91 | - $destinations = $query->getDestinations(); | |
| 92 | - | |
| 93 | - $headers = array_merge([''], $destinations); | |
| 94 | - $data = []; | |
| 95 | -        foreach ($response->getRows() as $index => $row) { | |
| 96 | - $r = [$origins[$index]]; | |
| 97 | -            foreach ($row->getElements() as $element) { | |
| 98 | -                if (Element::STATUS_OK === $element->getStatus()) { | |
| 99 | - $r[] = $element->getDistance().', '.$element->getDuration(); | |
| 100 | -                } else { | |
| 101 | - $r[] = 'unavailable'; | |
| 102 | - } | |
| 103 | - } | |
| 104 | - $data[] = $r; | |
| 105 | - } | |
| 106 | - | |
| 107 | - $table = new Table($output); | |
| 108 | - $table | |
| 109 | - ->setHeaders($headers) | |
| 110 | - ->setRows($data) | |
| 111 | - ; | |
| 112 | - $table->render(); | |
| 113 | - } | |
| 114 | - | |
| 115 | - /** | |
| 116 | - * @throws \LogicException | |
| 117 | - * | |
| 118 | - * @return ContainerInterface | |
| 119 | - */ | |
| 120 | - protected function getContainer(): ContainerInterface | |
| 121 | -    { | |
| 122 | -        if (null === $this->container) { | |
| 123 | - $application = $this->getApplication(); | |
| 124 | -            if (null === $application) { | |
| 125 | -                throw new \LogicException('The container cannot be retrieved as the application instance is not yet set.'); | |
| 126 | - } | |
| 127 | - | |
| 128 | - $this->container = $application->getKernel()->getContainer(); | |
| 129 | - } | |
| 130 | - | |
| 131 | - return $this->container; | |
| 132 | - } | |
| 133 | - | |
| 134 | - /** | |
| 135 | -     * {@inheritdoc} | |
| 136 | - */ | |
| 137 | - public function setContainer(ContainerInterface $container = null): void | |
| 138 | -    { | |
| 139 | - $this->container = $container; | |
| 140 | - } | |
| 141 | -} | |