Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
find.php
1<?php
2
4
17
22class Find extends Base
23{
25 public function findById(int $id, string $languageId, int $searchScope)
26 {
27 return $this->find(IFindById::class, 'findById', [$id, $languageId], $searchScope);
28 }
29
31 public function findByExternalId(string $externalId, string $sourceCode, string $languageId, int $searchScope)
32 {
33 return $this->find(IFindByExternalId::class, 'findByExternalId', [$externalId, $sourceCode, $languageId], $searchScope);
34 }
35
37 public function findByText(string $text, string $languageId, int $searchScope)
38 {
39 return $this->find(IFindByText::class, 'findByText', [$text, $languageId], $searchScope) ?? new Location\Collection();
40 }
41
42 public function autocomplete(array $params, int $searchScope)
43 {
44 return $this->find(ISupportAutocomplete::class, 'autocomplete', [$params], $searchScope) ?? [];
45 }
46
47 public function findParents(Location $location, string $languageId, int $searchScope)
48 {
49 return $this->find(IFindParents::class, 'findParents', [$location, $languageId], $searchScope) ?? new Parents();
50 }
51
54 {
55 $idx = 0;
56
57 foreach($locationRepositories as $repository)
58 {
59 if($repository instanceof IFindById
60 || $repository instanceof IFindByExternalId
61 || $repository instanceof IFindByText
62 || $repository instanceof IFindParents
63 )
64 {
65 $key = (string)$this->getRepoPriority($repository) . (string)($idx++);
66 $this->locationRepositories[$key] = $repository;
67 }
68 }
69
70 ksort($this->locationRepositories);
71 return $this;
72 }
73
81 protected function find(string $interface, string $method, array $params, int $searchScope)
82 {
83 $result = null;
84
85 foreach($this->locationRepositories as $repository)
86 {
87 if($repository instanceof IScope)
88 {
89 if(!$repository->isScopeSatisfy($searchScope))
90 {
91 continue;
92 }
93 }
94
95 if($repository instanceof $interface)
96 {
97 $result = call_user_func_array([$repository, $method], $params);
98
99 if($result)
100 {
101 if(!($result instanceof Location\Collection) || $result->count() > 0)
102 {
103 return $result;
104 }
105 }
106 }
107 }
108
109 return null;
110 }
111
116 protected function getRepoPriority(IRepository $repository)
117 {
118 if($repository instanceof ICache)
119 {
120 $result = self::REPO_PRIORITY_A;
121 }
122 elseif($repository instanceof IDatabase)
123 {
124 $result = self::REPO_PRIORITY_B;
125 }
126 else
127 {
128 $result = self::REPO_PRIORITY_C;
129 }
130
131 return $result;
132 }
133
134
135
136}
find(string $interface, string $method, array $params, int $searchScope)
Definition find.php:81
findById(int $id, string $languageId, int $searchScope)
Definition find.php:25
findByExternalId(string $externalId, string $sourceCode, string $languageId, int $searchScope)
Definition find.php:31
setLocationRepositories(array $locationRepositories)
Definition find.php:53
autocomplete(array $params, int $searchScope)
Definition find.php:42
findByText(string $text, string $languageId, int $searchScope)
Definition find.php:37
findParents(Location $location, string $languageId, int $searchScope)
Definition find.php:47