Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
hsphpreadconnection.php
1<?php
9namespace Bitrix\Main\Data;
10
17{
18 protected $host = 'localhost';
19 protected $port = '9998';
20
22 {
23 parent::__construct($configuration);
24
25 // host validation
27 {
28 if (!is_string($configuration['host']) || $configuration['host'] == "")
29 {
30 throw new \Bitrix\Main\Config\ConfigurationException("Invalid host parameter");
31 }
32
33 $this->host = $configuration['host'];
34 }
35
36 // port validation
38 {
39 if (!is_string($configuration['port']) || $configuration['port'] == "")
40 {
41 throw new \Bitrix\Main\Config\ConfigurationException("Invalid port parameter");
42 }
43
44 $this->port = $configuration['port'];
45 }
46 }
47
48 protected function connectInternal()
49 {
50 if ($this->isConnected)
51 {
52 return;
53 }
54
56 $this->resource->connect($this->host, $this->port);
57 $this->isConnected = true;
58 }
59
60 protected function disconnectInternal()
61 {
62 }
63
64 public function get($key)
65 {
66 return null;
67 }
68
69 public function set($key, $value)
70 {
71 return null;
72 }
73
74 public function getEntityByPrimary(\Bitrix\Main\ORM\Entity $entity, $primary, $select)
75 {
76 $this->connectInternal();
77
78 $table = $entity->getDBTableName();
79 $sqlConfiguration = $entity->getConnection()->getConfiguration();
80
81 $primary = (array) $primary;
82
83 if (count($primary) > 1)
84 {
85 throw new \Exception('HSPHP Read Socket doesn\'t support multiple select');
86 }
87
88 $indexId = $this->resource->getIndexId($sqlConfiguration['database'], $table, '', join(',', (array) $select));
89 $this->resource->select($indexId, '=', $primary);
90 $response = $this->resource->readResponse();
91
92 //foreach
93 $result = array();
94
95 if (is_array($response))
96 {
97 foreach ($response as $row)
98 {
99 $newRow = array();
100
101 foreach ($row as $k => $v)
102 {
103 $newRow[$select[$k]] = $v;
104 }
105
106 $result[] = $newRow;
107 }
108 }
109
110 return $result;
111 }
112}
getEntityByPrimary(\Bitrix\Main\ORM\Entity $entity, $primary, $select)