From: Michael M Slusarz Date: Mon, 27 Jul 2009 18:20:53 +0000 (-0600) Subject: No more is_a() -> use instanceof instead X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=488c875b979520b1c9b6bf46049a0ddbb8fd8158;p=horde.git No more is_a() -> use instanceof instead --- diff --git a/imp/ajax.php b/imp/ajax.php index c4e8e9434..8c16c9c2e 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -562,7 +562,7 @@ case 'ShowPortal': $blocks = $linkTags = array(); $css_load = array('imp' => true); foreach ($dimp_block_list as $title => $block) { - if (is_a($block['ob'], 'Horde_Block')) { + if ($block['ob'] instanceof Horde_Block) { $app = $block['ob']->getApp(); $content = (empty($css_load[$app]) ? Horde::styleSheetLink($app, '', false) : '') . $block['ob']->getContent(); $css_load[$app] = true; diff --git a/imp/attachment.php b/imp/attachment.php index f3e353fd3..352b341d4 100644 --- a/imp/attachment.php +++ b/imp/attachment.php @@ -55,7 +55,7 @@ if ($conf['compose']['link_attachments_notify']) { if ($vfsroot->exists($full_path, $file_name . '.notify')) { $delete_id = Horde_Util::getFormData('d'); $read_id = $vfsroot->read($full_path, $file_name . '.notify'); - if (is_a($read_id, 'PEAR_Error')) { + if ($read_id instanceof PEAR_Error) { Horde::logMessage($read_id, __FILE__, __LINE__, PEAR_LOG_ERR); } elseif ($delete_id == $read_id) { $vfsroot->deleteFile($full_path, $file_name); @@ -67,7 +67,7 @@ if ($conf['compose']['link_attachments_notify']) { /* Create a random identifier for this file. */ $id = uniqid(mt_rand()); $res = $vfsroot->writeData($full_path, $file_name . '.notify', $id, true); - if (is_a($res, 'PEAR_Error')) { + if ($res instanceof PEAR_Error) { Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR); } else { /* Load $mail_user's preferences so that we can use their @@ -108,7 +108,7 @@ if ($conf['compose']['link_attachments_notify']) { // Find the file's mime-type. $file_data = $vfsroot->read($full_path, $file_name); -if (is_a($file_data, 'PEAR_Error')) { +if ($file_data instanceof PEAR_Error) { Horde::logMessage($file_data, __FILE__, __LINE__, PEAR_LOG_ERR); throw new Horde_Exception(_("The specified file cannot be read.")); } diff --git a/imp/compose.php b/imp/compose.php index 15ea8e67a..00626a63a 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -122,13 +122,13 @@ if ($token = Horde_Util::getFormData('compose_formToken')) { ? Horde_Token::factory($conf['token']['driver'], Horde::getDriverConfig('token', $conf['token']['driver'])) : Horde_Token::factory('file'); - $verified = $tokenSource->verify($token); - /* Notify and reset the actionID. */ - if (is_a($verified, 'PEAR_Error')) { - $notification->push($verified); - $actionID = null; - } elseif (!$verified) { - $notification->push(_("You have already submitted this page."), 'horde.error'); + try { + if (!$tokenSource->verify($token)) { + $notification->push(_("You have already submitted this page."), 'horde.error'); + $actionID = null; + } + } catch (Horde_Exception $e) { + $notification->push($e->getMessage()); $actionID = null; } } diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index d4ef2575a..b0fd3c08d 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -1550,7 +1550,7 @@ class IMP_Compose global $conf; $res = $GLOBALS['browser']->wasFileUploaded($name, _("attachment")); - if (is_a($res, 'PEAR_Error')) { + if ($res instanceof PEAR_Error) { throw new IMP_Compose_Exception($res); } @@ -1687,7 +1687,7 @@ class IMP_Compose $result = $vfs_file ? $vfs->write(self::VFS_ATTACH_PATH, $cacheID, $data, true) : $vfs->writeData(self::VFS_ATTACH_PATH, $cacheID, $data, true); - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { return $result; } @@ -2134,7 +2134,7 @@ class IMP_Compose $data = file_get_contents($att->getInformation('temp_filename')); $res = $vfs->writeData($fullpath, escapeshellcmd($att->getName()), $data, true); } - if (is_a($res, 'PEAR_Error')) { + if ($res instanceof PEAR_Error) { Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR); return IMP_Compose_Exception($res); } @@ -2408,7 +2408,7 @@ class IMP_Compose $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type'])); // TODO: Garbage collection? $result = $vfs->writeData(self::VFS_DRAFTS_PATH, hash('md5', Horde_Util::getFormData('user')), $body, true); - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { return; } @@ -2428,7 +2428,7 @@ class IMP_Compose $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type'])); if ($vfs->exists(self::VFS_DRAFTS_PATH, $filename)) { $data = $vfs->read(self::VFS_DRAFTS_PATH, $filename); - if (is_a($data, 'PEAR_Error')) { + if ($data instanceof PEAR_Error) { return; } $vfs->deleteFile(self::VFS_DRAFTS_PATH, $filename); diff --git a/imp/lib/Contents.php b/imp/lib/Contents.php index 196f1f616..c49977105 100644 --- a/imp/lib/Contents.php +++ b/imp/lib/Contents.php @@ -99,7 +99,7 @@ class IMP_Contents */ static public function singleton($in) { - $sig = is_a($in, 'Horde_Mime_Part') + $sig = ($in instanceof Horde_Mime_Part) ? hash('md5', serialize($in)) : $in; @@ -119,7 +119,7 @@ class IMP_Contents */ protected function __construct($in) { - if (is_a($in, 'Horde_Mime_Part')) { + if ($in instanceof Horde_Mime_Part) { $this->_message = $in; } else { list($this->_index, $this->_mailbox) = explode(IMP::IDX_SEP, $in); diff --git a/imp/lib/Identity/imp.php b/imp/lib/Identity/imp.php index ea380d4a4..009be826c 100644 --- a/imp/lib/Identity/imp.php +++ b/imp/lib/Identity/imp.php @@ -68,7 +68,8 @@ class Identity_imp extends Identity */ public function verify($identity = null) { - if (is_a($result = parent::verify($identity), 'PEAR_Error')) { + $result = parent::verify($identity); + if ($result instanceof PEAR_Error) { return $result; } diff --git a/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php b/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php index 9a61c5446..ba97c371a 100644 --- a/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php +++ b/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php @@ -40,7 +40,7 @@ class IMP_LoginTasks_Task_DeleteAttachmentsMonthly extends Horde_LoginTasks_Task /* Make sure cleaning is done recursively. */ $files = $vfs->listFolder($path, null, true, false, true); - if (is_a($files, 'PEAR_Error') || !is_array($files)) { + if (($files instanceof PEAR_Error) || !is_array($files)) { return false; } diff --git a/imp/lib/Maillog.php b/imp/lib/Maillog.php index ad74eb8fe..239fc37a1 100644 --- a/imp/lib/Maillog.php +++ b/imp/lib/Maillog.php @@ -57,7 +57,7 @@ class IMP_Maillog * is just a waste of time and a potential point of confusion, * especially since they most likely don't even know the message * is being logged. */ - if (is_a($r, 'PEAR_Error')) { + if ($r instanceof PEAR_Error) { $entry = sprintf('Could not log message details to Horde_History. Error returned: %s', $r->getMessage()); Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_ERR); } @@ -78,7 +78,7 @@ class IMP_Maillog $history = Horde_History::singleton(); $res = $history->getHistory(self::_getUniqueHistoryId($msg_id)); - if (is_a($res, 'PEAR_Error')) { + if ($res instanceof PEAR_Error) { throw new Horde_Exception($res); } diff --git a/imp/lib/Message.php b/imp/lib/Message.php index c48575a5d..1c5423041 100644 --- a/imp/lib/Message.php +++ b/imp/lib/Message.php @@ -522,7 +522,7 @@ class IMP_Message foreach ($partids as $partid) { $oldPart = $message->getPart($partid); - if (!is_a($oldPart, 'Horde_Mime_Part')) { + if (!($oldPart instanceof Horde_Mime_Part)) { continue; } $newPart = new Horde_Mime_Part(); diff --git a/imp/lib/Mime/Viewer/Images.php b/imp/lib/Mime/Viewer/Images.php index 9ebe86fb1..6df5b9d3e 100644 --- a/imp/lib/Mime/Viewer/Images.php +++ b/imp/lib/Mime/Viewer/Images.php @@ -260,13 +260,13 @@ EOD; $img = Horde_Image::factory('Gd', array('context' => $context)); } - if (!$img || is_a($img, 'PEAR_Error')) { + if (!$img || ($img instanceof PEAR_Error)) { return false; } if ($load) { $ret = $img->loadString(1, $this->_mimepart->getContents()); - if (is_a($ret, 'PEAR_Error')) { + if ($ret instanceof PEAR_Error) { return false; } } diff --git a/imp/lib/Mime/Viewer/Itip.php b/imp/lib/Mime/Viewer/Itip.php index 91f59ef4e..65dbe9bfa 100644 --- a/imp/lib/Mime/Viewer/Itip.php +++ b/imp/lib/Mime/Viewer/Itip.php @@ -84,7 +84,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver // Get the method type. $method = $vCal->getAttribute('METHOD'); - if (is_a($method, 'PEAR_Error')) { + if ($method instanceof PEAR_Error) { $method = ''; } @@ -222,7 +222,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver // Get the organizer details. $organizer = $vEvent->getAttribute('ORGANIZER'); - if (is_a($organizer, 'PEAR_Error')) { + if ($organizer instanceof PEAR_Error) { break; } $organizer = parse_url($organizer); @@ -237,22 +237,22 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver $vEvent_reply = Horde_iCalendar::newComponent('vevent', $vCal); $vEvent_reply->setAttribute('UID', $vEvent->getAttribute('UID')); - if (!is_a($vEvent->getAttribute('SUMMARY'), 'PEAR_error')) { + if (!$vEvent->getAttribute('SUMMARY') instanceof PEAR_Error)) { $vEvent_reply->setAttribute('SUMMARY', $vEvent->getAttribute('SUMMARY')); } - if (!is_a($vEvent->getAttribute('DESCRIPTION'), 'PEAR_error')) { + if (!$vEvent->getAttribute('DESCRIPTION') instanceof PEAR_Error) { $vEvent_reply->setAttribute('DESCRIPTION', $vEvent->getAttribute('DESCRIPTION')); } $dtstart = $vEvent->getAttribute('DTSTART', true); $vEvent_reply->setAttribute('DTSTART', $vEvent->getAttribute('DTSTART'), array_pop($dtstart)); - if (!is_a($vEvent->getAttribute('DTEND'), 'PEAR_error')) { + if (!($vEvent->getAttribute('DTEND') instanceof PEAR_Error)) { $dtend = $vEvent->getAttribute('DTEND', true); $vEvent_reply->setAttribute('DTEND', $vEvent->getAttribute('DTEND'), array_pop($dtend)); } else { $duration = $vEvent->getAttribute('DURATION', true); $vEvent_reply->setAttribute('DURATION', $vEvent->getAttribute('DURATION'), array_pop($duration)); } - if (!is_a($vEvent->getAttribute('SEQUENCE'), 'PEAR_error')) { + if (!($vEvent->getAttribute('SEQUENCE') instanceof PEAR_Error)) { $vEvent_reply->setAttribute('SEQUENCE', $vEvent->getAttribute('SEQUENCE')); } $vEvent_reply->setAttribute('ORGANIZER', $vEvent->getAttribute('ORGANIZER'), array_pop($organizer)); @@ -366,7 +366,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver // Get the organizer details. $organizer = $vFb->getAttribute('ORGANIZER'); - if (is_a($organizer, 'PEAR_Error')) { + if ($organizer instanceof PEAR_Error) { break; } $organizer = parse_url($organizer); @@ -379,13 +379,13 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver $endStamp = $startStamp + (60 * 24 * 3600); } else { $startStamp = $vFb->getAttribute('DTSTART'); - if (is_a($startStamp, 'PEAR_Error')) { + if ($startStamp instanceof PEAR_Error) { $startStamp = time(); } $endStamp = $vFb->getAttribute('DTEND'); - if (is_a($endStamp, 'PEAR_Error')) { + if ($endStamp instanceof PEAR_Error) { $duration = $vFb->getAttribute('DURATION'); - if (is_a($duration, 'PEAR_Error')) { + if ($duration instanceof PEAR_Error) { $endStamp = $startStamp + (60 * 24 * 3600); } else { $endStamp = $startStamp + $duration; @@ -533,7 +533,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver } $start = $vfb->getAttribute('DTSTART'); - if (!is_a($start, 'PEAR_Error')) { + if (!($start instanceof PEAR_Error)) { if (is_array($start)) { $html .= '

' . _("Start:") . ' ' . strftime($prefs->getValue('date_format'), mktime(0, 0, 0, $start['month'], $start['mday'], $start['year'])) . '

'; } else { @@ -542,7 +542,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver } $end = $vfb->getAttribute('DTEND'); - if (!is_a($end, 'PEAR_Error')) { + if (!($end instanceof PEAR_Error)) { if (is_array($end)) { $html .= '

' . _("End:") . ' ' . strftime($prefs->getValue('date_format'), mktime(0, 0, 0, $end['month'], $end['mday'], $end['year'])) . '

'; } else { @@ -601,7 +601,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver $options = array(); $attendees = $vevent->getAttribute('ATTENDEE'); - if (!is_a($attendees, 'PEAR_Error') && + if (!($attendees instanceof PEAR_Error) && !empty($attendees) && !is_array($attendees)) { $attendees = array($attendees); @@ -627,7 +627,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver // Check that you are one of the attendees here. $is_attendee = false; - if (!is_a($attendees, 'PEAR_Error') && !empty($attendees)) { + if (!($attendees instanceof PEAR_Error) && !empty($attendees)) { $identity = Identity::singleton(array('imp', 'imp')); for ($i = 0, $c = count($attendees); $i < $c; ++$i) { $attendee = parse_url($attendees[$i]); @@ -677,7 +677,8 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver break; case 'CANCEL': - if (is_a($instance = $vevent->getAttribute('RECURRENCE-ID'), 'PEAR_Error')) { + $instance = $vevent->getAttribute('RECURRENCE-ID'); + if ($instance instanceof PEAR_Error) { $desc = _("%s has cancelled \"%s\"."); if ($registry->hasMethod('calendar/delete')) { $options[] = ''; @@ -692,7 +693,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver } $summary = $vevent->getAttribute('SUMMARY'); - if (is_a($summary, 'PEAR_Error')) { + if ($summary instanceof PEAR_Error) { $desc = sprintf($desc, htmlspecialchars($sender), _("Unknown Meeting")); } else { $desc = sprintf($desc, htmlspecialchars($sender), htmlspecialchars($summary)); @@ -705,7 +706,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver } $start = $vevent->getAttribute('DTSTART'); - if (!is_a($start, 'PEAR_Error')) { + if (!($start instanceof PEAR_Error)) { if (is_array($start)) { $html .= '

' . _("Start:") . ' ' . strftime($prefs->getValue('date_format'), mktime(0, 0, 0, $start['month'], $start['mday'], $start['year'])) . '

'; } else { @@ -714,7 +715,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver } $end = $vevent->getAttribute('DTEND'); - if (!is_a($end, 'PEAR_Error')) { + if (!($end instanceof PEAR_Error)) { if (is_array($end)) { $html .= '

' . _("End:") . ' ' . strftime($prefs->getValue('date_format'), mktime(0, 0, 0, $end['month'], $end['mday'], $end['year'])) . '

'; } else { @@ -723,23 +724,23 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver } $sum = $vevent->getAttribute('SUMMARY'); - if (!is_a($sum, 'PEAR_Error')) { + if (!($sum instanceof PEAR_Error)) { $html .= '

' . _("Summary") . ': ' . htmlspecialchars($sum) . '

'; } else { $html .= '

' . _("Summary") . ': ' . _("None") . '

'; } $desc = $vevent->getAttribute('DESCRIPTION'); - if (!is_a($desc, 'PEAR_Error')) { + if (!($desc instanceof PEAR_Error)) { $html .= '

' . _("Description") . ': ' . nl2br(htmlspecialchars($desc)) . '

'; } $loc = $vevent->getAttribute('LOCATION'); - if (!is_a($loc, 'PEAR_Error')) { + if (!($loc instanceof PEAR_Error)) { $html .= '

' . _("Location") . ': ' . htmlspecialchars($loc) . '

'; } - if (!is_a($attendees, 'PEAR_Error') && !empty($attendees)) { + if (!($attendees instanceof PEAR_Error) && !empty($attendees)) { $html .= '

' . _("Attendees") . '

'; $html .= ''; @@ -861,7 +862,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver $options = array(); $organizer = $vtodo->getAttribute('ORGANIZER', true); - if (is_a($organizer, 'PEAR_Error')) { + if ($organizer instanceof PEAR_Error) { $sender = _("An unknown person"); } else { if (isset($organizer[0]['CN'])) { @@ -882,7 +883,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver } $summary = $vtodo->getAttribute('SUMMARY'); - if (is_a($summary, 'PEAR_Error')) { + if ($summary instanceof PEAR_Error) { $desc = sprintf($desc, htmlspecialchars($sender), _("Unknown Task")); } else { $desc = sprintf($desc, htmlspecialchars($sender), htmlspecialchars($summary)); @@ -895,26 +896,26 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver } $priority = $vtodo->getAttribute('PRIORITY'); - if (!is_a($priority, 'PEAR_Error')) { + if (!($priority instanceof PEAR_Error)) { $html .= '

' . _("Priority") . ': ' . (int)$priority . '

'; } $sum = $vtodo->getAttribute('SUMMARY'); - if (!is_a($sum, 'PEAR_Error')) { + if (!($sum instanceof PEAR_Error)) { $html .= '

' . _("Summary") . ': ' . htmlspecialchars($sum) . '

'; } else { $html .= '

' . _("Summary") . ': ' . _("None") . '

'; } $desc = $vtodo->getAttribute('DESCRIPTION'); - if (!is_a($desc, 'PEAR_Error')) { + if (!($desc instanceof PEAR_Error)) { $html .= '

' . _("Description") . ': ' . nl2br(htmlspecialchars($desc)) . '

'; } $attendees = $vtodo->getAttribute('ATTENDEE'); $params = $vtodo->getAttribute('ATTENDEE', true); - if (!is_a($attendees, 'PEAR_Error') && !empty($attendees)) { + if (!($attendees instanceof PEAR_Error) && !empty($attendees)) { $html .= '

' . _("Attendees") . '

'; if (!is_array($attendees)) { $attendees = array($attendees); diff --git a/imp/lib/Mime/Viewer/Pdf.php b/imp/lib/Mime/Viewer/Pdf.php index b0a2080a2..8ec5a7c68 100644 --- a/imp/lib/Mime/Viewer/Pdf.php +++ b/imp/lib/Mime/Viewer/Pdf.php @@ -116,13 +116,13 @@ class IMP_Horde_Mime_Viewer_Pdf extends Horde_Mime_Viewer_Pdf $img = Horde_Image::factory('Im', array('context' => array('tmpdir' => Horde::getTempdir(), 'convert' => $GLOBALS['conf']['image']['convert']))); - if (is_a($img, 'PEAR_Error')) { + if ($img instanceof PEAR_Error) { return false; } if ($load) { $ret = $img->loadString(1, $this->_mimepart->getContents()); - if (is_a($ret, 'PEAR_Error')) { + if ($ret instanceof PEAR_Error) { return false; } } diff --git a/imp/pgp.php b/imp/pgp.php index 8115f1f88..069af6b47 100644 --- a/imp/pgp.php +++ b/imp/pgp.php @@ -47,12 +47,12 @@ function _getImportKey() } $res = $GLOBALS['browser']->wasFileUploaded('upload_key', _("key")); - if (!is_a($res, 'PEAR_Error')) { - return file_get_contents($_FILES['upload_key']['tmp_name']); - } else { + if ($res instanceof PEAR_Error) { $GLOBALS['notification']->push($res, 'horde.error'); return; } + + return file_get_contents($_FILES['upload_key']['tmp_name']); } function _textWindowOutput($filename, $msg) diff --git a/imp/smime.php b/imp/smime.php index db011bfb5..17268953d 100644 --- a/imp/smime.php +++ b/imp/smime.php @@ -36,12 +36,12 @@ function _getImportKey() } $res = $GLOBALS['browser']->wasFileUploaded('upload_key', _("key")); - if (!is_a($res, 'PEAR_Error')) { - return file_get_contents($_FILES['upload_key']['tmp_name']); - } else { + if ($res instanceof PEAR_Error) { $GLOBALS['notification']->push($res, 'horde.error'); return; } + + return file_get_contents($_FILES['upload_key']['tmp_name']); } function _actionWindow() @@ -270,7 +270,7 @@ if ($openssl_check && $prefs->getValue('use_smime')) { } $t->set('personalkey-help', Horde_Help::link('imp', 'smime-overview-personalkey')); - $t->set('secure_check', is_a($secure_check, 'PEAR_Error')); + $t->set('secure_check', $secure_check instanceof PEAR_Error); if (!$t->get('secure_check')) { $t->set('has_key', $prefs->getValue('smime_public_key') && $prefs->getValue('smime_private_key')); if ($t->get('has_key')) {
' . _("Name") . '' . _("Role") . '' . _("Status") . '