Procházet zdrojové kódy

ZF-10363: fetches the version of the latest stable release (of Zend Framework)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22963 44c647ce-9c0f-0410-b52a-842ac1e357ba
intiilapa před 15 roky
rodič
revize
becc2e8ca2

+ 13 - 0
documentation/manual/en/module_specs/Zend_Version.xml

@@ -28,6 +28,19 @@
 $cmp = Zend_Version::compareVersion('2.0.0');
 ]]></programlisting>
     </example>
+
+    <para>
+        The static method <methodname>Zend_Version::getLatest()</methodname> provides the version 
+        number of the last stable release available for download on the site 
+        <ulink linked="http://framework.zend.com/download/latest">Zend Framework</ulink>.
+    </para>
+
+    <example id="zend.version.latest.example">
+        <programlisting language="php"><![CDATA[
+// returns 1.11.0 (or a later version)
+echo Zend_Version::getLatest();
+]]></programlisting>
+    </example>
 </sect1>
 <!--
 vim:se ts=4 sw=4 et:

+ 13 - 0
documentation/manual/fr/module_specs/Zend_Version.xml

@@ -29,4 +29,17 @@
 $cmp = Zend_Version::compareVersion('2.0.0');
 ]]></programlisting>
     </example>
+
+    <para>
+        La méthode statique <methodname>Zend_Version::getLatest()</methodname> permet d'obtenir le 
+        numéro de version de la dernière release stable disponible au téléchargement sur le site 
+        <ulink linked="http://framework.zend.com/download/latest">Zend Framework</ulink>.
+    </para>
+
+    <example id="zend.version.latest.example">
+        <programlisting language="php"><![CDATA[
+// retourne 1.11.0 (ou une version ultérieure)
+echo Zend_Version::getLatest();
+]]></programlisting>
+    </example>
 </sect1>

+ 30 - 2
library/Zend/Version.php

@@ -35,11 +35,18 @@ final class Zend_Version
     const VERSION = '1.11.0dev';
 
     /**
+     * The latest stable version Zend Framework available
+     * 
+     * @var string
+     */
+    protected static $_lastestVersion;
+
+    /**
      * Compare the specified Zend Framework version string $version
      * with the current Zend_Version::VERSION of Zend Framework.
      *
      * @param  string  $version  A version string (e.g. "0.7.1").
-     * @return boolean           -1 if the $version is older,
+     * @return int           -1 if the $version is older,
      *                           0 if they are the same,
      *                           and +1 if $version is newer.
      *
@@ -50,4 +57,25 @@ final class Zend_Version
         $version = preg_replace('/(\d)pr(\d?)/', '$1a$2', $version);
         return version_compare($version, strtolower(self::VERSION));
     }
-}
+
+    /**
+     * Fetches the version of the latest stable release
+     * 
+     * @link http://framework.zend.com/download/latest
+     * @return string
+     */
+    public static function getLatest()
+    {
+        if (null === self::$_lastestVersion) {
+            self::$_lastestVersion = 'not available';
+
+            $handle = fopen('http://framework.zend.com/api/zf-version', 'r');        
+            if (false !== $handle) {
+                self::$_lastestVersion = stream_get_contents($handle);
+                fclose($handle);
+            }
+        }
+
+        return self::$_lastestVersion;
+    }
+}

+ 12 - 0
tests/Zend/VersionTest.php

@@ -89,6 +89,18 @@ class Zend_VersionTest extends PHPUnit_Framework_TestCase
         }
     }
 
+    /**
+     * @group ZF-10363
+     */
+    public function testFetchLatestVersion()
+    {
+        $actual = Zend_Version::getLatest();
+        if ('not available' === $actual) {
+            $this->markIncomplete('http://framework.zend.com/ may be down');
+        }
+
+        $this->assertRegExp('/^[1-2](\.[0-9]+){2}/', $actual);
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == "Zend_VersionTest::main") {