Skip to content

Commit 7a7e928

Browse files
author
hikki
committed
1.3
1 parent bf0ee17 commit 7a7e928

File tree

2 files changed

+67
-27
lines changed

2 files changed

+67
-27
lines changed

src/DLPHelper.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace DLP;
4+
5+
6+
/**
7+
* Class DLPHelper
8+
* @package DLP
9+
*/
10+
class DLPHelper
11+
{
12+
/**
13+
* dot增减计算
14+
* @param array $selected 过去已经选择
15+
* @param array $select 已选择
16+
* @return array [insert,delete]
17+
*/
18+
public static function dotCalculate(array $selected,array $select)
19+
{
20+
$insert = [];
21+
$delete = [];
22+
$intersect = array_intersect($selected,$select);
23+
if(count($intersect) == count($selected) && count($intersect) == count($select)){
24+
return [$insert,$delete];
25+
}
26+
if(count($intersect) == count($selected) && count($intersect) < count($select)){
27+
$insert = array_diff($select,$intersect);
28+
return [$insert,$delete];
29+
}
30+
if(count($intersect) < count($selected) && count($intersect) == count($select)){
31+
$delete = array_diff($selected,$intersect);
32+
return [$insert,$delete];
33+
}
34+
if(count($intersect) < count($selected) && count($intersect) < count($select)){
35+
$insert = array_diff($select,$intersect);
36+
$delete = array_diff($selected,$intersect);
37+
return [$insert,$delete];
38+
}
39+
}
40+
41+
/**
42+
* @param array $data
43+
* @return false|string
44+
*/
45+
public static function safeJson(array $data)
46+
{
47+
self::recursiveJsonArray($data);
48+
return json_encode($data, JSON_UNESCAPED_UNICODE);
49+
}
50+
51+
/**
52+
* @param array $data
53+
*/
54+
private static function recursiveJsonArray(array &$data)
55+
{
56+
foreach ($data as &$d) {
57+
if (is_array($d)) {
58+
self::recursiveJsonArray($d);
59+
} else {
60+
$d = str_replace(['"', '\'', ':', '\\', '{', '}', '[', ']','`'], '', $d);
61+
}
62+
}
63+
}
64+
}

src/DLPViewer.php

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class DLPViewer
2727
public static function makeComponentDot(Form $form, string $column, string $title, array $select = [], array $selected = [],bool $strict = false)
2828
{
2929
if ($strict) {
30-
$select = self::safeJson($select);
31-
$selected = self::safeJson($selected);
30+
$select = DLPHelper::safeJson($select);
31+
$selected = DLPHelper::safeJson($selected);
3232
} else {
3333
$select = json_encode($select, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
3434
$selected = json_encode($selected, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
@@ -52,7 +52,7 @@ public static function makeComponentDot(Form $form, string $column, string $titl
5252
public static function makeComponentLine(Form $form, string $column, string $title, array $settings = [], array $data = [], bool $strict = false)
5353
{
5454
if($strict) {
55-
$data = self::safeJson($data);
55+
$data = DLPHelper::safeJson($data);
5656
}else{
5757
$data = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
5858
}
@@ -249,28 +249,4 @@ public static function result($success = true, $message = 'OK', $data = [])
249249
->header('Content-Type', 'application/json;charset=utf-8')
250250
->header('Access-Control-Allow-Origin', '*');
251251
}
252-
253-
/**
254-
* @param array $data
255-
* @return false|string
256-
*/
257-
public static function safeJson(array $data)
258-
{
259-
self::recursiveJsonArray($data);
260-
return json_encode($data, JSON_UNESCAPED_UNICODE);
261-
}
262-
263-
/**
264-
* @param array $data
265-
*/
266-
private static function recursiveJsonArray(array &$data)
267-
{
268-
foreach ($data as &$d) {
269-
if (is_array($d)) {
270-
self::recursiveJsonArray($d);
271-
} else {
272-
$d = str_replace(['"', '\'', ':', '\\', '{', '}', '[', ']','`'], '', $d);
273-
}
274-
}
275-
}
276252
}

0 commit comments

Comments
 (0)