Skip to content
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

To use PHP-DI 6.0 with the Symfony Bridge, with Symfony 3.3, 3.4 et 4+ #19

Merged
merged 8 commits into from
Mar 5, 2018
Merged

To use PHP-DI 6.0 with the Symfony Bridge, with Symfony 3.3, 3.4 et 4+ #19

merged 8 commits into from
Mar 5, 2018

Conversation

frenchcomp
Copy link
Contributor

Hi,
It's some patchs to allow use PHP-DI 6 with the bridge on Symfony 3.3, 3.4 and 4+.
This patch set the minimum required version of PHP to 7.0 (needed by PHP-DI 6).

I limited to Symfony 3.3 and higher because, from this version its container follows the PSR-11.

To allow alias from the PHP-DI container to the Symfony container, the Symfony service must be tagged as public, else it's not available with SF 4.0 and a deprecation notice is thrown with Symfony 3.4.

Have a nice day.
Richard.

Copy link
Member

@mnapoli mnapoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I've added a few comments inline and I've pushed a commit to (hopefully) fix the CI.

src/Kernel.php Outdated
@@ -105,7 +108,7 @@ private function disableDebugClassLoader()
protected function getPHPDIContainer()
{
if ($this->phpdiContainer === null) {
$builder = new \DI\ContainerBuilder();
$builder = new DiContainerBuilder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity I'd rather not alias the class (and the namespace is really short anyway), could you restore that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, no problem

src/Kernel.php Outdated
@@ -37,9 +38,11 @@ public function __construct($environment, $debug)
/**
* Implement this method to configure PHP-DI.
*
* @param DiContainerBuilder $builder
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter is not bringing value, could you revert?

@@ -24,7 +24,7 @@
*
* @author Matthieu Napoli <[email protected]>
*/
class SymfonyContainerBridge extends SymfonyContainer implements SymfonyContainerInterface, ContainerInterface
class SymfonyContainerBridge extends SymfonyContainer implements SymfonyContainerInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removal is because the interface is already implemented in Symfony right?

Is it possible to keep it anyway (for future-proofing)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I remove it because it already implemented in Symfony from the version 3.3.
But, it's allowed by PHP (no issue on an internal project with PHP 7.1), but some tools (PHPStorm...) display a warning.

We can also restore the original interface (Interop\Container\ContainerInterface instead of the PSR11) to avoid a BC break. (SF implements the PSR11).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's good to target PSR-11 only. So if I understand correctly can you add:

implements SymfonyContainerInterface, ContainerInterface

(ContainerInterface would be PSR-11)

$phpdiContainer->set('foo', \DI\get('class2'));
$ref = \DI\get('class2');
$ref->setName('foo');
$phpdiContainer->set('foo', $ref);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you have to do this? Because it looks like a regression in PHP-DI 6 to me 🤔

Copy link
Contributor Author

@frenchcomp frenchcomp Feb 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for me its a regression in PHP-DI 6, the \DI\get returns a reference and not an helper, and so the entry name will never injected into it. So the name is empty. (In PHP-DI 5 its an helper).

But I use PHP-DI only since few months, (it'is a pretty tool). So my experience with this project is limited and I did not have time to see if that was the expected behavior or not for PHP-DI 6.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you I have created an issue to check this in PHP-DI itself. It should not block this PR though.

@frenchcomp
Copy link
Contributor Author

Thanks for your review. I will fix them this week.

@frenchcomp
Copy link
Contributor Author

It's done. Sorry, it was a busy week..

@mnapoli
Copy link
Member

mnapoli commented Mar 5, 2018

Thanks!

@mnapoli mnapoli merged commit d536a47 into PHP-DI:master Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants