Symfony2 プロジェクトでは、この StackOverflow questionで提案されているように、データベース内の文字列を暗号化するためにカスタム マッピング フィールドを作成しました。Gedmo\Sluggable Doctrine 拡張機能を使用して、データベース フィールドの 1 つをスラッグ化したいと考えています。しかし、「encrypted_string」は許可されたタイプではないため、明らかに次のエラーメッセージが表示されます。
[Gedmo\Exception\InvalidMappingException]
フィールドを使用できません - [username] はスラッグ ストレージに使用できません。タイプは無効であり
、クラスの「文字列」または「テキスト」である必要があります - My\PrivateApplication\Bundle\UserBundle
\Entity\User
--編集-- これは私のエンティティです:
<?php
namespace My\PrivateApplication\Bundle\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo,
Gedmo\Translatable\Translatable;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Doctrine\Common\Collections\ArrayCollection;
/**
* My\PrivateApplication\Bundle\UserBundle\Entity\User
*
* @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="UserRepository")
*/
class User implements AdvancedUserInterface, \Serializable {
/**
* @var int
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(type="encrypted_string", length=255)
*/
private $surname;
/**
* @var string
*
* @ORM\Column(type="encrypted_string", length=255)
*/
private $name;
/**
* @var string
*
* @ORM\Column(type="encrypted_string", length=255, unique=true)
*/
private $username;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $password;
/**
* @var string
*
* @ORM\Column(type="encrypted_string", length=255)
*/
private $email;
/**
* @var string
*
* @ORM\Column(type="string", length=255, unique=true)
* @Gedmo\Slug(fields={"username"})
*/
private $slug;
/**
* @var string
*
* @ORM\Column(name="salt", type="string", length=40)
*/
private $salt;
/**
* Whether the account is active or not
*
* @var boolean
*
* @ORM\Column(name="is_active", type="boolean")
*/
private $isActive;
/**
* Whether the account is locked or not
*
* @var boolean
*
* @ORM\Column(name="is_locked", type="boolean")
*/
private $isLocked;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=true)
* @Gedmo\Timestampable(on="create")
*
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @var string
*
* @Gedmo\Locale
*/
private $locale;
/**
* Set the locale for the translatable behavior
*
* @param string $locale
*/
public function setTranslatableLocale($locale) {
$this->locale = $locale;
}
public function eraseCredentials()
{
}
public function getPassword()
{
return $this->password;
}
public function getRoles()
{
return array((string)$this->getRole());
}
public function getSalt()
{
return $this->salt;
}
public function getUsername()
{
return $this->username;
}
public function isAccountNonExpired()
{
return true;
}
public function isAccountNonLocked()
{
return ($this->isLocked()==0)? false : true;
}
public function isCredentialsNonExpired()
{
return true;
}
public function isEnabled()
{
return ($this->isActive==0) ? false : true;
}
/**
* Serialize the User object
* @see Serializable::serialize()
*/
public function serialize()
{
return serialize(array($this->id, $this->username, $this->password, $this->salt));
}
/**
* Unserialize the User object
* @see Serializable::unserialize()
*/
public function unserialize($serialized)
{
list($this->id, $this->username, $this->password, $this->salt) = unserialize($serialized);
}
//other accessor methods
}
クラス Gedmo\Sluggable\Mapping\Driver\Annotation のプロパティ $validTypes は、sluggable の有効な型を定義しているようです。新しいカスタム タイプを使用するように SluggableListener を変更するにはどうすればよいですか?
どうもありがとうございました。