-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathBrowseLocationsCommand.php
More file actions
55 lines (44 loc) · 1.66 KB
/
Copy pathBrowseLocationsCommand.php
File metadata and controls
55 lines (44 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php declare(strict_types=1);
namespace App\Command;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'doc:browse_locations',
description: 'Lists all descendants of the Location'
)]
class BrowseLocationsCommand extends Command
{
private LocationService $locationService;
public function __construct(LocationService $locationService)
{
$this->locationService = $locationService;
parent::__construct();
}
protected function configure(): void
{
$this
->setDefinition([
new InputArgument('locationId', InputArgument::REQUIRED, 'Location ID to browse from'),
]);
}
private function browseLocation(Location $location, OutputInterface $output, int $depth = 0): void
{
$output->writeln($location->contentInfo->name);
$children = $this->locationService->loadLocationChildren($location);
foreach ($children->locations as $child) {
$this->browseLocation($child, $output, $depth + 1);
}
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$locationId = (int) $input->getArgument('locationId');
$location = $this->locationService->loadLocation($locationId);
$this->browseLocation($location, $output);
return self::SUCCESS;
}
}