本文整理汇总了PHP中Diff::setStatus方法的典型用法代码示例。如果您正苦于以下问题:PHP Diff::setStatus方法的具体用法?PHP Diff::setStatus怎么用?PHP Diff::setStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Diff
的用法示例。
在下文中一共展示了Diff::setStatus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compare
/**
* Generate a diff beetween to variable
*
* @param mixed $old An object
* @param mixed $new An object
* @param string $identifier A name for the variable
* @param string $status Force a status
*
* @return Diff
*/
public function compare($old, $new, $identifier = null)
{
$diff = new Diff($old, $new, $identifier);
if (null === $new) {
if (null === $old) {
//same type, same value
//nothing to do
} else {
//new variable is null but not the old
$diff->setStatus(Diff::STATUS_DELETED);
}
} else {
if (is_object($new)) {
if (null === $old) {
//the new variable is an object but the old is null
$diff->setStatus(Diff::STATUS_CREATED);
} else {
if (is_object($old)) {
//the both variables are objects
$reflectionOld = new \ReflectionClass($old);
$reflectionNew = new \ReflectionClass($new);
if ($reflectionNew->getName() !== $reflectionOld->getName()) {
//not the same class
$diff->setStatus(Diff::STATUS_TYPE_CHANGED);
} else {
//same class
//check if a compare closure exists
if (isset($this->compares[$reflectionNew->getName()])) {
$this->compares[$reflectionNew->getName()]($diff);
} else {
//this is a map of properties to check when comparing
$map = array_merge($this->buildMap($reflectionOld), $this->buildMap($reflectionNew));
$done = array();
//parse new object
if (isset($map[$reflectionNew->getName()])) {
foreach ($map[$reflectionNew->getName()] as $propertyName) {
if (isset($this->excludes[$reflectionNew->getName()])) {
if (in_array($propertyName, $this->excludes[$reflectionNew->getName()])) {
//be sure to not do the test again
unset($map[$reflectionNew->getName()][$propertyName]);
continue;
}
}
$property = $reflectionNew->getProperty($propertyName);
$property->setAccessible(true);
if ($reflectionOld->hasProperty($propertyName)) {
$oldProperty = $reflectionOld->getProperty($propertyName);
$oldProperty->setAccessible(true);
$subdiff = $this->compare($oldProperty->getValue($old), $property->getValue($new), $propertyName);
if ($subdiff->isModified()) {
$diff->setStatus(Diff::STATUS_MODIFIED);
}
} else {
$subdiff = $this->compare(null, $property->getValue($new), $propertyName);
$subdiff->setStatus(Diff::STATUS_CREATED);
$diff->setStatus(Diff::STATUS_MODIFIED);
}
$diff->addProperty($propertyName, $subdiff);
$done[$propertyName] = true;
}
}
}
}
} else {
//array or scalar variable (integer, boolean, string)
$diff->setStatus(Diff::STATUS_TYPE_CHANGED);
}
}
} else {
if (is_array($new)) {
if (null === $old) {
//the new variable is an array but the old is null
$diff->setStatus(Diff::STATUS_CREATED);
} else {
if (is_object($old)) {
//the new variable is an array but the old is an object
$diff->setStatus(Diff::STATUS_TYPE_CHANGED);
} else {
if (is_array($old)) {
//the both variables are arrays
$done = array();
//parse new array
foreach ($new as $key => $value) {
if (isset($old[$key])) {
//an old value exists
$subdiff = $this->compare($old[$key], $value, $key);
if ($subdiff->isModified() || $subdiff->isCreated() || $subdiff->isDeleted()) {
$diff->setStatus(Diff::STATUS_MODIFIED);
}
} else {
//.........这里部分代码省略.........