Symfony\Component\DependencyInjection\Definition::setDecoratedService PHP 메소드

setDecoratedService() 공개 메소드

Sets the service that this service is decorating.
public setDecoratedService ( null | string $id, null | string $renamedId = null, integer $priority ) : Definition
$id null | string The decorated service id, use null to remove decoration
$renamedId null | string The new decorated service id
$priority integer The priority of decoration
리턴 Definition The current instance
    public function setDecoratedService($id, $renamedId = null, $priority = 0)
    {
        if ($renamedId && $id == $renamedId) {
            throw new InvalidArgumentException(sprintf('The decorated service inner name for "%s" must be different than the service name itself.', $id));
        }

        if (null === $id) {
            $this->decoratedService = null;
        } else {
            $this->decoratedService = array($id, $renamedId, (int) $priority);
        }

        return $this;
    }

Usage Example

예제 #1
0
    public function testSetGetDecoratedService()
    {
        $def = new Definition('stdClass');
        $this->assertNull($def->getDecoratedService());
        $def->setDecoratedService('foo', 'foo.renamed', 5);
        $this->assertEquals(array('foo', 'foo.renamed', 5), $def->getDecoratedService());
        $def->setDecoratedService(null);
        $this->assertNull($def->getDecoratedService());

        $def = new Definition('stdClass');
        $this->assertNull($def->getDecoratedService());
        $def->setDecoratedService('foo', 'foo.renamed');
        $this->assertEquals(array('foo', 'foo.renamed', 0), $def->getDecoratedService());
        $def->setDecoratedService(null);
        $this->assertNull($def->getDecoratedService());

        $def = new Definition('stdClass');
        $def->setDecoratedService('foo');
        $this->assertEquals(array('foo', null, 0), $def->getDecoratedService());
        $def->setDecoratedService(null);
        $this->assertNull($def->getDecoratedService());

        $def = new Definition('stdClass');
        $this->setExpectedException('InvalidArgumentException', 'The decorated service inner name for "foo" must be different than the service name itself.');
        $def->setDecoratedService('foo', 'foo');
    }
All Usage Examples Of Symfony\Component\DependencyInjection\Definition::setDecoratedService