Skip to content

Commit 0f06e50

Browse files
committed
Update TableDiff to initialize purifier with a cache storage location. Updated the HtmlDiffConfig with the additional parameter.
1 parent b3f41cc commit 0f06e50

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

lib/Caxy/HtmlDiff/HtmlDiffConfig.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ class HtmlDiffConfig
7373
*/
7474
protected $cacheProvider;
7575

76+
/**
77+
* @var null|String
78+
*/
79+
protected $purifierCacheLocation = null;
80+
7681
/**
7782
* @return HtmlDiffConfig
7883
*/
@@ -441,6 +446,26 @@ public function getCacheProvider()
441446
return $this->cacheProvider;
442447
}
443448

449+
/**
450+
* @param null|string
451+
*
452+
* @return $this
453+
*/
454+
public function setPurifierCacheLocation($purifierCacheLocation = null)
455+
{
456+
$this->purifierCacheLocation = $purifierCacheLocation;
457+
458+
return $this;
459+
}
460+
461+
/**
462+
* @return null|string
463+
*/
464+
public function getPurifierCacheLocation()
465+
{
466+
return $this->purifierCacheLocation;
467+
}
468+
444469
/**
445470
* @param string $tag
446471
*

lib/Caxy/HtmlDiff/Table/TableDiff.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public static function create($oldText, $newText, HtmlDiffConfig $config = null)
6666

6767
if (null !== $config) {
6868
$diff->setConfig($config);
69+
70+
$this->initPurifier($config->getPurifierCacheLocation());
6971
}
7072

7173
return $diff;
@@ -80,11 +82,32 @@ public static function create($oldText, $newText, HtmlDiffConfig $config = null)
8082
* @param array|null $specialCaseTags
8183
* @param bool|null $groupDiffs
8284
*/
83-
public function __construct($oldText, $newText, $encoding = 'UTF-8', $specialCaseTags = null, $groupDiffs = null)
85+
public function __construct(
86+
$oldText,
87+
$newText,
88+
$encoding = 'UTF-8',
89+
$specialCaseTags = null,
90+
$groupDiffs = null,
91+
$defaultPurifierSerializerCache = null
92+
)
8493
{
8594
parent::__construct($oldText, $newText, $encoding, $specialCaseTags, $groupDiffs);
8695

87-
$this->purifier = new \HTMLPurifier(\HTMLPurifier_Config::createDefault());
96+
$this->initPurifier($defaultPurifierSerializerCache);
97+
}
98+
99+
/**
100+
* Initializes HTMLPurifier with cache location
101+
* @param null|string $defaultPurifierSerializerCache
102+
* @return void
103+
*/
104+
protected function initPurifier($defaultPurifierSerializerCache)
105+
{
106+
$HTMLPurifierConfig = \HTMLPurifier_Config::createDefault();
107+
// Cache for the serializer defaults to inside the HTMLPurifier library
108+
// under the DefinitionCache/Serializer folder.
109+
$HTMLPurifierConfig->set('Cache.SerializerPath', $defaultPurifierSerializerCache);
110+
$this->purifier = new \HTMLPurifier($HTMLPurifierConfig);
88111
}
89112

90113
/**

0 commit comments

Comments
 (0)