Skip to content

Commit

Permalink
Merge pull request #12 from odandb/add-attributes-compatibility
Browse files Browse the repository at this point in the history
Add attributes compatibility
  • Loading branch information
magi-web authored Mar 14, 2023
2 parents 55a35de + 024872c commit a70c467
Show file tree
Hide file tree
Showing 19 changed files with 378 additions and 89 deletions.
27 changes: 14 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@
"doctrine/annotations": "^2.0",
"doctrine/orm": "^2.7",
"paragonie/ciphersweet": "^3.0 || ^4.0",
"symfony/config": "^4.4 || ^5.1 || ^6.0",
"symfony/console": "^4.4 || ^5.1 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.1 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.1 || ^6.0",
"symfony/process": "^4.4 || ^5.1 || ^6.0",
"symfony/property-access": "^4.4 || ^5.1 || ^6.0",
"symfony/property-info": "^4.4 || ^5.1 || ^6.0",
"symfony/yaml": "^4.4 || ^5.1 || ^6.0"
"symfony/config": "^5.4 || ^6.0",
"symfony/console": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/deprecation-contracts": "^2.5 || ^3.2",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/process": "^5.4 || ^6.0",
"symfony/property-access": "^5.4 || ^6.0",
"symfony/property-info": "^5.4 || ^6.0",
"symfony/yaml": "^5.4 || ^6.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.7",
"phpunit/phpunit": "^9.5",
"roave/security-advisories": "dev-latest",
"symfony/doctrine-bridge": "^5.1 || ^6.0",
"symfony/dotenv": "^5.1 || ^6.0",
"symfony/framework-bundle": "^5.1 || ^6.0",
"symfony/phpunit-bridge": "^5.1 || ^6.0",
"symfony/test-pack": "^1.0"
"symfony/doctrine-bridge": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/framework-bundle": "^5.4 || ^6.0",
"symfony/phpunit-bridge": "^6.0"
},
"suggest": {
"phpdocumentor/reflection-docblock": "To use the PHPDoc"
Expand Down
9 changes: 7 additions & 2 deletions src/Command/EncryptionKeyStringProviderGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@
namespace Odandb\DoctrineCiphersweetEncryptionBundle\Command;

use ParagonIE\ConstantTime\Hex;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(name: 'odb:enc:generate-string-key', description: 'Generate default encryption key for StringProvider (one of the different key provider managed by Ciphersweet library).')]
class EncryptionKeyStringProviderGenerator extends Command
{
/** @deprecated */
protected static $defaultName = 'odb:enc:generate-string-key';
protected static $defaultAlias = 'o:e:g';
/** @deprecated */
protected static $defaultDescription = 'Generate default encryption key for StringProvider (one of the different key provider managed by Ciphersweet library).';

protected static string $defaultAlias = 'o:e:g';

protected function configure(): void
{
$this
->setDescription('Generate default encryption key for StringProvider (one of the different key provider managed by Ciphersweet library).')
->setAliases([self::$defaultAlias])
;
}
Expand Down
9 changes: 7 additions & 2 deletions src/Command/FieldIndexPlannerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@


use ParagonIE\CipherSweet\Planner\FieldIndexPlanner;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(name: 'odb:enc:planner', description: 'Determine the Blind Index plan for a given field.')]
class FieldIndexPlannerCommand extends Command
{
/** @deprecated */
protected static $defaultName = 'odb:enc:planner';
protected static $defaultAlias = 'o:e:pl';
/** @deprecated */
protected static $defaultDescription = 'Determine the Blind Index plan for a given field.';

protected static string $defaultAlias = 'o:e:pl';

protected function configure(): void
{
$this
->setDescription('Determine the Blind Index plan for a given field.')
->setAliases([self::$defaultAlias])
;
}
Expand Down
9 changes: 7 additions & 2 deletions src/Command/GenerateIndexesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Odandb\DoctrineCiphersweetEncryptionBundle\Command;

use Odandb\DoctrineCiphersweetEncryptionBundle\Services\IndexableFieldsService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -15,10 +16,15 @@
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

#[AsCommand(name: 'odb:enc:indexes', description: 'Determine the Blind Index plan for a given field.')]
class GenerateIndexesCommand extends Command
{
/** @deprecated */
protected static $defaultName = 'odb:enc:indexes';
protected static $defaultAlias = 'o:e:i';
/** @deprecated */
protected static $defaultDescription = 'Determine the Blind Index plan for a given field.';

protected static string $defaultAlias = 'o:e:i';

protected const CONSOLE_ENTRYPOINT = 'bin/console';
protected const NB_RUNNING_PROCESSES = 5;
Expand All @@ -39,7 +45,6 @@ public function __construct(IndexableFieldsService $indexableFieldsService, stri
protected function configure(): void
{
$this
->setDescription('Determine the Blind Index plan for a given field.')
->setAliases([self::$defaultAlias])
->addArgument('class', InputArgument::REQUIRED, 'The entity class having fields that need a complete indexes recalculation.')

Expand Down
25 changes: 21 additions & 4 deletions src/Configuration/EncryptedField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,35 @@

namespace Odandb\DoctrineCiphersweetEncryptionBundle\Configuration;

use Attribute;
use Odandb\DoctrineCiphersweetEncryptionBundle\Encryptors\EncryptorInterface;

/**
* The Encrypted class handles the @EncryptedField annotation.
*
* @Annotation
* @NamedArgumentConstructor
* @Target({"PROPERTY","ANNOTATION"})
*/
#[Attribute(Attribute::TARGET_PROPERTY)]
class EncryptedField
{
/** @var int */
public int $filterBits = 32;
/** @readonly */
public int $filterBits = EncryptorInterface::DEFAULT_FILTER_BITS;

public string $mappedTypedProperty;
/** @readonly */
public ?string $mappedTypedProperty = null;

/** @var bool */
/** @readonly */
public bool $indexable = true;

public function __construct(
int $filterBits = EncryptorInterface::DEFAULT_FILTER_BITS,
?string $mappedTypedProperty = null,
bool $indexable = true
) {
$this->filterBits = $filterBits;
$this->mappedTypedProperty = $mappedTypedProperty;
$this->indexable = $indexable;
}
}
33 changes: 30 additions & 3 deletions src/Configuration/IndexableField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,45 @@

namespace Odandb\DoctrineCiphersweetEncryptionBundle\Configuration;

use Attribute;
use Odandb\DoctrineCiphersweetEncryptionBundle\Encryptors\EncryptorInterface;

/**
* The Encrypted class handles the @IndexableField annotation.
*
* @Annotation
* @NamedArgumentConstructor
* @Target({"PROPERTY","ANNOTATION"})
*/
#[Attribute(Attribute::TARGET_PROPERTY)]
class IndexableField
{
public bool $autoRefresh = true;
/** @readonly */
public string $indexesEntityClass;
public array $indexesGenerationMethods;
public string $valuePreprocessMethod;

/** @readonly */
public bool $autoRefresh = true;

/** @readonly */
public array $indexesGenerationMethods = [];

/** @readonly */
public ?string $valuePreprocessMethod = null;

/** @readonly */
public bool $fastIndexing = EncryptorInterface::DEFAULT_FAST_INDEXING;

public function __construct(
string $indexesEntityClass,
bool $autoRefresh = true,
array $indexesGenerationMethods = [],
?string $valuePreprocessMethod = null,
bool $fastIndexing = EncryptorInterface::DEFAULT_FAST_INDEXING
) {
$this->indexesEntityClass = $indexesEntityClass;
$this->autoRefresh = $autoRefresh;
$this->indexesGenerationMethods = $indexesGenerationMethods;
$this->valuePreprocessMethod = $valuePreprocessMethod;
$this->fastIndexing = $fastIndexing;
}
}
66 changes: 66 additions & 0 deletions src/Entity/IndexedEntityAttributeTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);


namespace Odandb\DoctrineCiphersweetEncryptionBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

trait IndexedEntityAttributeTrait
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
protected int $id;

#[ORM\Column(type: 'string', length: 255)]
protected string $fieldname;

/**
* onDeleteCascade -> If we delete $targetEntity, we need to delete cascade to the list EntityFilters
*/
#[ORM\JoinColumn(name: 'target_entity_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected object $targetEntity;

#[ORM\Column(type: 'string', length: 10)]
protected string $indexBi;

public function getId(): ?int
{
return $this->id;
}

public function getFieldname(): string
{
return $this->fieldname;
}

public function setFieldname(string $fieldname): self
{
$this->fieldname = $fieldname;
return $this;
}

public function getTargetEntity(): object
{
return $this->targetEntity;
}

public function setTargetEntity(?object $targetEntity): self
{
$this->targetEntity = $targetEntity;
return $this;
}

public function getIndexBi(): string
{
return $this->indexBi;
}

public function setIndexBi(string $indexBi): self
{
$this->indexBi = $indexBi;
return $this;
}
}
27 changes: 1 addition & 26 deletions src/Entity/IndexedEntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ trait IndexedEntityTrait
protected string $fieldname;

/**
* @var object
* onDeleteCascade -> If we delete $targetEntity, we need to delete cascade to the list EntityFilters
*
* @ORM\JoinColumn(name="target_entity_id", referencedColumnName="id", onDelete="CASCADE")
* onDeleteCascade -> si on supprime $targetEntity, on cascade la suppression jusqu'à la liste de EntityFilters
*/
protected object $targetEntity;

Expand All @@ -34,62 +33,38 @@ trait IndexedEntityTrait
*/
protected string $indexBi;

/**
* @return int
*/
public function getId(): ?int
{
return $this->id;
}

/**
* @return string
*/
public function getFieldname(): string
{
return $this->fieldname;
}

/**
* @param string $fieldname
* @return IndexedEntityTrait
*/
public function setFieldname(string $fieldname): self
{
$this->fieldname = $fieldname;
return $this;
}

/**
* @return object
*/
public function getTargetEntity(): object
{
return $this->targetEntity;
}

/**
* @param object|null $targetEntity
* @return $this
*/
public function setTargetEntity(?object $targetEntity): self
{
$this->targetEntity = $targetEntity;
return $this;
}

/**
* @return string
*/
public function getIndexBi(): string
{
return $this->indexBi;
}

/**
* @param string $indexBi
* @return self
*/
public function setIndexBi(string $indexBi): self
{
$this->indexBi = $indexBi;
Expand Down
Loading

0 comments on commit a70c467

Please sign in to comment.