Reputation: 11
I am trying to encrypt data for a medical application that's how i found DoctrineEncryptBundle (https://packagist.org/packages/michaeldegroot/doctrine-encrypt-bundle)
I am still a rookie with symfony 4 and the documentation give the method for what seems to be previous Symfony version.
I already downloaded the bundle (composer require michaeldegroot/doctrine-encrypt-bundle)
For step 2 : "Enable the database encryption bundle"What is explain in document vs what I did in SF4 Which seems correct.
Then, there is no config.yml in SF4 and I don't know where to define the configuration (encryptor class and the path to the key file).
This yaml =>
ambta_doctrine_encrypt:
encryptor_class: Halite # or Defuse
secret_directory_path: '%kernel.project_dir%' # Path where to store the keyfiles
The documentation : https://github.com/michaeldegroot/DoctrineEncryptBundle/blob/master/Resources/doc/configuration.md
My files Entity Patient (which i want to encrypt)
`
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Ambta\DoctrineEncryptBundle\Configuration\Encrypted;
/**
* @ORM\Entity
* @ORM\Entity(repositoryClass="App\Repository\PatientRepository")
* @ORM\Table(name="patient")
*/
class Patient {
/**
* @var string
* @Encrypted
* @ORM\Column(type="string")
*/
private $nom;`
The controller :
public function ajouterPatient(Request $request)
{
$patient = new Patient();
$form = $this->createForm(PatientType::class, $patient);
if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$patient->setNomsAffichage($patient->getNom()." ".$patient->getPrenom());
$patient->setActif(true);
$em->persist($patient);
$em->flush();
return $this->redirectToRoute('menu_patients');
}
return $this->render('Patients/ajouterPatient.html.twig', array(
'form' => $form->createView(),
));
}
I guess i should define something in service.yml like a link with the bundle but i don't know how.
Any help would be greatly appreciated.
Upvotes: 1
Views: 1932
Reputation: 147
I know this is an old question but for the people who still want to know where to define the configuration yaml file in Symfony 4 for this bundle, here is the answer I got it working with.
In the file config/bundles.php
Add at the end this line to define the Ambta Symfony bundle:
return [
...
Ambta\DoctrineEncryptBundle\AmbtaDoctrineEncryptBundle::class => ['all' => true]
];
Create a new yaml file in: config/packages/orm_services.yaml
Here you can put the configuration. For example:
ambta_doctrine_encrypt:
encryptor_class: Halite
secret_directory_path: '%kernel.project_dir%'
Upvotes: 5