-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from caxy/feature/list-diff-fixes
Misc. list diffing updates and fixes
- Loading branch information
Showing
5 changed files
with
498 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
namespace Caxy\HtmlDiff\ListDiff; | ||
|
||
class DiffList | ||
{ | ||
protected $listType; | ||
|
||
protected $listItems = array(); | ||
|
||
protected $attributes = array(); | ||
|
||
protected $startTag; | ||
|
||
protected $endTag; | ||
|
||
public function __construct($listType, $startTag, $endTag, $listItems = array(), $attributes = array()) | ||
{ | ||
$this->listType = $listType; | ||
$this->startTag = $startTag; | ||
$this->endTag = $endTag; | ||
$this->listItems = $listItems; | ||
$this->attributes = $attributes; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getListType() | ||
{ | ||
return $this->listType; | ||
} | ||
|
||
/** | ||
* @param mixed $listType | ||
* | ||
* @return DiffList | ||
*/ | ||
public function setListType($listType) | ||
{ | ||
$this->listType = $listType; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getStartTag() | ||
{ | ||
return $this->startTag; | ||
} | ||
|
||
public function getStartTagWithDiffClass($class = 'diff-list') | ||
{ | ||
return str_replace('>', ' class="'.$class.'">', $this->startTag); | ||
} | ||
|
||
/** | ||
* @param mixed $startTag | ||
*/ | ||
public function setStartTag($startTag) | ||
{ | ||
$this->startTag = $startTag; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getEndTag() | ||
{ | ||
return $this->endTag; | ||
} | ||
|
||
/** | ||
* @param mixed $endTag | ||
*/ | ||
public function setEndTag($endTag) | ||
{ | ||
$this->endTag = $endTag; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getListItems() | ||
{ | ||
return $this->listItems; | ||
} | ||
|
||
/** | ||
* @param mixed $listItems | ||
* | ||
* @return DiffList | ||
*/ | ||
public function setListItems($listItems) | ||
{ | ||
$this->listItems = $listItems; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
namespace Caxy\HtmlDiff\ListDiff; | ||
|
||
class DiffListItem | ||
{ | ||
protected $attributes = array(); | ||
|
||
protected $text; | ||
|
||
protected $startTag; | ||
|
||
protected $endTag; | ||
|
||
public function __construct($text, $attributes = array(), $startTag, $endTag) | ||
{ | ||
$this->text = $text; | ||
$this->attributes = $attributes; | ||
$this->startTag = $startTag; | ||
$this->endTag = $endTag; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getAttributes() | ||
{ | ||
return $this->attributes; | ||
} | ||
|
||
/** | ||
* @param array $attributes | ||
* | ||
* @return DiffListItem | ||
*/ | ||
public function setAttributes($attributes) | ||
{ | ||
$this->attributes = $attributes; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getText() | ||
{ | ||
return $this->text; | ||
} | ||
|
||
/** | ||
* @param mixed $text | ||
* | ||
* @return DiffListItem | ||
*/ | ||
public function setText($text) | ||
{ | ||
$this->text = $text; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getStartTag() | ||
{ | ||
return $this->startTag; | ||
} | ||
|
||
public function getStartTagWithDiffClass($class = 'normal') | ||
{ | ||
return str_replace('>', ' class="'.$class.'">', $this->startTag); | ||
} | ||
|
||
/** | ||
* @param mixed $startTag | ||
* | ||
* @return DiffListItem | ||
*/ | ||
public function setStartTag($startTag) | ||
{ | ||
$this->startTag = $startTag; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getEndTag() | ||
{ | ||
return $this->endTag; | ||
} | ||
|
||
/** | ||
* @param mixed $endTag | ||
* | ||
* @return DiffListItem | ||
*/ | ||
public function setEndTag($endTag) | ||
{ | ||
$this->endTag = $endTag; | ||
|
||
return $this; | ||
} | ||
|
||
public function getHtml($class = 'normal', $wrapTag = null) | ||
{ | ||
$startWrap = $wrapTag ? sprintf('<%s>', $wrapTag) : ''; | ||
$endWrap = $wrapTag ? sprintf('</%s>', $wrapTag) : ''; | ||
return sprintf('%s%s%s%s%s', $this->getStartTagWithDiffClass($class), $startWrap, $this->getInnerHtml(), $endWrap, $this->endTag); | ||
} | ||
|
||
public function getInnerHtml() | ||
{ | ||
return implode('', $this->text); | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->getHtml(); | ||
} | ||
} |
Oops, something went wrong.