9 public const EVENT_ID =
'onGetUrlBuilders';
11 private static self $instance;
19 protected function __construct()
28 $this->builders[$id] = $item;
31 'WEIGHT' => (int)$item->getWeight(),
32 'COUNTER' => $counter,
37 $event =
new Main\Event(
'iblock', self::EVENT_ID, []);
39 $resultList = $event->getResults();
40 if (empty($resultList) || !is_array($resultList))
44 foreach ($resultList as $eventResult)
46 if ($eventResult->getType() !== Main\EventResult::SUCCESS)
50 $row = $eventResult->getParameters();
51 if (empty($row) || !is_array($row))
55 foreach ($row as $className)
57 if (!is_string($className) || $className ===
'')
61 if (!class_exists($className))
66 $item =
new $className();
70 if (!isset($this->builders[$id]))
72 $this->builders[$id] = $item;
75 'WEIGHT' => (int)$item->getWeight(),
76 'COUNTER' => $counter,
84 unset($eventResult, $resultList);
86 if (!empty($this->map))
88 Main\Type\Collection::sortByColumn(
91 'WEIGHT' => SORT_DESC,
92 'COUNTER' => SORT_ASC,
100 if (!isset(self::$instance))
105 return self::$instance;
113 if (defined(
'URL_BUILDER_TYPE') && is_string(URL_BUILDER_TYPE))
115 if (isset($this->builders[URL_BUILDER_TYPE]))
117 $result = $this->builders[URL_BUILDER_TYPE];
120 if ($result ===
null)
122 foreach ($this->map as $row)
124 if ($this->builders[$row[
'ID']]->use())
126 $result = $this->builders[$row[
'ID']];
135 if (isset($this->builders[$builder]))
137 $result = $this->builders[$builder];
getBuilder(string $builder=BaseBuilder::TYPE_AUTODETECT)