-
-
Notifications
You must be signed in to change notification settings - Fork 188
/
TypeConverterCommandController.php
86 lines (77 loc) · 2.81 KB
/
TypeConverterCommandController.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Neos\Flow\Command;
/*
* This file is part of the Neos.Flow package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Neos\Flow\Property\PropertyMapper;
/**
* Command controller for listing active type converters
*
* @Flow\Scope("singleton")
*/
class TypeConverterCommandController extends CommandController
{
/**
* @Flow\Inject
* @var PropertyMapper
*/
protected $propertyMapper;
/**
* Lists all currently active and registered type converters
*
* All active converters are listed with ordered by priority and grouped by
* source type first and target type second.
*
* @param string $source Filter by source
* @param string $target Filter by target type
* @return void
*/
public function listCommand(string $source = null, string $target = null)
{
$this->outputLine();
if ($source !== null) {
$this->outputLine(sprintf('<info>!!</info> Filter by source : <comment>%s</comment>', $source));
}
if ($target !== null) {
$this->outputLine(sprintf('<info>!!</info> Filter by target type : <comment>%s</comment>', $target));
}
$this->outputLine();
$headers = ['Source', 'Target', 'Priority', 'ClassName'];
$table = [];
foreach ($this->propertyMapper->getTypeConverters() as $sourceType => $targetTypePriorityAndClassName) {
if ($source !== null && preg_match('#' . $source . '#', $sourceType) !== 1) {
continue;
}
foreach ($targetTypePriorityAndClassName as $targetType => $priorityAndClassName) {
if ($target !== null && preg_match('#' . $target . '#', $targetType) !== 1) {
continue;
}
krsort($priorityAndClassName);
foreach ($priorityAndClassName as $priority => $className) {
$table[] = [
$sourceType,
$targetType,
$priority,
$className
];
}
}
}
$sourceSorting = $targetSorting = $prioritySorting = [];
foreach ($table as $key => $row) {
$sourceSorting[$key] = strtolower($row[0]);
$targetSorting[$key] = strtolower($row[1]);
$prioritySorting[$key] = $row[2];
}
array_multisort($sourceSorting, SORT_ASC, $targetSorting, SORT_ASC, $prioritySorting, SORT_NUMERIC, $table);
$this->output->outputTable($table, $headers);
}
}