Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/util/structure/restore_path_element.class.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00030 class restore_path_element {
00031 
00033     private $name;
00034 
00036     private $path;
00037 
00039     private $grouped;
00040 
00042     private $pobject;
00043 
00045     private $data;
00046 
00054     public function __construct($name, $path, $grouped = false) {
00055 
00056         $this->validate_name($name); // Check name
00057 
00058         $this->name = $name;
00059         $this->path = $path;
00060         $this->grouped = $grouped;
00061         $this->pobject = null;
00062         $this->data = null;
00063     }
00064 
00065     protected function validate_name($name) {
00066         // Validate various name constraints, throwing exception if needed
00067         if (empty($name)) {
00068             throw new restore_path_element_exception('restore_path_element_emptyname', $name);
00069         }
00070         if (preg_replace('/\s/', '', $name) != $name) {
00071             throw new restore_path_element_exception('restore_path_element_whitespace', $name);
00072         }
00073         if (preg_replace('/[^\x30-\x39\x41-\x5a\x5f\x61-\x7a]/', '', $name) != $name) {
00074             throw new restore_path_element_exception('restore_path_element_notasciiname', $name);
00075         }
00076     }
00077 
00078     protected function validate_pobject($pobject) {
00079         if (!is_object($pobject)) {
00080             throw new restore_path_element_exception('restore_path_element_noobject', $pobject);
00081         }
00082         if (!method_exists($pobject, $this->get_processing_method())) {
00083             throw new restore_path_element_exception('restore_path_element_missingmethod', $this->get_processing_method());
00084         }
00085     }
00086 
00087 
00089 
00090     public function set_processing_object($pobject) {
00091         $this->validate_pobject($pobject);
00092         $this->pobject = $pobject;
00093     }
00094 
00095     public function set_data($data) {
00096         $this->data = $data;
00097     }
00098     public function get_name() {
00099         return $this->name;
00100     }
00101 
00102     public function get_path() {
00103         return $this->path;
00104     }
00105 
00106     public function is_grouped() {
00107         return $this->grouped;
00108     }
00109 
00110     public function get_processing_object() {
00111         return $this->pobject;
00112     }
00113 
00114     public function get_processing_method() {
00115         return 'process_' . $this->name;
00116     }
00117 
00118     public function get_data() {
00119         return $this->data;
00120     }
00121 }
00122 
00126 class restore_path_element_exception extends moodle_exception {
00127 
00135     public function __construct($errorcode, $a = null, $debuginfo = null) {
00136         parent::__construct($errorcode, '', '', $a, $debuginfo);
00137     }
00138 }
 All Data Structures Namespaces Files Functions Variables Enumerations