@inject with default value (optional service)

Notice: This thread is very old.
matopeto
Member | 395
+
0
-

In nette 2.0 i used to write optional services as:

<?php

function injectService(Service $service = null) {
	$this->service = $service;
}

?>

That make Service optional (If service was not defined in config, it has default null value).

Is any way to do that with @inject annotation?

This doesn't work:

<?php

   /** @var Service @inject */
   public $service = null;

?>

And I know that I can use old style, but I would like use this with simple @inject annotation.

(Sorry for my bad english:))

enumag
Member | 2118
+
0
-

Null is the default value in PHP so this would be really wierd.

Maybe some option in the annotaion:

/** @var Service @inject(optional=TRUE) */
public $service;
matopeto
Member | 395
+
0
-

Thanks,

But it is only implementation suggestion? Because it is not working in Nette 2.1.*.

enumag
Member | 2118
+
0
-

Yeah that's only suggestion. I don't think a solution exists right now.

Last edited by enumag (2014-04-15 17:35)