Moderator: Basti
repos http://www.avedo.net/repository/public public
repos http://www.avedo.net/repository/public2 public
repos http://www.avedo.net/repository/forum private hutab
// create object and declare the file that holds the repository-servers
$repos = new Repository('repos.txt');
// get the array with the information of the repository-servers
$server = $repos->getRepos();
// get the Information of all packages available
$packs = $repos->getPackInfo();
// print out the data
print_r ($server);
print_r ($packs);
<?php
error_reporting(E_ALL);
// include HttpConnect class
require_once('HttpConnect.php');
// define server-constants
define ('REPOS', 0);
define ('SERVER', 1);
define ('PERM', 2);
define ('PWD', 3);
/***
* The Repository class allows reading files that hold the repository-servers,
* reading information about different packages and
* downloading the spezific packages
*
* @package Repository
* @version 1.0
* @author Andreas Wilhelm <Andreas2209@web.de>
* @copyright Andreas Wilhelm
**/
class Repository extends HttpConnect
{
// protected class variables
protected $repos = array();
/**
* Constructor - Is called when the class is instanced
*
* @access: public
* @param Str $path
* @return NONE
*/
public function __construct($path = 'repos.csv')
{
// save each line of data to an array-element
$lines = file($path);
foreach($lines as $line => $server)
{
// split up the differnet elements of a line by space
$server = preg_split("/ /", $server, 100, PREG_SPLIT_NO_EMPTY);
// prepare Data
$repos = trim($server[REPOS]);
$host = trim($server[SERVER]);
$perm = trim($server[PERM]);
if( isset($server[PWD]) )
{
$pwd = trim($server[PWD]);
}
// contains this line a repository-server
if( $repos == 'repos' )
{
if( $perm == 'public' )
{
$this->repos[$host] = 'NONE';
}
else if( $perm == 'private' )
{
$this->repos[$host] = $pwd;
}
else
{
throw new Exception("Line $line is not a valid path to repository-server.");
}
}
else
{
throw new Exception("Line $line holds no repository-server.");
}
}
}
/**
* getRepos() - Returns the array of repository-servers
*
* @access: public
* @return Array
*/
public function getRepos()
{
return $this->repos;
}
/**
* getPackInfo() - Gets the information about the different packages
*
* @access: public
* @return Array
*/
public function getPackInfo()
{
$host = $this->getRepos();
// array that contains the package-data
$packages = array();
foreach( $host as $url => $pwd)
{
// file that contains the package-information
$file = 'control.txt';
// prepare user and password
if( $pwd == 'NONE' )
{
$pwd = '';
$user = '';
$ssl = false;
}
else
{
$user = 'repos';
$ssl = true;
}
// prepare uri
$host = parse_url($url, PHP_URL_HOST);
$path = parse_url($url, PHP_URL_PATH);
// send HTTP-Request
$this->server($host, 80, $ssl);
$get = $this->get("$path/$file", false, false, $user, $pwd);
// get content of the package-information-file
$info = $get['CONTENT'];
// separate package-information-blocks
$block = explode("\n\n", $info);
foreach($block as $key => $packinfo)
{
//get single fields
$fields = explode("\n", $packinfo);
// save information to array
foreach($fields as $field)
{
if( preg_match('/([^:]+):(.+)/m', $field, $match) )
{
$package[$this->getName($match[1])] = trim($match[2]);
}
}
$package['Url'] = "$url/$package[Package]";
// save info-data for actual block to $packages
$packages[] = $package;
}
}
return $packages;
}
/**
* getName() - Returns the name of a received htpp-header-field
*
* @access: private
* @param Str $str
* @return String
*/
private function getName($str)
{
return preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($str)));
}
/**
* getPack() - Downloads a package to your server
*
* @access: public
* @param Str $path
* @return NONE
*/
public function getPack($path)
{
}
}
try
{
$repos = new Repository('repos.txt');
$server = $repos->getRepos();
$packs = $repos->getPackInfo();
print_r ($server);
print_r ($packs);
}
catch(Exception $e)
{
echo $e->getMessage();
}
?>
Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste