Static function as a factory 28/10/2014

Did you know, you could register a public static function as a factory in Nette configuration? Well, you do now. ;) Just write your factory method: class PdoFactory { public static function create(string $dsn) : \PDO { $name = 'xxx'; $password = 'asd'; return new \PDO($dsn, $name, $password); } } And register it in your config.neon: services: - PdoFactory::create('mysql:host=localhost;dbname=test')

Did you know, you could register a public static function as a factory in Nette configuration? Well, you do now. ;)

Just write your factory method:

class PdoFactory
{
	public static function create(string $dsn) : \PDO
	{
		$name = 'xxx';
		$password = 'asd';

		return new \PDO($dsn, $name, $password);
	}
}

And register it in your config.neon:

services:
	- PdoFactory::create('mysql:host=localhost;dbname=test')