示例#1
0
 protected function pre_save(&$object)
 {
     $errors = array();
     libxml_use_internal_errors(TRUE);
     $cleaned = array();
     foreach ($object['registry'] as $section => $xml) {
         $dom = new DOMDocument('1.0');
         $dom->formatOutput = FALSE;
         if (strlen(trim($xml)) == 0) {
             kohana::log('debug', 'Section: ' . $section . ' Empty XML');
             unset($cleaned[$section]);
             continue;
         }
         try {
             if ($dom->loadXML('<root>' . trim($xml) . '</root>')) {
                 $cleaned[$section] = trim(str_replace('<?xml version="1.0"?>', '', $dom->saveXML()));
                 kohana::log('debug', 'Section: ' . $section . ' Cleaned XML: ' . $dom->saveXML());
                 continue;
             } else {
                 $errors[] = ucfirst($section);
             }
         } catch (Exception $e) {
             $errors[] = ucfirst($section);
         }
     }
     if (count($errors) > 0) {
         throw new Exception('Please correct the XML errors in these sections: ' . implode(', ', $errors));
     }
     $object['registry'] = $cleaned;
     kohana::log('debug', 'Successfully validated XML');
     parent::pre_save($object);
 }
示例#2
0
 protected function pre_save(&$object)
 {
     $patterns = $object['patterns'];
     foreach ($patterns as $key => $pattern) {
         if (empty($pattern)) {
             unset($patterns[$key]);
         }
     }
     if (empty($patterns)) {
         throw new Exception('You must provide at least one pattern');
     }
     $object['patterns'] = array_values($patterns);
     parent::pre_save($object);
 }
示例#3
0
 protected function pre_save(&$object)
 {
     if (get_class($object) == 'Endpoint') {
         $mac = strtolower(str_replace(array(' ', ':', '_', '\\', '/'), array(), $object['mac']));
         if (strlen($mac) != 12) {
             throw new Exception("Invalid mac address - it should be 12 characters long, optionally with colons.");
         }
         if (preg_match('/^[0-9a-f]{12}$/', $mac) !== 1) {
             throw new Exception("Invalid mac address - it should contain only digits (0-9), letters a-f, and optionally colons.");
         }
         $object['mac'] = $mac;
         if (array_key_exists('lines', $_POST)) {
             $object['lines'] = serialize($_POST['lines']);
         }
         if (array_key_exists('buttons', $_POST)) {
             $settings = unserialize($object['settings']);
             if (!is_array($settings)) {
                 $settings = array();
             }
             $settings['buttons'] = $_POST['buttons'];
             $object->settings = serialize($settings);
         }
     }
     parent::pre_save($object);
 }
示例#4
0
文件: odbc.php 项目: swk/bluebox
 protected function pre_save(&$object)
 {
     $object['port'] = $this->getPort();
     parent::pre_save($object);
 }