NOBUG: Fixing trivial variable name mismatch
[moodle.git] / backup / util / helper / backup_general_helper.class.php
CommitLineData
69dd0c8c
EL
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * @package moodlecore
20 * @subpackage backup-helper
21 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25/**
26 * Non instantiable helper class providing general helper methods for backup/restore
27 *
28 * This class contains various general helper static methods available for backup/restore
29 *
30 * TODO: Finish phpdocs
31 */
32abstract class backup_general_helper extends backup_helper {
33
34 /**
35 * Calculate one checksum for any array/object. Works recursively
36 */
37 public static function array_checksum_recursive($arr) {
38
39 $checksum = ''; // Init checksum
40
41 // Check we are going to process one array always, objects must be cast before
42 if (!is_array($arr)) {
43 throw new backup_helper_exception('array_expected');
44 }
45 foreach ($arr as $key => $value) {
46 if ($value instanceof checksumable) {
47 $checksum = md5($checksum . '-' . $key . '-' . $value->calculate_checksum());
48 } else if (is_object($value)) {
49 $checksum = md5($checksum . '-' . $key . '-' . self::array_checksum_recursive((array)$value));
50 } else if (is_array($value)) {
51 $checksum = md5($checksum . '-' . $key . '-' . self::array_checksum_recursive($value));
52 } else {
53 $checksum = md5($checksum . '-' . $key . '-' . $value);
54 }
55 }
56 return $checksum;
57 }
58}