Skip to content
Snippets Groups Projects
Commit 6252c00c authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #68179 refactor digital resources services instance creation

parent c0cdcbaa
Branches
Tags
3 merge requests!2582Dev#68179 contractuel connecteur storyplayr contactuel,!2577Dev#68184 contractuel http api moissonnage le kiosk,!2568Dev#68179 contractuel connecteur storyplayr contactuel
Pipeline #3739 failed with stage
in 11 minutes
Showing with 41 additions and 52 deletions
......@@ -29,8 +29,7 @@ class Class_DigitalResource_Batch extends Class_Batch_RessourceNumerique {
protected function _getService() {
$service = $this->_config->getService();
return new $service($this->_config);
return $this->_config->getServiceInstance();
}
......
......@@ -30,7 +30,12 @@ class Class_DigitalResource_Config extends Class_Entity {
public static function getName() {
return (new Class_DigitalResource_Name())->getName(static::class);
return static::getNameFor(static::class);
}
public static function getNameFor($class_name) {
return (new Class_DigitalResource_Name())->getName($class_name);
}
......@@ -39,6 +44,12 @@ class Class_DigitalResource_Config extends Class_Entity {
}
public static function getInstanceFor($class_name) {
return Class_DigitalResource::getInstance()->configFor(static::getNameFor($class_name));
}
public static function getInstanceFromController($controller) {
return Class_DigitalResource::getInstance()->configFor((new Class_DigitalResource_Name())->getNameFromController($controller));
}
......@@ -228,4 +239,10 @@ class Class_DigitalResource_Config extends Class_Entity {
public function getRecordSsoUrl($user, $record) {
return $this->getAlbumSsoUrl($suer, $record->getAlbum());
}
public function getServiceInstance() {
$service = $this->getService();
return new $service($this);
}
}
\ No newline at end of file
......@@ -37,5 +37,4 @@ class Class_DigitalResource_Name {
$path = array_reverse(explode('/', dirname(static::getPath($class))));
return array_shift($path);
}
}
?>
\ No newline at end of file
}
\ No newline at end of file
......@@ -23,10 +23,17 @@
class Class_DigitalResource_Service extends Class_WebService_BibNumerique_Abstract {
protected $_config;
public static function getInstance() {
return Class_DigitalResource_Config::getInstanceFor(static::class)->getServiceInstance();
}
public function __construct($config) {
$this->_config = $config;
}
protected function getDocType() {
return $this->_config->getDocType();
}
......@@ -41,4 +48,3 @@ class Class_DigitalResource_Service extends Class_WebService_BibNumerique_Abstra
return $this->_config->getName();
}
}
?>
\ No newline at end of file
......@@ -288,7 +288,7 @@ abstract class AssimilServiceTestCase extends ModelTestCase {
->whenCalled('open_url')
->answers(true);
$this->_service = new Assimil_Service(new Assimil_Config(new Class_DigitalResource_Wrapper(Class_DigitalResource::getInstance(), 'Assimil')));
$this->_service = Assimil_Service::getInstance();
Assimil_Service::setDefaultHttpClient($this->_http_client);
$this->_service->harvest();
Class_Album::clearCache();
......@@ -410,7 +410,7 @@ class AssimilServiceSecondHarvestTest extends AssimilServiceTestCase {
->whenCalled('open_url')
->answers(true);
$service = new Assimil_Service(new Assimil_Config(new Class_DigitalResource_Wrapper(Class_DigitalResource::getInstance(), 'Assimil')));
$service = Assimil_Service::getInstance();
Assimil_Service::setDefaultHttpClient($http_client);
$service->harvest();
Class_Album::clearCache();
......
......@@ -36,10 +36,7 @@ class LaSourisQuiRaconteFixtures {
->answers('a picture');
LaSourisQuiRaconte_Service::setDefaultHttpClient($http_client);
return new LaSourisQuiRaconte_Service(
new LaSourisQuiRaconte_Config(
new Class_DigitalResource_Wrapper(Class_DigitalResource::getInstance(),
'LaSourisQuiRaconte')));
return LaSourisQuiRaconte_Service::getInstance();
}
......
......@@ -41,8 +41,7 @@ class LekioskAdminVars {
abstract class LeKioskLinkModeLinkTestCase extends ModelTestCase {
protected
$_storm_default_to_volatile = true,
$_lekiosk_config;
$_storm_default_to_volatile = true;
public function setUp() {
......@@ -53,10 +52,6 @@ abstract class LeKioskLinkModeLinkTestCase extends ModelTestCase {
'mail_site' => '']);
LekioskAdminVars::activate();
$this->_lekiosk_config =
new Assimil_Config(new Class_DigitalResource_Wrapper (Class_DigitalResource::getInstance(), 'LeKiosk'));
$this->_module_menu = new Class_DigitalResource_ModuleMenu($this->_lekiosk_config);
}
}
......
......@@ -58,13 +58,11 @@ class MusicmeFixtures {
Musicme_Service::setDefaultHttpClient($http_client);
return new Musicme_Service(
new Musicme_Config(
new Class_DigitalResource_Wrapper(Class_DigitalResource::getInstance(),
'Musicme')));
return Musicme_Service::getInstance();
}
public function logValidUser() {
$group = $this->fixture('Class_UserGroup', ['id' => 1]);
......
......@@ -23,6 +23,11 @@
class Omeka_Service extends Class_WebService_BibNumerique_AbstractOAI {
protected $_config;
public static function getInstance() {
return Class_DigitalResource_Config::getInstanceFor(static::class)->getServiceInstance();
}
public function __construct($config) {
$this->_config = $config;
$this->_oaiws = $config->newOAIClient();
......
......@@ -36,10 +36,7 @@ class OmekaFixtures {
->answers(file_get_contents(__DIR__ . '/omeka_oai_page_1.xml'));
Omeka_Service::setDefaultHttpClient($http_client);
return new Omeka_Service(
new Omeka_Config(
new Class_DigitalResource_Wrapper(Class_DigitalResource::getInstance(),
'Omeka')));
return Omeka_Service::getInstance();
}
}
......@@ -148,7 +145,7 @@ class OmekaHarvestedTest extends AbstractControllerTestCase {
/** @test */
public function withoutRootURLShouldBeDisabled() {
Class_AdminVar::set('Omeka_ROOT_URL', '');
$this->assertFalse((new Class_DigitalResource())->configFor('Omeka')->isEnabled());
$this->assertFalse(Omeka_Config::getInstance()->isEnabled());
}
}
?>
\ No newline at end of file
......@@ -39,30 +39,6 @@ class SkilleosAdminVars {
abstract class SkilleosLinkModeLinkTestCase extends ModelTestCase {
protected
$_storm_default_to_volatile = true,
$_skilleos_config;
public function setUp() {
parent::setUp();
$this->fixture('Class_Profil', [
'id' => 1,
'libelle' => 'portail',
'mail_site' => '']);
SkilleosAdminVars::activate();
$this->_skilleos_config =
new Skilleos_Config(new Class_DigitalResource_Wrapper (Class_DigitalResource::getInstance(), 'Skilleos'));
$this->_module_menu = new Class_DigitalResource_ModuleMenu($this->_skilleos_config);
}
}
class SkilleosModulesControllerUserWithGroupWithRightTest
extends AbstractControllerTestCase {
......@@ -229,7 +205,7 @@ abstract class SkilleosServiceTestCase extends AbstractControllerTestCase {
->beStrict();
$this->_service = new Skilleos_Service(new Skilleos_Config(new Class_DigitalResource_Wrapper(Class_DigitalResource::getInstance(), 'Skilleos')));
$this->_service = Skilleos_Service::getInstance();
Skilleos_Service::setDefaultHttpClient($http_client);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment