Permalink
Browse files

Adding support to different directory structure on PEAR package

---------------------------------------------------------------

Added structure key support to PEAR package generator. It accepts
a comma separated list as value or a simple value. This change make
package generation more flexible and not dependent on a fixed structure.
  • Loading branch information...
1 parent a991997 commit 17f9bbfed0dfa8269bfc06912d7af60bb35eae2f nsenna committed with c9s Sep 14, 2012
View
@@ -1,3 +1,4 @@
.onion
vendor
tests/tmp
+.idea/
@@ -27,8 +27,8 @@ class Package implements PackageInterface
public $license;
public $licenseUri;
- /**
- * main stability
+ /**
+ * main stability
*/
public $stability;
@@ -57,8 +57,8 @@ class Package implements PackageInterface
*/
public $deps = array();
- /**
- * ConfigContainer object
+ /**
+ * @var \Onion\ConfigContainer
*/
public $config;
@@ -69,15 +69,20 @@ class Package implements PackageInterface
public function getDefaultStructureConfig()
{
- // directory structure
- return array(
- 'doc' => array('doc', 'docs','examples'),
- 'test' => (array) 'tests',
- 'php' => (array) 'src',
- // xxx: better config for roles
- // 'script' => (array) 'bin',
- 'data' => (array) 'data',
- );
+ $configuredStructure = $this->config->get('structure');
+
+ if (empty($configuredStructure)) {
+ return array(
+ 'doc' => array('doc', 'docs','examples'),
+ 'test' => (array) 'tests',
+ 'php' => (array) 'src',
+ // xxx: better config for roles
+ // 'script' => (array) 'bin',
+ 'data' => (array) 'data',
+ );
+ }
+
+ return $configuredStructure;
}
@@ -37,8 +37,8 @@
* $pkgxml->generate('package.xml');
*
*/
-class PackageConfigReader
- implements LoggableInterface
+class PackageConfigReader
+ implements LoggableInterface
{
public $config;
@@ -76,7 +76,7 @@ function read($file)
$ini = null;
try {
- $ini = parse_ini_file( $file , true );
+ $ini = $this->parseFile($file);
}
catch( Exception $e ) {
throw new Exception( "Package.ini: $file syntax error: " . $e->getMessage() );
@@ -166,29 +166,29 @@ function read($file)
$requires = $config->get('require');
if( ! $requires ) {
- // use default core dependency
+ // use default core dependency
$logger->info2("* required section is not defined. use php 5.3 and pearinstaller 1.4 by default.",1);
$pkginfo->deps[] = array(
'type' => 'core',
'name' => 'php',
'version' => array( 'min' => '5.3' ),
);
- $pkginfo->deps[] = array(
+ $pkginfo->deps[] = array(
'type' => 'core',
'name' => 'pearinstaller',
'version' => array( 'min' => '1.4' ),
);
}
if( $requires ) {
- foreach( $requires as $key => $value )
+ foreach( $requires as $key => $value )
{
$type = $this->detectDependencyType( $key , $value );
switch($type) {
case 'core':
$version = SpecUtils::parseVersion( $value );
- $pkginfo->deps[] = array(
+ $pkginfo->deps[] = array(
'type' => 'core',
'name' => $key,
'version' => $version, /* [ min => , max => ] */
@@ -242,7 +242,7 @@ function detectDependencyType($key,$value = null)
elseif( preg_match('/^ext(?:ension)?\/\w+/',$key) ) {
return 'extension';
- }
+ }
// todo: check if there is a resource for this.
else {
// otherwisze it's a package
@@ -257,15 +257,15 @@ function detectDependencyType($key,$value = null)
function parseDependency($key,$value)
{
// format: {channel host}/{package name} = {version expression}
- if( preg_match('/^([a-zA-Z0-9.-]+)\/(\w+)$/' , $key , $regs ) )
+ if( preg_match('/^([a-zA-Z0-9.-]+)\/(\w+)$/' , $key , $regs ) )
{
if( $value != 'conflict' )
{
return array(
'type' => 'pear',
'name' => $regs[2],
'version' => SpecUtils::parseVersion($value),
- 'resource' => array(
+ 'resource' => array(
'type' => 'channel',
'channel' => $regs[1],
)
@@ -276,7 +276,7 @@ function parseDependency($key,$value)
'type' => 'pear',
'name' => $regs[2],
'conflict' => 1,
- 'resource' => array(
+ 'resource' => array(
'type' => 'channel',
'channel' => $regs[1],
)
@@ -291,7 +291,7 @@ function parseDependency($key,$value)
'version' => SpecUtils::parseVersion($value),
);
}
- elseif( preg_match('/^(\w+)$/',$key,$regs) )
+ elseif( preg_match('/^(\w+)$/',$key,$regs) )
{
// PEAR package with URI format
if( preg_match('/^https?:\/\//',$value) ) {
@@ -317,6 +317,32 @@ public function getResources()
{
}
+ private function parseFile($file)
+ {
+ $ini = parse_ini_file($file, true);
+ if (isset($ini['structure'])) {
+ $ini['structure'] = $this->parseCommaSeparatedListValue($ini['structure']);
+ }
+
+ return $ini;
+ }
+
+ private function parseCommaSeparatedListValue(array $entry)
+ {
+ foreach ($entry as $key => $value) {
+ if (false !== strpos($value, ',')) {
+ $list = explode(',', $value);
+ foreach ($list as $item) {
+ $parsedStructure[$key][] = trim($item);
+ }
+ } else {
+ $parsedStructure[$key][] = $value;
+ }
+ }
+
+ return $parsedStructure;
+ }
+
}
@@ -0,0 +1,34 @@
+<?php
+
+namespace tests\Onion\Package;
+
+class PackageTest extends \PHPUnit_Framework_TestCase
+{
+ public function testShouldUseIniFileConfiguredDirectoryStructure()
+ {
+ $logger = new \CLIFramework\Logger();
+ $logger->quiet();
+ $config = new \Onion\PackageConfigReader();
+ $config->setLogger($logger);
+
+ $package = $config->read(__DIR__ . '/fixtures/stub.ini');
+
+ $fileStructure = $package->getDefaultStructureConfig();
+
+ $this->assertEquals(array('lib'), $fileStructure['php']);
+ }
+
+ public function testShouldUseDefaultDirectoryStructure()
+ {
+ $logger = new \CLIFramework\Logger();
+ $logger->quiet();
+ $config = new \Onion\PackageConfigReader();
+ $config->setLogger($logger);
+
+ $package = $config->read(__DIR__ . '/fixtures/stub_with_no_structure.ini');
+
+ $fileStructure = $package->getDefaultStructureConfig();
+
+ $this->assertEquals(array('src'), $fileStructure['php']);
+ }
+}
@@ -0,0 +1,72 @@
+[package]
+name = Onion
+summary = A Simple PHP Packager Builder.
+desc = "Onion, The fast approch to make packages for PHP. Onion is
+ able to generate a PEAR-compatible package.xml file from a very simple config file."
+version = 0.0.8
+stability = alpha
+
+; homepage = http://php-onion.org ; optional
+; license = PHP ; optional, default to PHP
+; version.api = 0.0.1 ; optional, defualt to "version"
+; author = Yo-An Lin <cornelius.howl@gmail.com> # also works
+author = Yo-An Lin <cornelius.howl@gmail.com>
+authors[] = Yo-An Lin <cornelius.howl@gmail.com>
+channel = pear.corneltek.com
+
+[require]
+php = 5.3
+pearinstaller = 1.4.1
+
+; packages
+pear.corneltek.com/GetOptionKit = 0.0.2
+pear.corneltek.com/CLIFramework = 0.0.2
+pear.corneltek.com/Universal = 0.0.2
+pear.symfony-project.com/YAML = 0.0.0
+; pear.phpunit.de/PHPUnit = 0.0.0
+
+; extensions
+; extension/reflection = 0
+; extension/ctype = 0
+extension/pcre = 0
+
+
+[require CLIFramework]
+git = http://github.com/c9s/CLIFramework
+type = pear
+
+[require Asset]
+git = https://github.com/kriswallsmith/assetic.git
+; autoload = (
+; Assetic: src
+; )
+
+[require Smarty]
+url = http://www.smarty.net/files/Smarty-3.1.8.tar.gz
+bootstrap = path/to/init.php
+
+[resource phpan]
+type = pub
+host = pubphp.org
+
+[resource openpear]
+type = pear
+host = openpear.org
+
+[resource corneltek]
+type = pear
+host = pear.corneltek.com
+
+[roles]
+onion.phar = script
+changes.* = doc
+*.md = doc
+
+[repository]
+git = git://github.com/c9s/Onion.git
+
+[structure]
+doc = doc, docs, examples
+test = tests
+php = lib
+data = data
@@ -0,0 +1,66 @@
+[package]
+name = Onion
+summary = A Simple PHP Packager Builder.
+desc = "Onion, The fast approch to make packages for PHP. Onion is
+ able to generate a PEAR-compatible package.xml file from a very simple config file."
+version = 0.0.8
+stability = alpha
+
+; homepage = http://php-onion.org ; optional
+; license = PHP ; optional, default to PHP
+; version.api = 0.0.1 ; optional, defualt to "version"
+; author = Yo-An Lin <cornelius.howl@gmail.com> # also works
+author = Yo-An Lin <cornelius.howl@gmail.com>
+authors[] = Yo-An Lin <cornelius.howl@gmail.com>
+channel = pear.corneltek.com
+
+[require]
+php = 5.3
+pearinstaller = 1.4.1
+
+; packages
+pear.corneltek.com/GetOptionKit = 0.0.2
+pear.corneltek.com/CLIFramework = 0.0.2
+pear.corneltek.com/Universal = 0.0.2
+pear.symfony-project.com/YAML = 0.0.0
+; pear.phpunit.de/PHPUnit = 0.0.0
+
+; extensions
+; extension/reflection = 0
+; extension/ctype = 0
+extension/pcre = 0
+
+
+[require CLIFramework]
+git = http://github.com/c9s/CLIFramework
+type = pear
+
+[require Asset]
+git = https://github.com/kriswallsmith/assetic.git
+; autoload = (
+; Assetic: src
+; )
+
+[require Smarty]
+url = http://www.smarty.net/files/Smarty-3.1.8.tar.gz
+bootstrap = path/to/init.php
+
+[resource phpan]
+type = pub
+host = pubphp.org
+
+[resource openpear]
+type = pear
+host = openpear.org
+
+[resource corneltek]
+type = pear
+host = pear.corneltek.com
+
+[roles]
+onion.phar = script
+changes.* = doc
+*.md = doc
+
+[repository]
+git = git://github.com/c9s/Onion.git
Oops, something went wrong.

0 comments on commit 17f9bbf

Please sign in to comment.