当前位置: 首页>>代码示例>>PHP>>正文


PHP Diff::setStatus方法代码示例

本文整理汇总了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 {
//.........这里部分代码省略.........
开发者ID:pitpit,项目名称:php-diff,代码行数:101,代码来源:DiffEngine.php


注:本文中的Diff::setStatus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。