Skip to content

Instantly share code, notes, and snippets.

@immutef
Created September 26, 2014 10:36
Show Gist options
  • Save immutef/fbd4996cd6380a0e4480 to your computer and use it in GitHub Desktop.
Save immutef/fbd4996cd6380a0e4480 to your computer and use it in GitHub Desktop.
Abstract Service Definitions with Constructor Arguments
<?php
abstract class AbstractService
{
public function __construct(SomeService $someService)
{
// ...
}
}
<?php
class ConcreteService extends AbstractService
{
public function __construct(SomeService $someService, AnotherService $anotherService)
{
parent::__construct($someService);
// ...
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="service.abstract.class">AbstractService</parameter>
<parameter key="service.concrete.class">ConcreteService</parameter>
</parameters>
<services>
<service id="service.abstract" class="%service.abstract.class%" abstract="true">
<argument type="service" id="some.service"/>
</service>
<service id="service.concrete" class="%service.concrete.class%" parent="service.abstract">
<argument type="service" id="another.service"/>
</service>
</services>
</container>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment