-
Notifications
You must be signed in to change notification settings - Fork 231
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
add attribute driver support #692
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,65 +11,122 @@ The User Model | |
|
||
We begin this tutorial with the model for a ``User`` document: | ||
|
||
.. code-block:: php | ||
.. configuration-block:: | ||
|
||
// src/Document/User.php | ||
namespace App\Document; | ||
.. code-block:: php-annotations | ||
|
||
use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique as MongoDBUnique; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
// src/Document/User.php | ||
namespace App\Document; | ||
|
||
/** | ||
* @MongoDB\Document(collection="users") | ||
* @MongoDBUnique(fields="email") | ||
*/ | ||
class User | ||
{ | ||
/** | ||
* @MongoDB\Id | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @MongoDB\Field(type="string") | ||
* @Assert\NotBlank() | ||
* @Assert\Email() | ||
*/ | ||
protected $email; | ||
use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique as MongoDBUnique; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
/** | ||
* @MongoDB\Field(type="string") | ||
* @Assert\NotBlank() | ||
* @MongoDB\Document(collection="users") | ||
* @MongoDB\Unique(fields="email") | ||
*/ | ||
protected $password; | ||
|
||
public function getId() | ||
class User | ||
{ | ||
return $this->id; | ||
/** | ||
* @MongoDB\Id | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @MongoDB\Field(type="string") | ||
* @Assert\NotBlank() | ||
* @Assert\Email() | ||
*/ | ||
protected $email; | ||
|
||
/** | ||
* @MongoDB\Field(type="string") | ||
* @Assert\NotBlank() | ||
*/ | ||
protected $password; | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getEmail() | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public function setEmail($email) | ||
{ | ||
$this->email = $email; | ||
} | ||
|
||
public function getPassword() | ||
{ | ||
return $this->password; | ||
} | ||
|
||
// stupid simple encryption (please don't copy it!) | ||
public function setPassword($password) | ||
{ | ||
$this->password = sha1($password); | ||
} | ||
} | ||
|
||
public function getEmail() | ||
{ | ||
return $this->email; | ||
} | ||
.. code-block:: php-attributes | ||
|
||
public function setEmail($email) | ||
{ | ||
$this->email = $email; | ||
} | ||
// src/Document/User.php | ||
namespace App\Document; | ||
|
||
public function getPassword() | ||
{ | ||
return $this->password; | ||
} | ||
use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique as MongoDBUnique; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
// stupid simple encryption (please don't copy it!) | ||
public function setPassword($password) | ||
#[MongoDB\Document(collection: 'users')] | ||
#[MongoDB\Unique(fields: 'email')] | ||
class User | ||
{ | ||
$this->password = sha1($password); | ||
/** | ||
* @MongoDB\Id | ||
*/ | ||
#[MongoDB\Id] | ||
protected string $id; | ||
|
||
#[MongoDB\Field(type: 'string')] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe in our examples we could suggest to use constants like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be changed in annotation examples then too but I think this is a candidate for a separate PR. |
||
#[Assert\NotBlank] | ||
#[Assert\Email] | ||
protected ?string $email = null; | ||
|
||
#[MongoDB\Field(type: 'string')] | ||
#[Assert\NotBlank] | ||
protected ?string $password = null; | ||
|
||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getEmail(): ?string | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public function setEmail(?string $email): void | ||
{ | ||
$this->email = $email; | ||
} | ||
|
||
public function getPassword(): ?string | ||
{ | ||
return $this->password; | ||
} | ||
|
||
// stupid simple encryption (please don't copy it!) | ||
public function setPassword(?string $password): void | ||
{ | ||
$this->password = sha1($password); | ||
} | ||
} | ||
} | ||
|
||
This ``User`` document contains three fields and two of them (email and | ||
password) should be displayed in the form. The email property must be unique | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better if we keep
annotation
example and add a new one forattribute