-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from jolicode/feat/debug-mode
feat(debug): add debug command and profiler for symfony
- Loading branch information
Showing
37 changed files
with
614 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Debug a Mapper | ||
|
||
AutoMapper provides 2 ways to debug what's going on with a mapper when using the Symfony bundle: | ||
|
||
## The `debug:mapper` Command | ||
|
||
The `debug:mapper` command will display the mapping information for a specific mapper. | ||
This can be useful to understand how AutoMapper is mapping your objects and why some properties are not mapped. | ||
|
||
```bash | ||
php bin/console debug:mapper User UserDTO | ||
``` | ||
|
||
![Profiler](../images/debug-cli.png) | ||
|
||
## Using the symfony profiler | ||
|
||
AutoMapper provides a panel in the Symfony profiler that will display the mapping information for each request. | ||
Please note that this only display Mapper that has been generated during the request, if you have a mapper that was not | ||
generated during the request it will not be displayed. | ||
|
||
You can find the panel in the Symfony profiler under the `AutoMapper` tab. | ||
|
||
![Profiler](../images/debug-profiler-1.png) | ||
![Profiler](../images/debug-profiler-2.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AutoMapper\Symfony\Bundle\Command; | ||
|
||
use AutoMapper\Metadata\Dependency; | ||
use AutoMapper\Metadata\MetadataFactory; | ||
use AutoMapper\Metadata\PropertyMetadata; | ||
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 Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
final class DebugMapperCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly MetadataFactory $metadataFactory | ||
) { | ||
parent::__construct('debug:mapper'); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Debug Mapper from source to target') | ||
->addArgument('source', InputArgument::REQUIRED, 'Source class or "array"') | ||
->addArgument('target', InputArgument::REQUIRED, 'Target class or "array"') | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
/** @var class-string<object>|'array' $source */ | ||
$source = $input->getArgument('source'); | ||
/** @var class-string<object>|'array' $target */ | ||
$target = $input->getArgument('target'); | ||
|
||
$metadata = $this->metadataFactory->getGeneratorMetadata($source, $target); | ||
|
||
$style = new SymfonyStyle($input, $output); | ||
$style->section('Mapper:'); | ||
|
||
$style->horizontalTable( | ||
['Source', 'Target', 'Classname', 'Check attributes', 'Use constructor', 'Provider'], | ||
[ | ||
[ | ||
$metadata->mapperMetadata->source, | ||
$metadata->mapperMetadata->target, | ||
$metadata->mapperMetadata->className, | ||
$metadata->checkAttributes ? 'Yes' : 'No', | ||
$metadata->hasConstructor() ? 'Yes' : 'No', | ||
$metadata->provider, | ||
], | ||
]); | ||
|
||
$style->section('Dependencies:'); | ||
|
||
$style->table( | ||
['Mapper', 'Source', 'Target'], | ||
array_map( | ||
fn (Dependency $dependency) => [ | ||
$dependency->mapperDependency->name, | ||
$dependency->mapperDependency->source, | ||
$dependency->mapperDependency->target, | ||
], | ||
$metadata->getDependencies() | ||
) | ||
); | ||
|
||
$style->section('Used Properties:'); | ||
|
||
$style->table( | ||
[sprintf('%s -> %s', $source, $target), 'If', 'Transformer', 'Groups', 'MaxDepth'], | ||
array_map( | ||
fn (PropertyMetadata $property) => [ | ||
$property->source->name . ' -> ' . $property->target->name, | ||
$property->if, | ||
\get_class($property->transformer), | ||
$property->disableGroupsCheck ? 'Disabled' : implode(', ', $property->groups ?? []), | ||
$property->maxDepth, | ||
], | ||
array_filter($metadata->propertiesMetadata, fn (PropertyMetadata $property) => !$property->ignored) | ||
) | ||
); | ||
|
||
$style->section('Not Used Properties:'); | ||
|
||
$style->table( | ||
[sprintf('%s -> %s', $source, $target), 'Not used reason'], | ||
array_map( | ||
fn (PropertyMetadata $property) => [ | ||
$property->source->name . ' -> ' . $property->target->name, | ||
$property->ignoreReason, | ||
], | ||
array_filter($metadata->propertiesMetadata, fn (PropertyMetadata $property) => $property->ignored) | ||
) | ||
); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
Oops, something went wrong.