Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
linkbase.php
1<?php
3
7
8abstract class LinkBase
9{
10 protected $query;
11 protected $page;
12
13 public function __construct()
14 {
15 $this->query = new Fields();
16 }
17
18 public function setRequestUri($url)
19 {
20 $uri = new Uri($url);
21 return $this
22 ->setPage($uri->getPath())
23 ->setQuery($uri->getQuery());
24 }
25
26 public function setField($name, $value)
27 {
28 $this->query->set($name, $value);
29 return $this;
30 }
31 public function getField($name)
32 {
33 return $this->query->get($name);
34 }
35 public function setFieldsValues($values)
36 {
37 if(is_array($values))
38 {
39 $this->query->setValues($values);
40 }
41 return $this;
42 }
43 public function getFieldsValues()
44 {
45 return $this->query->getValues();
46 }
47 public function setQuery($query)
48 {
49 $params = $this->parseParams($query);
50 if(is_array($params))
51 {
52 foreach ($params as $name=>$value)
53 {
54 $this->query->set($name, $value);
55 }
56 }
57 return $this;
58 }
59
60 public function build()
61 {
62 $uri = new Uri($this->page);
63 return $uri
64 ->addParams($this->getFieldsValues())
65 ->getUri();
66 }
67 public function redirect()
68 {
69 LocalRedirect($this->build());
70 }
71
72 public function setPage($page)
73 {
74 $this->page = $page;
75 return $this;
76 }
77 public function setPageByType($type)
78 {
79 $registry = Registry::getRegistry()[$this->getType()];
80 $page = isset($registry[$type]) ? $registry[$type]:null;
81
82 if(is_null($page))
83 {
84 throw new ArgumentException("Unsupported link type: {$type}");
85 }
86
87 $this->setPage($page);
88 return $this;
89 }
90 public function getPage()
91 {
92 return $this->page;
93 }
94
95 protected function parseParams($data)
96 {
97 parse_str($data, $values);
98 return $values;
99 }
100
101 abstract public function getType();
102
106 abstract public function fill();//setFieldsValues($this->getDefaultFieldsValues())
107}