-
-
Notifications
You must be signed in to change notification settings - Fork 52
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 PHP 8.0 support #75
Conversation
The failing tests show an issue within |
Yup, |
@Slamdunk |
In the latest commit 7eb79bf I've dropped support to |
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.
LGTM 👍
You mean |
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.
Overall, good addition here. Thanks so far!
Please keep the BC in mind and re-evaluate the changes in the FormElementManagerFactory
to avoid bc breaks for end users.
src/FormElementManagerFactory.php
Outdated
@@ -11,31 +11,22 @@ | |||
use Interop\Container\ContainerInterface; | |||
use Laminas\ServiceManager\AbstractPluginManager; | |||
use Laminas\ServiceManager\Config; | |||
use Laminas\ServiceManager\FactoryInterface; | |||
use Laminas\ServiceManager\Factory\FactoryInterface; |
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.
Changing the interface is a BC break aswell.
Unless we are bumping major version here, we should avoid such changes.
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.
Thanks for implementing BC!
Just one more thing to reconsider.
* | ||
* Enforces that elements retrieved are instances of ElementInterface. | ||
*/ | ||
class FormElementManagerV2Polyfill extends AbstractPluginManager | ||
class FormElementManager extends AbstractPluginManager |
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.
Oh, didn't see that.
So you've renamed the v2 plugin manager instead of the v3 one.
Please diff with the v3 plugin manager from 2.15.0 to see whats missing in here.
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.
So you've renamed the v2 plugin manager instead of the v3 one.
No, I've renamed the v3 one, don't know why git tells otherwise. It already is BC, no API changes introduced except for protected $shareByDefault = false;
which can't work anyway with v3:
$ git diff 2.16.x:src/FormElementManager/FormElementManagerV3Polyfill.php php_80_support:src/FormElementManager.php
diff --git a/src/FormElementManager/FormElementManagerV3Polyfill.php b/src/FormElementManager.php
index aaa8202d..e9af6a3a 100644
--- a/src/FormElementManager/FormElementManagerV3Polyfill.php
+++ b/src/FormElementManager.php
@@ -6,10 +6,11 @@
* @license https://github.com/laminas/laminas-form/blob/master/LICENSE.md New BSD License
*/
-namespace Laminas\Form\FormElementManager;
+namespace Laminas\Form;
use Interop\Container\ContainerInterface;
use Laminas\Form\Element;
+use Laminas\Form\Exception;
use Laminas\Form\ElementFactory;
use Laminas\Form\ElementInterface;
use Laminas\Form\Fieldset;
@@ -32,10 +33,8 @@ use function sprintf;
*
* Enforces that elements retrieved are instances of ElementInterface.
*/
-class FormElementManagerV3Polyfill extends AbstractPluginManager
+class FormElementManager extends AbstractPluginManager
{
- use FormElementManagerTrait;
-
/**
* Aliases for default set of helpers
*
@@ -277,13 +276,6 @@ class FormElementManagerV3Polyfill extends AbstractPluginManager
*/
protected $sharedByDefault = false;
- /**
- * Don't share form elements by default (v2)
- *
- * @var bool
- */
- protected $shareByDefault = false;
-
/**
* Interface all plugins managed by this class must implement.
* @var string
@@ -399,4 +391,62 @@ class FormElementManagerV3Polyfill extends AbstractPluginManager
return $this;
}
+ /**
+ * Try to pull hydrator from the creation context, or instantiates it from its name
+ *
+ * @param string $hydratorName
+ * @return mixed
+ * @throws Exception\DomainException
+ */
+ public function getHydratorFromName($hydratorName)
+ {
+ $services = $this->creationContext;
+
+ if ($services && $services->has('HydratorManager')) {
+ $hydrators = $services->get('HydratorManager');
+ if ($hydrators->has($hydratorName)) {
+ return $hydrators->get($hydratorName);
+ }
+ }
+
+ if ($services && $services->has($hydratorName)) {
+ return $services->get($hydratorName);
+ }
+
+ if (! class_exists($hydratorName)) {
+ throw new Exception\DomainException(sprintf(
+ 'Expects string hydrator name to be a valid class name; received "%s"',
+ $hydratorName
+ ));
+ }
+
+ $hydrator = new $hydratorName;
+ return $hydrator;
+ }
+
+ /**
+ * Try to pull factory from the creation context, or instantiates it from its name
+ *
+ * @param string $factoryName
+ * @return mixed
+ * @throws Exception\DomainException
+ */
+ public function getFactoryFromName($factoryName)
+ {
+ $services = $this->creationContext;
+
+ if ($services && $services->has($factoryName)) {
+ return $services->get($factoryName);
+ }
+
+ if (! class_exists($factoryName)) {
+ throw new Exception\DomainException(sprintf(
+ 'Expects string factory name to be a valid class name; received "%s"',
+ $factoryName
+ ));
+ }
+
+ $factory = new $factoryName;
+ return $factory;
+ }
}
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.
hm, as I've looked into it yesterday, it looked like there were missing some aliases 🤔
I'll check that again when I find spare time.
Thanks for re-checking.
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.
@boesing may I help further on this?
So, Libraries that rely on The only solution I see to this is to upgrade I'm going to work on this, but I'm not sure I can replace Annotation parsing. |
In order to not reinvent the wheel, I'll try to use https://github.com/doctrine/annotations |
After a day thinking about it, the issues affecting PHP 8 and So we can ship this as-is, declaring partial support for annotations on PHP 8. and then we can focus on the next MAJOR with a replacement for |
How about using php Attributes directly instead? Maybe this is an sufficiend alternative without the need of another dependency? |
Please open a new issue report for that topic. Thanks in advance! 👍 |
I had a look into An annotation
Hence, the constructors of all annotations classes have to be changed which might be considered a BC break, since those classes have not been marked as public function __construct(array $data)
{
[...]
} to the following: public function __construct($data)
{
if (!is_array($data) && !isset($data['value'])) {
$data = ['value' => $data];
}
[...]
} Still, in the unlikely event that someone was extended the annotation classes and overwritten the constructor, things will likely break, as with In consequence, it might be easier to release a new major (i.e. 3.0) with annotations support through |
I wonder if its just possible to use |
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
Ok, I've verified again this PR against doctrine/DoctrineORMModule#661 and all tests pass. I consider this ready-to-merge as users can run this on PHP 8.0 without BC Breaks, but of course we need to deprecate the current Annotation stuff. We can postpone that until we find a proper alternative. |
Close #73