10000 [WIP] adding DisableAutoMapping code to registration form by weaverryan · Pull Request #514 · symfony/maker-bundle · GitHub
[go: up one dir, main page]

Skip to content

[WIP] adding DisableAutoMapping code to registration form #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding DisableAutoValidatoin to make:user when possible
  • Loading branch information
weaverryan committed Dec 6, 2019
commit be45c2989da8ae4afe2a7564c72138a120c5c684
8 changes: 8 additions & 0 deletions src/Security/UserClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node;
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints\DisableAutoMapping;

/**
* Adds logic to implement UserInterface to an existing User class.
Expand Down Expand Up @@ -190,6 +191,13 @@ private function addGetPassword(ClassSourceManipulator $manipulator, UserClassCo
],
[$propertyDocs]
);

if (class_exists(DisableAutoMapping::class)) {
$manipulator->addValidationAnnotation(
'password',
DisableAutoMapping::class
);
}
} else {
// add normal property
$manipulator->addProperty('password', [$propertyDocs]);
Expand Down
12 changes: 12 additions & 0 deletions src/Util/ClassSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,18 @@ public function addAnnotationToProperty(string $propertyName, string $annotation
$this->updateSourceCodeFromNewStmts();
}

/**
* Helper to add a validation annotation that is aware of the preferred "as Assert" alias
*/
public function addValidationAnnotation(string $propertyName, string $annotationClass, array $options)
{
if (strpos($annotationClass, 'Symfony\Component\Validator\Constraints') !== 0) {
throw new \Exception('addValidationAnnotation is meant only for use with constraints in the Symfony\Component\Validator\Constraints namespace. Use addAnnotationToProperty() instead.');
}

$this->addAnnotationToProperty($propertyName, $annotationClass, $options, true, 'Assert');
}

private function addNewLineToComments(string $existingCommentsText, string $newDocLine): Doc
{
$docLines = $existingCommentsText ? explode("\n", $existingCommentsText) : [];
Expand Down
0