Skip to content

Add support for deprecated definitions #15491

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 6 commits into from
Sep 25, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[DI] Trigger a deprecated error on the container builder
  • Loading branch information
Taluu committed Sep 24, 2015
commit 954247d55011514c9ba404a6c4ba51115ce4918e
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,10 @@ public function createService(Definition $definition, $id, $tryProxy = true)
throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id));
}

if ($definition->isDeprecated()) {
@trigger_error(sprintf('The service %s relies on a deprecated definition. You should avoid using it.', $id), E_USER_DEPRECATED);
}

if ($tryProxy && $definition->isLazy()) {
$container = $this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ public function testDefinitions()
}
}

public function testCreateDeprecatedService()
{
$definition = new Definition('stdClass');
$definition->setDeprecated(true);

$that = $this;
$wasTriggered = false;

set_error_handler(function ($errno, $errstr) use ($that, &$wasTriggered) {
$that->assertSame(E_USER_DEPRECATED, $errno);
$that->assertSame('The service deprecated_foo relies on a deprecated definition. You should avoid using it.', $errstr);
$wasTriggered = true;
});

$builder = new ContainerBuilder();
$builder->createService($definition, 'deprecated_foo');

restore_error_handler();
Copy link
Member

Choose a reason for hiding this comment

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

you'd need to check $this->assertTrue($wasTriggered); here also


$this->assertTrue($wasTriggered);
}

/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::register
*/
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy