Skip to content

Documented "Handling decorations on non existent service" #12442

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

Conversation

mtarld
Copy link
Contributor

@mtarld mtarld commented Oct 7, 2019

Documentation part for the PR:
symfony/symfony#33854

@OskarStark OskarStark added this to the 4.4 milestone Oct 11, 2019
@OskarStark OskarStark added the Waiting Code Merge Docs for features pending to be merged label Oct 11, 2019
fabpot added a commit to symfony/symfony that referenced this pull request Nov 3, 2019
…non existent decorated services (mtarld)

This PR was merged into the 4.4 branch.

Discussion
----------

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

| 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
```yaml
decorator:
    decorates: decorated
    decoration_on_invalid: ignore
```
Available values: `exception`, `ignore`, `null`. `exception` if nothing is specified.

## Xml configuration
```xml
<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

Commits
-------

f167c77 Handle non existent decorated services
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull request Nov 3, 2019
…non existent decorated services (mtarld)

This PR was merged into the 4.4 branch.

Discussion
----------

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

| 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
```yaml
decorator:
    decorates: decorated
    decoration_on_invalid: ignore
```
Available values: `exception`, `ignore`, `null`. `exception` if nothing is specified.

## Xml configuration
```xml
<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

Commits
-------

f167c77eaf Handle non existent decorated services
@javiereguiluz javiereguiluz added DependencyInjection and removed Waiting Code Merge Docs for features pending to be merged labels Dec 17, 2019
Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mtarld mtarld force-pushed the feature/behavior-on-decorated-invalid branch from 46883da to 5e9a253 Compare February 13, 2020 18:22
@mtarld mtarld force-pushed the feature/behavior-on-decorated-invalid branch from 5e9a253 to c0fa50e Compare February 14, 2020 07:58
@mtarld mtarld force-pushed the feature/behavior-on-decorated-invalid branch from c0fa50e to cb07e30 Compare February 14, 2020 11:10
@OskarStark
Copy link
Contributor

Thanks for your work on this new feature!

OskarStark added a commit that referenced this pull request Feb 15, 2020
…ce" (mtarld)

This PR was merged into the 4.4 branch.

Discussion
----------

Documented "Handling decorations on non existent service"

Documentation part for the PR:
symfony/symfony#33854

Commits
-------

cb07e30 Add "Handling decorations on non existent service"
@OskarStark OskarStark merged commit cb07e30 into symfony:4.4 Feb 15, 2020
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.

5 participants