Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
hsphpreadconnection.php
1
<?php
9
namespace
Bitrix\Main\Data
;
10
16
class
HsphpReadConnection
extends
NosqlConnection
implements
\Bitrix\Main\ORM\Query\INosqlPrimarySelector
17
{
18
protected
$host
=
'localhost'
;
19
protected
$port
=
'9998'
;
20
21
public
function
__construct
(
array
$configuration
)
22
{
23
parent::__construct(
$configuration
);
24
25
// host validation
26
if
(
array_key_exists
(
'host'
,
$configuration
))
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
37
if
(
array_key_exists
(
'port'
,
$configuration
))
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
55
$this->
resource
=
new \HSPHP\ReadSocket
();
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
}
Bitrix\Main\Data\Connection\$configuration
$configuration
Definition
connection.php:21
Bitrix\Main\Data\Connection\isConnected
isConnected()
Definition
connection.php:62
Bitrix\Main\Data\HsphpReadConnection
Definition
hsphpreadconnection.php:17
Bitrix\Main\Data\HsphpReadConnection\getEntityByPrimary
getEntityByPrimary(\Bitrix\Main\ORM\Entity $entity, $primary, $select)
Definition
hsphpreadconnection.php:74
Bitrix\Main\Data\HsphpReadConnection\connectInternal
connectInternal()
Definition
hsphpreadconnection.php:48
Bitrix\Main\Data\HsphpReadConnection\disconnectInternal
disconnectInternal()
Definition
hsphpreadconnection.php:60
Bitrix\Main\Data\HsphpReadConnection\$host
$host
Definition
hsphpreadconnection.php:18
Bitrix\Main\Data\HsphpReadConnection\$port
$port
Definition
hsphpreadconnection.php:19
Bitrix\Main\Data\HsphpReadConnection\__construct
__construct(array $configuration)
Definition
hsphpreadconnection.php:21
Bitrix\Main\Data\NosqlConnection
Definition
nosqlconnection.php:12
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Main\ORM\Query\INosqlPrimarySelector
Definition
inosqlprimaryselector.php:14
Bitrix\Main\Data
Definition
aliases.php:105
Bitrix
modules
main
lib
data
hsphpreadconnection.php
Создано системой
1.10.0