LBCAlerte_ynh/sources/lib/AdService/SiteConfigFactory.php
Jimmy Monin 57708e3169 Initial commit
Functional, without SSO
2016-09-18 11:03:26 +02:00

33 lines
997 B
PHP

<?php
namespace AdService;
class SiteConfigFactory
{
protected static $instances;
/**
* @param string $url
* @param bool $singleton en général, c'est la même config pour tous.
* @return \AdService\SiteConfig\AbstractSiteConfig
*/
public static function factory($url, $singleton=true)
{
if (false !== strpos($url, "leboncoin.fr")) {
$className = 'AdService\SiteConfig\Lbc';
} elseif (false !== strpos($url, "olx.ua")) {
$className = 'AdService\SiteConfig\Olx';
} elseif (false !== strpos($url, "www.seloger.com")) {
$className = 'AdService\SiteConfig\Seloger';
} else {
throw new Exception("No config found");
}
if ($singleton) {
if (!isset(self::$instances[$className])) {
self::$instances[$className] = new $className;
}
return self::$instances[$className];
}
return new $className;
}
}