8000 Inject via PHP 8 attributes by mnapoli · Pull Request #738 · PHP-DI/PHP-DI · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Inject via PHP 8 attributes #738

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

Merged
merged 1 commit into from
Oct 5, 2020
Merged

Inject via PHP 8 attributes #738

merged 1 commit into from
Oct 5, 2020

Conversation

mnapoli
Copy link
Member
@mnapoli mnapoli commented Sep 28, 2020

PHP-DI 7 will support PHP 8 attributes as a replacement for Doctrine annotations.

I think it still makes sense to support Doctrine annotations if we can to ease upgrading, so I haven't removed it. They are however deprecated.

Example:

use DI\Attribute\Inject;

class UserController
{
    #[Inject]
    private FormFactoryInterface $formFactory;

    public function createForm($type, $data, $options)
    {
        // $this->formFactory->...
    }
}

The attribute behaves like the annotation. Note that the class is different (DI\Attribute\Inject instead of DI\Annotation\Inject).

The "best practices" recommendations do not change: using attributes is recommended in places like controllers and other glue code, and discouraged in domain code.

@mnapoli mnapoli added this to the 7.0 milestone Sep 28, 2020
@mnapoli
Copy link
Member Author
mnapoli commented Oct 5, 2020

The build is currently failing because PHPStan doesn't fully support PHP 8 yet, and phpcs doesn't support attributes too.

Good to merge in branch v1.0.

@mnapoli mnapoli merged commit 4aeb4ac into v7 Oct 5, 2020
@mnapoli mnapoli deleted the php8-attributes branch October 5, 2020 13:41
@mnapoli mnapoli mentioned this pull request Oct 5, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0