Author: sevein
Date: Tue Nov 24 13:34:55 2009
New Revision: 3948

Log:
Update sfInstall class (from sfInstallPlugin) to make use of sfWebBrowserPlugin 
with error handling support.

Modified:
   trunk/plugins/sfInstallPlugin/lib/sfInstall.class.php

Modified: trunk/plugins/sfInstallPlugin/lib/sfInstall.class.php
==============================================================================
--- trunk/plugins/sfInstallPlugin/lib/sfInstall.class.php       Tue Nov 24 
13:08:02 2009        (r3947)
+++ trunk/plugins/sfInstallPlugin/lib/sfInstall.class.php       Tue Nov 24 
13:34:55 2009        (r3948)
@@ -1,6 +1,20 @@
 <?php
 
 /*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 // TODO: Integrate with symfony/data/bin/check_configuration.php
@@ -158,18 +172,26 @@
   protected static function get($url)
   {
     $request = sfContext::getInstance()->request;
+    $browser = new sfWebBrowser;
 
-    // TODO: Error handling
-    $handle = fsockopen($request->getHost(), 80, $null, $null, 5);
-    fwrite($handle, implode("\r\n", array(
-      'GET '.$url.' HTTP/1.1',
-      'Host: '.$request->getHost()))."\r\n\r\n");
-    fflush($handle);
-
-    $contents = stream_get_contents($handle);
-    fclose($handle);
-
-    return $contents;
+    try
+    {
+      if (true !== 
$browser->get($request->getUriPrefix().$url)->responseIsError())
+      {
+        // Successful response (eg. 200, 201, etc)
+        return $browser->getResponseText();
+      }
+      else
+      {
+        // Error response (eg. 404, 500, etc)
+        return false;
+      }
+    }
+    catch (Exception $e)
+    {
+      // Adapter error [curl,fopen,fsockopen] (eg. Host not found)
+      return false;
+    }
   }
 
   // Must be called after checkDatabasesYml() because the $noScriptNameUrl will
@@ -389,17 +411,17 @@
     switch (strtolower(substr($memoryLimit, -1)))
     {
       case 'k':
-        $memoryLimit = round(intval(substr($memoryLimit, 0, -1))/1024, 3);
+        $memoryLimit = round(intval(substr($memoryLimit, 0, -1)) / 1024, 3);
         break;
       case 'm':
         $memoryLimit = intval(substr($memoryLimit, 0, -1));
         break;
       case 'g':
-        $memoryLimit = intval(substr($memoryLimit, 0, -1))*1024;
+        $memoryLimit = intval(substr($memoryLimit, 0, -1)) * 1024;
         break;
       default:
         // If suffix is not K, M, or G (case-insensitive), then value is 
assumed to be bytes
-        $memoryLimit = round(intval($memoryLimit)/1048576, 3);
+        $memoryLimit = round(intval($memoryLimit) / 1048576, 3);
     }
 
     if ($memoryLimit < self::$MINIMUM_MEMORY_LIMIT_MB)

--

You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.


Reply via email to