Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sourceselector.php
1<?php
2
4
12
14{
16
18 {
19 $this->sourceRepository = $sourceRepository ?: new SourceRepository(new OrmConverter());
20 }
21
22 public function setSource(string $sourceCode, IConfigFactory $configFactory): Result
23 {
24 $result = new Result();
25
26 $source = $this->sourceRepository->findByCode($sourceCode);
27
28 if (!$source)
29 {
30 $source = Factory::makeSource($sourceCode);
31 $source->setName($sourceCode);
32 }
33
34 $source->setConfig(
35 $configFactory->createConfig()
36 );
37
38 $res = $this->sourceRepository->save($source);
39
40 if(!$res->isSuccess())
41 {
42 $result->addErrors($res->getErrors());
43 }
44
45 SourceCodePicker::setSourceCode($sourceCode);
46
47 return $result;
48 }
49
50 public static function setGoogleSource(string $frontendKey, string $backendKey): Result
51 {
52 $sourceSelector = new self();
53 $configFactory = new Google\ConfigFactory($frontendKey, $backendKey);
54 return $sourceSelector->setSource(Factory::GOOGLE_SOURCE_CODE, $configFactory);
55 }
56
57 public static function setOsmSource(string $serviceUrl, string $token): Result
58 {
59 $sourceSelector = new self();
60 $configFactory = new Osm\ConfigFactory($serviceUrl, $token);
61 return $sourceSelector->setSource(Factory::OSM_SOURCE_CODE, $configFactory);
62 }
63}
static setOsmSource(string $serviceUrl, string $token)
static setGoogleSource(string $frontendKey, string $backendKey)
setSource(string $sourceCode, IConfigFactory $configFactory)
__construct(SourceRepository $sourceRepository=null)