1+ <?php
2+
3+ namespace Caxy \HtmlDiffBundle \Service ;
4+
5+ use Symfony \Component \DependencyInjection \ContainerInterface ;
6+ use Caxy \HtmlDiff \HtmlDiff ;
7+
8+ class HtmlDiffService
9+ {
10+ protected $ container ;
11+
12+ protected $ specialCaseTags = array ('strong ' , 'b ' , 'i ' , 'big ' , 'small ' , 'u ' , 'sub ' , 'sup ' , 'strike ' , 's ' , 'p ' );
13+
14+ protected $ encoding = 'UTF-8 ' ;
15+
16+ public function __construct (ContainerInterface $ container )
17+ {
18+ $ this ->container = $ container ;
19+
20+ $ encoding = $ this ->container ->getParameter ('caxy_html_diff.encoding ' );
21+ if (!empty ($ encoding )) {
22+ $ this ->encoding = $ encoding ;
23+ }
24+
25+ $ specialCaseTags = $ this ->container ->getParameter ('caxy_html_diff.special_case_tags ' );
26+ if (!empty ($ specialCaseTags )) {
27+ $ this ->specialCaseTags = $ specialCaseTags ;
28+ }
29+ }
30+
31+ public function diff ($ oldText , $ newText )
32+ {
33+ $ diff = new HtmlDiff ($ oldText , $ newText , $ this ->encoding , $ this ->specialCaseTags );
34+
35+ return $ diff ->build ();
36+ }
37+
38+ public function getEncoding ()
39+ {
40+ return $ this ->encoding ;
41+ }
42+
43+ public function setEncoding ($ encoding )
44+ {
45+ $ this ->encoding = $ encoding ;
46+
47+ return $ this ;
48+ }
49+
50+ public function getSpecialCaseTags ()
51+ {
52+ return $ this ->specialCaseTags ;
53+ }
54+
55+ public function addSpecialCaseTag ($ tag )
56+ {
57+ if (!in_array ($ tag , $ this ->specialCaseTags )) {
58+ $ this ->specialCaseTags [] = $ tag ;
59+ }
60+
61+ return $ this ;
62+ }
63+
64+ public function removeSpecialCaseTag ($ tag )
65+ {
66+ if (($ key = array_search ($ tag , $ this ->specialCaseTags )) !== false ) {
67+ unset($ this ->specialCaseTags [$ key ]);
68+ }
69+
70+ return $ this ;
71+ }
72+
73+ }
0 commit comments