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

[DI] Add ability to choose behavior of decorations on non existent decorated services #33854

Open
wants to merge 1 commit into
base: 4.4
from

Conversation

@mtarld
Copy link

commented Oct 4, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets #33522
License MIT
Doc PR symfony/symfony-docs#12442

Handling decorations on non existent decorated services

Handle decorations on non existent decorated services by either throwing the service not found exception, silently ignoring services (decorator & decorated) all together or leave the decorated service to null (current behavior)

Something almost similar to how missing services as parameters are handles.

Yaml configuration

decorator:
    decorates: decorated
    decoration_on_invalid: ignore

Available values: exception, ignore, null. exception if nothing is specified.

Xml configuration

<service id="decorator" decorates="decorated" decoration-on-invalid="ignore" />

Available values: exception, ignore, null. exception if nothing is specified.

Behavior

  • exception: Throws a ServiceNotFoundException telling that the decorator's dependency is missing
  • ignore: Remove decorator definition. Decorator and decorated will not be available at all.
  • null: Keep decorator but set decorated to null. Therefore, decorator __construct should be written with a nullable decorated dependency (public function __contruct(?DecoratedInterface $decorated) {}) and check should be done in other methods
@nicolas-grekas nicolas-grekas added this to the next milestone Oct 4, 2019
@mtarld mtarld force-pushed the mtarld:feature/behavior-on-decorated-invalid branch 2 times, most recently from cb2e43d to b4ec498 Oct 7, 2019
@mtarld mtarld changed the title [WIP] Feature/behavior on decorated invalid Add ability to choose behavior of decorations on non existent decorated services Oct 7, 2019
@mtarld mtarld force-pushed the mtarld:feature/behavior-on-decorated-invalid branch from f9b889d to fc449ec Oct 7, 2019
@mtarld mtarld marked this pull request as ready for review Oct 7, 2019
@mtarld mtarld force-pushed the mtarld:feature/behavior-on-decorated-invalid branch from fc449ec to 9f93002 Oct 7, 2019
@mtarld mtarld force-pushed the mtarld:feature/behavior-on-decorated-invalid branch 6 times, most recently from 61c96c8 to 8bee11a Oct 8, 2019
@nicolas-grekas nicolas-grekas changed the title Add ability to choose behavior of decorations on non existent decorated services [DI] Add ability to choose behavior of decorations on non existent decorated services Oct 13, 2019
@nicolas-grekas nicolas-grekas force-pushed the mtarld:feature/behavior-on-decorated-invalid branch from 8bee11a to 33098d2 Oct 13, 2019
Copy link
Member

left a comment

(FYI, I made some tweaks, esp. in ResolveInvalidReferencesPass)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.