Hello,

I was wondering if it is possible to provide parameters when
referencing a service. I'll try to explain what I mean. Let's say I
have an abstract class Dao that is extended by classes Dao1 and Dao2.
The abstract class Dao has a dependency on a class X. Class X needs
some (scalar) parameters to function. Let's call this parameters: a,
b, c. The parameters a and b are the same whether I instantiate a Dao1
or Dao2. But parameter c has to have a certain value when
instantiating a Dao1 and another value when I instantiate a Dao2.
Below is some sample code:

<?php
abstract class Dao
{
  private $x;
  public function __construct( X $x )
  {
    $this->x = $x;
  }
}

class Dao1 extends Dao
{
}

class Dao2 extends Dao
{
}

class X
{
  private $a, $b, $c;
  public function __construct( $a, $b, $c )
  {
    $this->a = $a;
    $this->b = $b;
    $this->c = $c;
  }
}
?>

What I would like to able to do is:

<?php
$params = array( 'a' => 1, 'b' => 2 );
$container = new sfServiceContainerBuilder( $params );
$container->register( 'x', 'X' )->addArgument( '%a%' )-
>addArgument( '%b%' );
$container->register( 'dao1', 'Dao1' )->addArgument( new
sfServiceReference( 'x', array( 'a' => 2, 'c' => 3 ) );
$container->register( 'dao2', 'Dao2' )->addArgument( new
sfServiceReference( 'x', array( 'b' => 1, 'c' => 5 ) );
?>

This would save me from declaring two definitions of the "x" service.
The arguments provided with the sfServiceReference would overwrite (or
be appended to arguments list) the initial parameters at the moment of
service creation. I have to say I am not sure I see all the angles but
I thought I'd let you know.

Thanks in advance.

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to