Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
executer.php
1<?php
2
4
8
9
11{
12 private $api;
13 private $scriptPath;
14
15 public function __construct($api)
16 {
17 if (empty($api))
18 throw new ArgumentNullException('api');
19
20 $this->scriptPath = $_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/sale/lib/tradingplatform/vk/api/scripts";
21 $this->api = $api;
22 }
23
24
31 private function getScript($name)
32 {
33 $filePath = $this->scriptPath . '/' . $name . '.vks';
34 if (IO\File::isFileExists($filePath))
35 {
36 $script = IO\File::getFileContents($filePath);
37// $script = file_get_contents($filePath);
38
39 return $script;
40 }
41
42 return NULL;
43 }
44
45
53 public function __call($methodName, $arguments)
54 {
55// prepare METHOD name
56 $methodName = mb_strtolower($methodName);
57 if (mb_strpos($methodName, 'execute') == 0)
58 {
59 $methodName = str_replace("execute", "", $methodName);
60 }
61
62 $script = $this->getScript($methodName);
63 if (count($arguments))
64 {
65 $script = $this->prepareParams($script, $arguments[0]);
66 }
67 $response = $this->api->run('execute', array('code' => $script));
68
69 return $response;
70 }
71
72
81 private function prepareParams($script, $params)
82 {
83 foreach ($params as $key => $value)
84 {
85 if (is_array($value))
86 {
87 $value = \CUtil::PhpToJSObject($value);
88 }
89 $script = str_replace('%'.mb_strtoupper($key) . '%', $value, $script);
90 }
91
92 return $script;
93 }
94
101 private function decodeMultibyteUnicode($str)
102 {
103 $str = preg_replace_callback('/\\\\u(\w{4})/', function ($matches)
104 {
105 return html_entity_decode('&#x' . $matches[1] . ';', null, 'UTF-8');
106 }, $str);
107
108 return $str;
109 }
110}