8000 [DependencyInjection] IntrospectableContainerInterface::initialized() by evillemez · Pull Request #3557 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] IntrospectableContainerInterface::initialized() #3557

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
Apr 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 13 additions & 1 deletion src/Symfony/Component/DependencyInjection/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
*
* @api
*/
class Container implements ContainerInterface
class Container implements IntrospectableContainerInterface
{
protected $parameterBag;
protected $services;
Expand Down Expand Up @@ -265,6 +265,18 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
throw new ServiceNotFoundException($id);
}
}

/**
* Returns true if the given service has actually been initialized
*
* @param string $id The service identifier
*
* @return Boolean true if service has already been initialized, false otherwise
*/
public function initialized($id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use {@inheritdoc} here?

And the interface PHPDoc does not mention the return.

Copy link
Author

Choose a reason for hiding this comment

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

@inheritdoc specifically for this method, or for IntrospectableContainerInterface? I didn't use @inheritdoc here because I didn't see it done anywhere else for this class. Should I? Good catch on the interface docs, fixing.

{
return isset($this->services[strtolower($id)]);
}

/**
* Gets all service ids.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection;

/**
* IntrospectableContainerInterface defines additional introspection functionality
* for containers, allowing logic to be implemented based on a Container's state.
*
* @author Evan Villemez <evillemez@gmail.com>
*
*/
interface IntrospectableContainerInterface extends ContainerInterface
{
/**
* Check for whether or not a service has been initialized.
*
* @param string $id
*
* @return Boolean true if the service has been initialized, false otherwise
*
*/
function initialized($id);

}
12 changes: 12 additions & 0 deletions src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ public function testHas()
$this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
}

/**
* @covers Symfony\Component\DependencyInjection\Container::initialized
*/
public function testInitialized()
{
$sc = new ProjectServiceContainer();
$sc->set('foo', new \stdClass());
$this->assertTrue($sc->initialized('foo'), '->initialized() returns true if service is loaded');
$this->assertFalse($sc->initialized('foo1'), '->initialized() returns false if service is not loaded');
$this->assertFalse($sc->initialized('bar'), '->initialized() returns false if a service is defined, but not currently loaded');
}

public function testEnterLeaveCurrentScope()
{
$container = new ProjectServiceContainer();
Expand Down
0