From 2b3b7b1fc8b560e9a4a6b5710da2adaa096acca5 Mon Sep 17 00:00:00 2001 From: Witold Wasiczko Date: Thu, 18 Jun 2020 19:53:14 +0200 Subject: [PATCH 1/4] Update to doctrine v3 --- composer.json | 7 ++++--- .../Authentication/Adapter/ObjectRepository.php | 11 ++++++++--- src/DoctrineModule/Form/Element/Proxy.php | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index e5b7e483..9b367e43 100644 --- a/composer.json +++ b/composer.json @@ -48,9 +48,10 @@ "require": { "php": "^7.2", "doctrine/cache": "^1.7", - "doctrine/common": "^2.8", - "doctrine/doctrine-laminas-hydrator": "^2.0.2", - "doctrine/persistence": "^1.3.7", + "doctrine/common": "^3.0", + "doctrine/doctrine-laminas-hydrator": "^2.0.3", + "doctrine/inflector": "^2.0", + "doctrine/persistence": "^2.0", "laminas/laminas-authentication": "^2.5.3", "laminas/laminas-cache": "^2.7.1", "laminas/laminas-form": "^2.11", diff --git a/src/DoctrineModule/Authentication/Adapter/ObjectRepository.php b/src/DoctrineModule/Authentication/Adapter/ObjectRepository.php index 890e3a1b..b38dcaec 100644 --- a/src/DoctrineModule/Authentication/Adapter/ObjectRepository.php +++ b/src/DoctrineModule/Authentication/Adapter/ObjectRepository.php @@ -4,7 +4,8 @@ namespace DoctrineModule\Authentication\Adapter; -use Doctrine\Common\Inflector\Inflector; +use Doctrine\Inflector\Inflector; +use Doctrine\Inflector\InflectorFactory; use DoctrineModule\Options\Authentication as AuthenticationOptions; use Laminas\Authentication\Adapter\AbstractAdapter; use Laminas\Authentication\Adapter\Exception; @@ -32,14 +33,18 @@ class ObjectRepository extends AbstractAdapter */ protected $authenticationResultInfo = null; + /** @var Inflector */ + protected $inflector; + /** * Constructor * * @param mixed[]|AuthenticationOptions $options */ - public function __construct($options = []) + public function __construct($options = [], Inflector $inflector = null) { $this->setOptions($options); + $this->inflector = $inflector ?? InflectorFactory::create()->build(); } /** @@ -88,7 +93,7 @@ public function authenticate() : AuthenticationResult protected function validateIdentity(object $identity) : AuthenticationResult { $credentialProperty = $this->options->getCredentialProperty(); - $getter = 'get' . Inflector::classify($credentialProperty); + $getter = 'get' . $this->inflector->classify($credentialProperty); $documentCredential = null; if (method_exists($identity, $getter)) { diff --git a/src/DoctrineModule/Form/Element/Proxy.php b/src/DoctrineModule/Form/Element/Proxy.php index 0c3b6436..bba5e3db 100644 --- a/src/DoctrineModule/Form/Element/Proxy.php +++ b/src/DoctrineModule/Form/Element/Proxy.php @@ -5,7 +5,8 @@ namespace DoctrineModule\Form\Element; use Doctrine\Common\Collections\Collection; -use Doctrine\Common\Inflector\Inflector; +use Doctrine\Inflector\Inflector; +use Doctrine\Inflector\InflectorFactory; use Doctrine\Persistence\ObjectManager; use DoctrineModule\Persistence\ObjectManagerAwareInterface; use Laminas\Stdlib\Guard\ArrayOrTraversableGuardTrait; @@ -72,6 +73,14 @@ class Proxy implements ObjectManagerAwareInterface /** @var string|null */ protected $optgroupDefault; + /** @var Inflector */ + protected $inflector; + + public function __construct(Inflector $inflector = null) + { + $this->inflector = $inflector ?? InflectorFactory::create()->build(); + } + /** * @param mixed[] $options */ @@ -486,7 +495,7 @@ protected function loadValueOptions() : void ); } - $getter = 'get' . Inflector::classify($property); + $getter = 'get' . $this->inflector->classify($property); if (! is_callable([$object, $getter])) { throw new RuntimeException( @@ -546,7 +555,7 @@ protected function loadValueOptions() : void } // optgroup_identifier found, handle grouping - $optgroupGetter = 'get' . Inflector::classify($this->getOptgroupIdentifier()); + $optgroupGetter = 'get' . $this->inflector->classify($this->getOptgroupIdentifier()); if (! is_callable([$object, $optgroupGetter])) { throw new RuntimeException( From 5affac320d3fb903be8e8c6f65c279128a14f619 Mon Sep 17 00:00:00 2001 From: Witold Wasiczko Date: Thu, 18 Jun 2020 20:03:07 +0200 Subject: [PATCH 2/4] Drop doctrine/common --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 9b367e43..baf5240d 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,6 @@ "require": { "php": "^7.2", "doctrine/cache": "^1.7", - "doctrine/common": "^3.0", "doctrine/doctrine-laminas-hydrator": "^2.0.3", "doctrine/inflector": "^2.0", "doctrine/persistence": "^2.0", From 8a467a651d443dcbeac02d4c081c6b9f00c578fc Mon Sep 17 00:00:00 2001 From: Witold Wasiczko Date: Thu, 18 Jun 2020 20:04:54 +0200 Subject: [PATCH 3/4] Nullable params --- src/DoctrineModule/Authentication/Adapter/ObjectRepository.php | 2 +- src/DoctrineModule/Form/Element/Proxy.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DoctrineModule/Authentication/Adapter/ObjectRepository.php b/src/DoctrineModule/Authentication/Adapter/ObjectRepository.php index b38dcaec..dbff81cc 100644 --- a/src/DoctrineModule/Authentication/Adapter/ObjectRepository.php +++ b/src/DoctrineModule/Authentication/Adapter/ObjectRepository.php @@ -41,7 +41,7 @@ class ObjectRepository extends AbstractAdapter * * @param mixed[]|AuthenticationOptions $options */ - public function __construct($options = [], Inflector $inflector = null) + public function __construct($options = [], ?Inflector $inflector = null) { $this->setOptions($options); $this->inflector = $inflector ?? InflectorFactory::create()->build(); diff --git a/src/DoctrineModule/Form/Element/Proxy.php b/src/DoctrineModule/Form/Element/Proxy.php index bba5e3db..79e24589 100644 --- a/src/DoctrineModule/Form/Element/Proxy.php +++ b/src/DoctrineModule/Form/Element/Proxy.php @@ -76,7 +76,7 @@ class Proxy implements ObjectManagerAwareInterface /** @var Inflector */ protected $inflector; - public function __construct(Inflector $inflector = null) + public function __construct(?Inflector $inflector = null) { $this->inflector = $inflector ?? InflectorFactory::create()->build(); } From 352278bb771920f93b4ac75df8cecf4d209eca47 Mon Sep 17 00:00:00 2001 From: Witold Wasiczko Date: Thu, 18 Jun 2020 20:09:09 +0200 Subject: [PATCH 4/4] Add event manager --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index baf5240d..98d92d87 100644 --- a/composer.json +++ b/composer.json @@ -49,6 +49,7 @@ "php": "^7.2", "doctrine/cache": "^1.7", "doctrine/doctrine-laminas-hydrator": "^2.0.3", + "doctrine/event-manager": "^1.0.0", "doctrine/inflector": "^2.0", "doctrine/persistence": "^2.0", "laminas/laminas-authentication": "^2.5.3",