<commit_before><?php
namespace PhpBrew;
use DOMDocument;


/**
 * parse available downloads
 */
class PhpSource
{

    static function getStasVersions()
    {
        $baseUrl = 'http://downloads.php.net/stas/';
        $html = file_get_contents($baseUrl);
        $dom = new DOMDocument;
        $dom->loadHtml( $html );

        $items = $dom->getElementsByTagName('a');
        $versions = array();
        foreach( $items as $item ) 
        {
            $href = $item->getAttribute('href');
            if( preg_match('/php-(.*?)\.tar\.bz2$/' , $href , $regs ) ) {
                $version = $regs[1];
                $link = $baseUrl . $href;
                $versions[ 'php-' . $version] = array( 'url' => $link );
            }
        }
        return $versions;
    }

    static function getStableVersions()
    {
        // svn tags: https://svn.php.net/repository/php/php-src/tags/
        // reference: http://www.php.net/releases/
        return array( 
            'php-5.4.0'  => array( 'url' => 'http://www.php.net/distributions/php-5.4.0.tar.bz2' ),
            'php-5.3.10' => array( 'url' => 'http://www.php.net/distributions/php-5.3.10.tar.bz2'),
            'php-5.3.9' =>  array( 'url' => 'http://www.php.net/distributions/php-5.3.9.tar.bz2' ),
            'php-5.3.8' =>  array( 'url' => 'http://www.php.net/distributions/php-5.3.8.tar.bz2' ),
            'php-5.3.7' =>  array( 'url' => 'http://www.php.net/distributions/php-5.3.7.tar.bz2' ),
            'php-5.3.2' =>  array( 'url' => 'http://museum.php.net/php5/php-5.3.2.tar.bz2'       ),
            'php-5.3.1' =>  array( 'url' => 'http://museum.php.net/php5/php-5.3.1.tar.bz2'       ),
        );
    }

    static function getSvnVersions()
    {
        //    http://www.php.net/svn.php # svn
        return array( 
            'php-svn-head' => array( 'svn' => 'https://svn.php.net/repository/php/php-src/trunk' ),
            'php-svn-5.3' => array( 'svn' => 'https://svn.php.net/repository/php/php-src/branches/PHP_5_3' ),
            'php-svn-5.4' => array( 'svn' => 'https://svn.php.net/repository/php/php-src/branches/PHP_5_4' ),
        );
    }

    static function getSnapshotVersions()
    {
        // http://snaps.php.net/php5.3-201202070630.tar.bz2
    }<commit_msg>Add getting known php version online<commit_after><?php
namespace PhpBrew;
use DOMDocument;


/**
 * parse available downloads
 */
class PhpSource
{
    static function versionCompare($verion1, $verion2)
    {
        if( $verion1 == $verion2 ) {
            return 0;
        }
        return version_compare($verion1, $verion2, '>') ? -1 : 1;
    }

    static function getStasVersions()
    {
        $baseUrl = 'http://downloads.php.net/stas/';
        $html = file_get_contents($baseUrl);
        $dom = new DOMDocument;
        $dom->loadHtml( $html );

        $items = $dom->getElementsByTagName('a');
        $versions = array();
        foreach( $items as $item )
        {
            $href = $item->getAttribute('href');
            if( preg_match('/php-(.*?)\.tar\.bz2$/' , $href , $regs ) ) {
                $version = $regs[1];
                $link = $baseUrl . $href;
                $versions[ 'php-' . $version] = array( 'url' => $link );
            }
        }
        return $versions;
    }

    static function getStableVersions()
    {
        // reference: http://www.php.net/downloads.php
        //            http://www.php.net/releases/
        $downloadUrls = array(
            'http://www.php.net/downloads.php',
            'http://www.php.net/releases/'
        );
        $phpFilePattern = '/php-(.*?)\.tar\.bz2/';
        $versions = array();

        foreach( $downloadUrls as $downloadUrl ) {
            $html = @file_get_contents($downloadUrl);
            if( $html ){
                $baseUrl = 'http://www.php.net/distributions/';
                $dom = new DOMDocument;
                @$dom->loadHtml( $html );

                $items = $dom->getElementsByTagName('a');
                foreach( $items as $item ) {
                    $link = $item->getAttribute('href');
                    if( preg_match($phpFilePattern, $link, $regs ) ) {
                        $version = 'php-' . $regs[1];
                        if( strpos($link, '/') === 0 ) {
                            $link = $baseUrl . $version . '.tar.bz2';
                        }
                        $versions[$version] = array( 'url' => $link );
                    }
                }
            }
            else {
                echo "connection eror: $downloadUrl\n";
            }
        }
        uksort( $versions, array('self', 'versionCompare') );

        return $versions;
    }

    static function getSvnVersions()
    {
        //    http://www.php.net/svn.php # svn
        return array(
            'php-svn-head' => array( 'svn' => 'https://svn.php.net/repository/php/php-src/trunk' ),
            'php-svn-5.3' => array( 'svn' => 'https://svn.php.net/repository/php/php-src/branches/PHP_5_3' ),
            'php-svn-5.4' => array( 'svn' => 'https://svn.php.net/repository/php/php-src/branches/PHP_5_4' ),
        );
    }

    static function getSnapshotVersions()
    {
        // http://snaps.php.net/php5.3-201202070630.tar.bz2
    }
{'fraction_non_alphanumeric': 0.18363844393592677, 'fraction_numerical': 0.02212051868802441, 'mean_word_length': 1.6159600997506234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, 'https://': 7, 'lorem ipsum': 0, 'www.': 13, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3069421', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1757, 'n_words': 267}