Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Command::recursively_show_difference( $dictated,  $current = null )

Recursively output the difference between “dictated” and “current”


Source Source

File: libraries/lifterlms-cli/src/Commands/Restful/Command.php

523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
private function recursively_show_difference( $dictated, $current = null ) {
 
    $this->output_nesting_level++;
 
    if ( $this->is_assoc_array( $dictated ) ) {
 
        foreach ( $dictated as $key => $value ) {
 
            if ( $this->is_assoc_array( $value ) || is_array( $value ) ) {
 
                $new_current = isset( $current[ $key ] ) ? $current[ $key ] : null;
                if ( $new_current ) {
                    $this->nested_line( $key . ': ' );
                } else {
                    $this->add_line( $key . ': ' );
                }
 
                $this->recursively_show_difference( $value, $new_current );
 
            } elseif ( is_string( $value ) ) {
 
                $pre = $key . ': ';
 
                if ( isset( $current[ $key ] ) && $current[ $key ] !== $value ) {
 
                    $this->remove_line( $pre . $current[ $key ] );
                    $this->add_line( $pre . $value );
 
                } elseif ( ! isset( $current[ $key ] ) ) {
 
                    $this->add_line( $pre . $value );
 
                }
            }
        }
    } elseif ( is_array( $dictated ) ) {
 
        foreach ( $dictated as $value ) {
 
            if ( ! $current
                || ! in_array( $value, $current ) ) {
                $this->add_line( '- ' . $value );
            }
        }
    } elseif ( is_string( $value ) ) {
 
        $pre = $key . ': ';
 
        if ( isset( $current[ $key ] ) && $current[ $key ] !== $value ) {
 
            $this->remove_line( $pre . $current[ $key ] );
            $this->add_line( $pre . $value );
 
        } elseif ( ! isset( $current[ $key ] ) ) {
 
            $this->add_line( $pre . $value );
 
        } else {
 
            $this->nested_line( $pre );
 
        }
    }
 
    $this->output_nesting_level--;
 
}

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.