Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 18 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 03, 2012
@c9s c9s Remove old PEAR package stuff. 52d60fa
Commits on Apr 04, 2012
@c9s c9s Fix package installer f907947
View
BIN  onion
Binary file not shown
View
2  scripts/onion
@@ -13,6 +13,8 @@
require __DIR__ . '/../vendor/pear/Universal/ClassLoader/SplClassLoader.php';
$classLoader = new \Universal\ClassLoader\SplClassLoader(array(
'Onion' => 'src',
+ 'PEARX' => 'src',
+ 'CurlKit' => 'src',
'CLIFramework' => 'vendor/pear',
'GetOptionKit' => 'vendor/pear',
));
View
1  src/Onion/Command/BundleCommand.php
@@ -67,7 +67,6 @@ function execute()
}
$installer = new \Onion\Installer( $manager );
$installer->install();
-
$logger->info('Done');
}
}
View
4 src/Onion/Dependency/DependencyManager.php
@@ -28,13 +28,13 @@ class DependencyManager
- function hasPackage( \Onion\Package\PackageInterface $package)
+ function hasPackage($package)
{
return isset( $this->packagesById[ $package->getId() ] );
}
- function addPackage( \Onion\Package\PackageInterface $package)
+ function addPackage($package)
{
// check package
if( isset( $this->packagesById[ $package->getId() ] ) ) {
View
85 src/Onion/Dependency/DependencyResolver.php
@@ -29,7 +29,7 @@ function __construct()
$this->logger = \Onion\Application::getLogger();
}
- function resolvePearPackage(\Onion\Pear\Package $package)
+ function resolvePearPackage($package)
{
if( $this->manager->hasPackage( $package ) ) {
// xxx: check existing package version requirement..
@@ -40,7 +40,7 @@ function resolvePearPackage(\Onion\Pear\Package $package)
$this->manager->addPackage($package);
// get dependent package info
- $this->logger->info( "Resolving PEAR package dependency: {$package->name}" );
+ $this->logger->info( "Resolving PEAR package dependency: {$package->getId()}" );
$version = $package->latest;
if( isset( $package->deps[ $version ]['required']['extension']) ) {
@@ -64,15 +64,15 @@ function resolvePearPackage(\Onion\Pear\Package $package)
foreach( $pkgs as $dep ) {
$packageName = $dep['name'];
- $channelHost = $dep['channel'];
+ $host = $dep['channel'];
- $this->logger->info2("Discovering channel $channelHost for $packageName",1);
+ $this->logger->info2("Discovering channel $host for $packageName",1);
- // discover pear channel
- $discover = new \Onion\Pear\ChannelDiscover;
- $channel = $discover->lookup( $channelHost );
- $channel->prefetchPackagesInfo();
- $depPackage = $channel->getPackage( $packageName );
+ $channel = new \PEARX\Channel( $host, array(
+ 'cache' => \Onion\Application::getInstance()->getCache(),
+ // xxx: downloader support
+ ));
+ $depPackage = $channel->findPackage( $packageName );
$this->resolvePearPackage( $depPackage );
}
}
@@ -81,47 +81,36 @@ function resolvePearPackage(\Onion\Pear\Package $package)
function resolve( $package )
{
// expand package and package dependencies to package object
- if( is_a( $package ,'\Onion\Package\Package' ) )
- {
-
- // if installed , check if upgrade is need ?
- if( ! $package->local )
- $this->manager->addPackage($package);
-
-
- // expand package dependencies
- $deps = $package->getDependencies();
- foreach( $deps as $dep ) {
-
- // Expand pear package (refacotr this to dependencyInfo object)
- if( $dep['type'] == 'pear' ) {
- $depPackageName = $dep['name'];
- $this->logger->info2("Tracking dependency for PEAR package: {$dep['name']} ..." , 1);
- if( $dep['resource']['type'] == 'channel' ) {
- $channelHost = $dep['resource']['channel'];
-
- // discover pear channel
- $discover = new \Onion\Pear\ChannelDiscover;
- $channel = $discover->lookup( $channelHost );
- $channel->prefetchPackagesInfo();
- $depPackage = $channel->getPackage( $depPackageName );
- $this->resolvePearPackage( $depPackage );
- }
- }
- elseif( $dep['type'] == 'extension' ) {
- $depExtensionName = $dep['name'];
- $this->logger->info2("Tracking dependency for extension: {$dep['name']} ..." , 1);
+ // if installed , check if upgrade is need ?
+ if( ! $package->local )
+ $this->manager->addPackage($package);
+
+ // expand package dependencies
+ $deps = $package->getDependencies();
+ foreach( $deps as $dep ) {
+
+ // Expand pear package (refacotr this to dependencyInfo object)
+ if( $dep['type'] == 'pear' ) {
+ $depPackageName = $dep['name'];
+ $this->logger->info2("Tracking dependency for PEAR package: {$dep['name']} ..." , 1);
+ if( $dep['resource']['type'] == 'channel' ) {
+ $host = $dep['resource']['channel'];
+
+ $channel = new \PEARX\Channel( $host , array(
+ 'cache' => \Onion\Application::getInstance()->getCache(),
+ ));
+ $depPackage = $channel->findPackage( $depPackageName );
+
+ // discover pear channel
+ // $channel->prefetchPackagesInfo();
+ // $depPackage = $channel->getPackage( $depPackageName );
+ $this->resolvePearPackage( $depPackage );
}
}
- }
- elseif( is_a( $package , '\Onion\Package\PearPackage' ) ) {
- // xxx: support pear package
-
- }
- elseif( is_a( $package , '\Onion\Package\LibraryPackage' ) ) {
- // xxx: support library package
-
-
+ elseif( $dep['type'] == 'extension' ) {
+ $depExtensionName = $dep['name'];
+ $this->logger->info2("Tracking dependency for extension: {$dep['name']} ..." , 1);
+ }
}
}
View
6 src/Onion/Installer.php
@@ -55,10 +55,8 @@ function install()
{
$packages = $this->manager->getPackages();
foreach( $packages as $package ) {
- if( is_a( $package , '\Onion\Pear\Package' ) ) {
- $installer = $this->getPearInstaller();
- $installer->install( $package );
- }
+ $installer = $this->getPearInstaller();
+ $installer->install( $package );
}
}
}
View
4 src/Onion/Installer/PearInstaller.php
@@ -41,10 +41,10 @@ function install( $package )
$packageSourceDir = $packageDir . DIRECTORY_SEPARATOR . $package->name . '-' . $package->latest;
// var_dump( $package );
- $url = $package->getDistUrlByVersion( $package->latest );
+ $url = $package->getReleaseDistUrl( $package->latest );
// download the package.
- $logger->info( "Downloading " . $package->getId() . '-' . $package->latest . "..." );
+ $logger->info( "Downloading " . $package->name . '-' . $package->latest . "..." );
$cwd = getcwd();
chdir( $workspace );
View
239 src/Onion/Pear/Channel.php
@@ -1,239 +0,0 @@
-<?php
-namespace Onion\Pear;
-use Onion\Downloader\DownloaderManager;
-use DOMDocument;
-
-/**
- * A Simple Pear Channel data manipulator
- *
- */
-class Channel
-{
-
- /**
- * channel name
- */
- public $name;
-
- /**
- * channel alias
- */
- public $alias;
-
- /**
- * channel summary
- */
- public $summary;
-
- /**
- * primary server
- */
- public $primary;
-
- /**
- * mirror servers
- *
- * @var array
- */
- public $mirrors = array();
-
-
- /**
- * Packages info
- *
- * Contains the information of packages of current channel.
- */
- public $packages = array();
-
- function __construct()
- {
-
- }
-
- function loadCache()
- {
- // XXX: try to load channel info from cache.
- }
-
- function getName()
- {
- return $this->name;
- }
-
- function getSummary()
- {
- return $this->summary;
- }
-
- function getAlias()
- {
- return $this->alias;
- }
-
- function getPrimaryServer()
- {
- return $this->primary;
- }
-
- function getMirrorServers()
- {
- return $this->mirrors;
- }
-
- function getRestBaseUrl($version = null)
- {
- if( $version && $this->primary[$version] )
- return $this->primary[ $version ];
-
- $versions = array('REST1.3','REST1.2','REST1.1');
- foreach( $versions as $k ) {
- if( isset( $this->primary[ $k ] ) )
- return $this->primary[ $k ];
- }
- }
-
-
- function getAllPackages()
- {
- return $this->prefetchPackagesInfo();
- }
-
- // cache this.
- function prefetchPackagesInfo()
- {
- if( ! empty($this->packages) ) {
- return $this->packages;
- }
-
- $dm = new DownloaderManager;
-
- $restBaseurl = $this->getRestBaseUrl();
- $uriComp = parse_url( $restBaseurl );
-
- $baseurl = $uriComp['scheme'] . '://' . $uriComp['host'];
-
- $categoryXml = $dm->downloadXml($restBaseurl . "/c/categories.xml");
- $categories = $categoryXml->getElementsByTagName("c");
- foreach ($categories as $category) {
-
- // path like: /rest/c/Default/info.xml
- $categoryLink = $category->getAttribute("xlink:href");
- $categoryLink = str_replace("info.xml", "packagesinfo.xml", $categoryLink);
- $packagesInfoXml = $dm->downloadXml( $baseurl . '/' . $categoryLink);
- $packagesInfo = $packagesInfoXml->getElementsByTagName('pi');
- foreach( $packagesInfo as $package ) {
-
-
- // build package information
-
- // echo $package->C14N();
- $p = $package->getElementsByTagName('p')->item(0);
- $packageName = $p->getElementsByTagName('n')->item(0)->nodeValue;
- $packageSummary = $p->getElementsByTagName('s')->item(0)->nodeValue;
- $packageDesc = $p->getElementsByTagName('d')->item(0)->nodeValue;
- $packageChannel = $p->getElementsByTagName('c')->item(0)->nodeValue;
- $packageLicense = $p->getElementsByTagName('l')->item(0)->nodeValue;
-
-
- $packageObj = new Package;
- $packageObj->name = $packageName;
- $packageObj->summary = $packageSummary;
- $packageObj->desc = $packageDesc;
- $packageObj->channel = $packageChannel;
- $packageObj->license = $packageLicense;
- $packageObj->releases = array();
- $packageObj->deps = array();
-
- $latestStable = 0;
- $latestAlpha = 0;
- $latestBeta = 0;
- $latest = 0;
- $releases = $package->getElementsByTagName('a')->item(0)->getElementsByTagName('r');
- foreach( $releases as $release ) {
- $version = $release->getElementsByTagName('v')->item(0)->nodeValue;
- $stability = $release->getElementsByTagName('s')->item(0)->nodeValue;
-
- $packageObj->releases[ $version ] = $stability;
-
- if( version_compare( $version , $latest ) === 1 ) {
- $latest = $version;
- }
-
- switch( $stability ) {
- case 'stable':
- if( version_compare( $version , $latestStable ) === 1 ) {
- $latestStable = $version;
- }
- break;
- case 'alpha':
- if( version_compare( $version , $latestAlpha ) === 1 ) {
- $latestAlpha = $version;
- }
- break;
- case 'beta':
- if( version_compare( $version , $latestBeta ) === 1 ) {
- $latestBeta = $version;
- }
- break;
- }
- }
-
- $packageObj->stable = $latestStable;
- $packageObj->alpha = $latestAlpha;
- $packageObj->beta = $latestBeta;
- $packageObj->latest = $latest;
-
-
- $deps = $package->getElementsByTagName('deps');
- foreach( $deps as $dep ) {
- $version = $dep->getElementsByTagName('v')->item(0)->nodeValue;
- $depInfo = unserialize($dep->getElementsByTagName('d')->item(0)->nodeValue);
-
- /*
- * depInfo structure:
- array(1) {
- ["required"]=>
- array(2) {
- ["php"]=>
- array(1) {
- ["min"]=>
- string(3) "5.3"
- }
- ["pearinstaller"]=>
- array(1) {
- ["min"]=>
- string(3) "1.4"
- }
- }
- }
- */
- $packageObj->deps[ $version ] = $depInfo;
-
- // XXX: build Resource Informations for fetching
-
- }
- // var_dump( $packageObj );
- $this->packages[ $packageObj->name ] = $packageObj;
- }
- }
-
- // save to channel object.
- return $this->packages;
- }
-
- function getPackage($name)
- {
- return $this->packages[ $name ];
- }
-
- function removePackage($name)
- {
- unset($this->packages[$name]);
- }
-
- function __sleep()
- {
- return array( 'name' , 'alias' , 'summary' , 'primary' , 'mirrors' , 'packages' );
- }
-
-}
View
48 src/Onion/Pear/ChannelParser.php
@@ -1,48 +0,0 @@
-<?php
-/*
- * This file is part of the Onion package.
- *
- * (c) Yo-An Lin <cornelius.howl@gmail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- */
-namespace Onion\Pear;
-use Onion\Pear\Channel;
-use SimpleXMLElement;
-use Exception;
-
-class ChannelParser
-{
-
- function parse($arg)
- {
- $xmlstr = null;
- if( strpos($arg,'<?xml') === 0 ) {
- $xmlstr = $arg;
- } elseif( is_file($arg) ) {
- $xmlstr = file_get_contents($arg);
- } else {
- throw new Exception("Unexpectedd argument for channel parser.");
- }
-
- // build channel object.
- $channel = new Channel;
- $xml = new SimpleXMLElement($xmlstr);
-
- $channel->name = (string) $xml->name;
- $channel->summary = (string) $xml->summary;
- $channel->alias = (string) $xml->suggestedalias;
-
- // build primary server section
- $channel->primary = array();
- foreach( $xml->servers->primary->rest->baseurl as $element ) {
- $attrs = $element->attributes();
- $channel->primary[ (string) $attrs->type ] = (string) $element;
- }
- return $channel;
- }
-
-}
-
View
84 src/Onion/Pear/Package.php
@@ -1,84 +0,0 @@
-<?php
-/*
- * This file is part of the Onion package.
- *
- * (c) Yo-An Lin <cornelius.howl@gmail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- */
-namespace Onion\Pear;
-use Onion\Package\PackageInterface;
-use Exception;
-
-/**
- * pear channel package
- * */
-class Package
- implements PackageInterface
-{
- public $name;
- public $desc;
- public $summary;
- public $channel;
- public $license;
-
- /* last version */
- public $latest;
-
- /* last stable version */
- public $stable;
-
- /* last alpha version */
- public $alpha;
-
- /* last beta version */
- public $beta;
-
- /* all releases */
- public $releases = array();
-
- /**
- * dependencies
- */
- public $deps = array();
-
- public function getId()
- {
- return $this->name;
- }
-
- public function __sleep()
- {
- return array('name','summary','channel','desc','license','latest','stable','alpha','beta','releases','deps');
- }
-
- public function __wakeup()
- {
-
- }
-
- public function getLastDistUrl()
- {
- return $this->getDistUrlByVersion( $this->latest );
- }
-
- public function getDistUrlByVersion($version, $extension = 'tgz' )
- {
- // xxx: save for https or http base url from channel discover object
- return sprintf( 'http://%s/get/%s-%s.%s' , $this->channel, $this->name , $version , $extension );
- }
-
- public function toArray()
- {
- return (array) $this;
-
- $a = array('name','summary','channel','desc','license','latest','stable','alpha','beta','releases','deps');
- foreach( array() as $k ) {
- $a[ $k ] = $this->{ $k };
- }
- return $a;
- }
-
-}
View
3  src/PEARX/Category.php
@@ -55,7 +55,8 @@ public function getPackages()
$package->name = $p->getElementsByTagName('n')->item(0)->nodeValue;
$package->summary = $p->getElementsByTagName('s')->item(0)->nodeValue;
$package->desc = $p->getElementsByTagName('d')->item(0)->nodeValue;
- $package->channel = $p->getElementsByTagName('c')->item(0)->nodeValue;
+ // $package->channel = $p->getElementsByTagName('c')->item(0)->nodeValue;
+ $package->channel = $this->channel;
$package->license = $p->getElementsByTagName('l')->item(0)->nodeValue;
$depsList = $node->getElementsByTagName('deps');
View
2  src/PEARX/Channel.php
@@ -90,7 +90,7 @@ public function getRestBaseUrl($version = null)
public function fetchChannelXml($host)
{
$xmlstr = null;
- $xmlstr = $this->cache ? $this->cache->get( $host ) : null;
+ $xmlstr = $this->core->cache ? $this->core->cache->get( $host ) : null;
// cache not found.
if( null !== $xmlstr )
View
16 src/PEARX/Core.php
@@ -21,13 +21,23 @@ function __construct( $options = array() )
}
}
- public function request($url)
+ public function request($url, $force = false)
{
+ if( false == $force && $content = $this->cache->get( $url ) ) {
+ if( $content )
+ return $content;
+ }
+
if( $this->downloader ) {
- return $this->downloader->fetch( $url );
+ $content = $this->downloader->fetch( $url );
}
ini_set('default_socket_timeout', 120);
- return file_get_contents($url);
+ $content = file_get_contents($url);
+
+ if( $this->cache ) {
+ $this->cache->set( $url , $content );
+ }
+ return $content;
}
View
19 src/PEARX/Package.php
@@ -11,7 +11,7 @@ class Package
public $desc;
/**
- * @var string channel
+ * @var Channel
*/
public $channel;
@@ -50,6 +50,23 @@ public function getRelease( $version )
return $this->versions[ $version ];
}
+ public function getReleaseDistUrl($version, $extension = 'tgz' )
+ {
+ // xxx: save for https or http base url from channel discover object
+ // return sprintf( 'http://%s/get/%s-%s.%s' , $this->channel, $this->name , $version , $extension );
+ return sprintf('%s/get/%s-%s.%s',$this->channel->getBaseUrl(), $this->name , $version , $extension );
+ }
+
+ public function getLastReleaseDistUrl()
+ {
+ return $this->getReleaseDistUrl( $this->latest );
+ }
+
+ public function getId()
+ {
+ return $this->name;
+ }
+
}
View
6 tests/Onion/Dependency/DependencyResolverTest.php
@@ -34,7 +34,7 @@ function test()
ok( $pkg->desc );
ok( $pkg->stability );
- ok( $pkg->getId() );
+ ok( $pkg->name );
ok( $pkg->getDependencies() );
$dr = new \Onion\Dependency\DependencyResolver;
@@ -48,9 +48,9 @@ function test()
// var_dump( $packages );
foreach( $packages as $package ) {
ok( $package );
- ok( $package->getId() );
+ ok( $package->name );
// echo get_class( $package ) . "\n";
- // echo $package->getId() . "\n";
+ // echo $package->name . "\n";
}
$installer = new \Onion\Installer( $manager );
View
30 tests/Onion/Pear/ChannelDiscoverTest.php
@@ -1,30 +0,0 @@
-<?php
-namespace Onion\Pear;
-use PHPUnit_Framework_TestCase;
-use Onion\Pear\ChannelDiscover;
-
-class ChannelDiscoverTest extends \PHPUnit_Framework_TestCase
-{
- function test()
- {
- $discover = new ChannelDiscover;
- ok( $discover );
-
- // XXX: we should also test on: components.ez.no/channel.xml
- $channel = $discover->lookup( 'pear.corneltek.com' );
- ok( $channel );
- isa_ok( '\Onion\Pear\Channel' , $channel );
-
- $packages = $channel->getAllPackages();
-
- $str = serialize( $channel );
- ok( $str );
-
- $channelNew = unserialize( $str );
- ok( $channelNew );
-
- ok( $channelNew->packages );
- }
-}
-
-
View
38 tests/Onion/Pear/ChannelParserTest.php
@@ -1,38 +0,0 @@
-<?php
-/*
- * This file is part of the {{ }} package.
- *
- * (c) Yo-An Lin <cornelius.howl@gmail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- */
-namespace tests\Onion\Pear;
-
-class ChannelParserTest extends \PHPUnit_Framework_TestCase
-{
- function test()
- {
- # $channel = new \Pyrus\ChannelFile( 'tests/data/pear2.channel.xml' );
- # var_dump( $channel );
-
- $parser = new \Onion\Pear\ChannelParser;
- ok( $parser );
-
- $files = explode(' ','tests/data/pear2.channel.xml tests/data/pear.channel.xml tests/data/pear2.channel.xml');
-
- foreach( $files as $file ) {
- $channel = $parser->parse( $file );
- ok( $channel );
- ok($channel->name);
- ok($channel->summary);
- ok($channel->alias);
- ok($channel->primary);
-
- ok( $b = $channel->getRestBaseUrl() );
- // var_dump( $b );
- }
- }
-}
-
View
1  tests/PEARX/ChannelTest.php
@@ -31,7 +31,6 @@ public function testPackageFind()
ok( $package->license );
}
-
/**
* @dataProvider getChannels
*/

No commit comments for this range

Something went wrong with that request. Please try again.