Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
2
4
5use \Bitrix\Main\Web\Uri;
6
7class Base
8{
9 protected $directory = '';
10 protected $pages = [];
11 protected static $instance;
12
13 final public static function getInstance()
14 {
15 if (!isset(static::$instance))
16 {
17 static::$instance = new static();
18 }
19 return static::$instance;
20 }
21
22 protected function getDir()
23 {
24 return SITE_DIR.$this->directory;
25 }
26
27 protected function getReplaced(string $url, $replace = null, $subject = null)
28 {
29 if (!is_null($replace) && !is_null($subject))
30 {
31 $url = str_replace($replace, $subject, $url);
32 }
33
34 return $url;
35 }
36
37 protected function addParams($url, $params)
38 {
39 if (is_array($params))
40 {
41 $uri = new Uri($url);
42 $uri->addParams($params);
43 $url = $uri->getUri();
44 }
45
46 return $url;
47 }
48
49 protected function getUrl($page, $replace = null, $subject = null, $query = null)
50 {
51 $url = null;
52 if(array_key_exists($page, $this->pages))
53 {
54 $url = $this->getDir().$this->pages[$page];
55
56 if (!is_null($replace) && !is_null($subject))
57 {
58 $url = $this->getReplaced($url, $replace, $subject);
59 }
60 $url = $this->getReplaced($url, '//', '/');
61
62 if(is_array($query))
63 {
64 $url = $this->addParams($url, $query);
65 }
66 }
67
68 return $url;
69 }
70
71}
addParams($url, $params)
Definition base.php:37
getReplaced(string $url, $replace=null, $subject=null)
Definition base.php:27
getUrl($page, $replace=null, $subject=null, $query=null)
Definition base.php:49
static getInstance()
Definition base.php:13