Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
nsenna committed Sep 14, 2012
commit 68b43015f9683ecb8bf8a53e23367ce43a74e0da
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.onion
vendor
tests/tmp
.idea/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write your idea in doc/plans (and expand it as a plan later) ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a folder of project configuration created by PhpStorm so the next developer do not need to have it :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool~ thanks ;-)

2012/9/17 Nelson Senna do Amaral [email protected]

In .gitignore:

@@ -1,3 +1,4 @@
.onion
vendor
tests/tmp
+.idea/

This is a folder of project configuration created by PhpStorm so the next
developer do not need to have it :-)


Reply to this email directly or view it on GitHubhttps://github.com//pull/35/files#r1614843.

Best Regards,

Yo-An Lin

31 changes: 18 additions & 13 deletions src/Onion/Package/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Package implements PackageInterface
public $license;
public $licenseUri;

/**
* main stability
/**
* main stability
*/
public $stability;

Expand Down Expand Up @@ -57,8 +57,8 @@ class Package implements PackageInterface
*/
public $deps = array();

/**
* ConfigContainer object
/**
* @var \Onion\ConfigContainer
*/
public $config;

Expand All @@ -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;
}


Expand Down
50 changes: 38 additions & 12 deletions src/Onion/PackageConfigReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
* $pkgxml->generate('package.xml');
*
*/
class PackageConfigReader
implements LoggableInterface
class PackageConfigReader
implements LoggableInterface
{
public $config;

Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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 => ] */
Expand Down Expand Up @@ -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
Expand All @@ -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],
)
Expand All @@ -276,7 +276,7 @@ function parseDependency($key,$value)
'type' => 'pear',
'name' => $regs[2],
'conflict' => 1,
'resource' => array(
'resource' => array(
'type' => 'channel',
'channel' => $regs[1],
)
Expand All @@ -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) ) {
Expand All @@ -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;
}

}


Expand Down
34 changes: 34 additions & 0 deletions tests/Onion/Package/PackageTest.php
Original file line number Diff line number Diff line change
@@ -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']);
}
}
72 changes: 72 additions & 0 deletions tests/Onion/Package/fixtures/stub.ini
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> # also works
author = Yo-An Lin <[email protected]>
authors[] = Yo-An Lin <[email protected]>
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
66 changes: 66 additions & 0 deletions tests/Onion/Package/fixtures/stub_with_no_structure.ini
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> # also works
author = Yo-An Lin <[email protected]>
authors[] = Yo-An Lin <[email protected]>
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
Loading