Skip to content

Commit

Permalink
Merge pull request pyrus#5 from till/master
Browse files Browse the repository at this point in the history
pear2skeleton refactoring and basic test coverage
  • Loading branch information
saltybeagle committed Jul 14, 2011
2 parents 035f5c9 + b8dcfdf commit 87abc45
Show file tree
Hide file tree
Showing 8 changed files with 468 additions and 159 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/autoload.php
/Pyrus_Developer-*.*
*.komodoproject
tests/*package-test*
vendor*
199 changes: 40 additions & 159 deletions src/Pyrus/Developer/PackageFile/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,175 +432,56 @@ function runTests($frontend, $args, $options)
}
}

function pear2Skeleton($frontend, $args, $options)
/**
* Create the PEAR2 skeleton
*
* @param mixed $frontend \Pyrus\ScriptFrontend\Commands
* @param array $args
* @param array $options
*
* @return void
*
* @uses Pyrus\Developer\PackageFile\Commands\PEAR2Skeleton
* @uses self::makePackageXml()
*/
public function pear2Skeleton($frontend, array $args, array $options)
{
if (!isset($args['channel'])) {
$args['channel'] = 'pear2.php.net';
}
$info = $this->parsePackageName($args['package'], $args['channel']);

if (file_exists($info['path'])) {
throw new \Pyrus\Developer\Creator\Exception('Path ' . $info['path'] .
' already exists');
}
mkdir($info['path']);
chdir($info['path']);

mkdir('src');
mkdir('src/' . $info['mainPath'], 0777, true);
file_put_contents('src/' . $info['mainPath'] . '/Main.php', '<?php
/**
* ' . $info['mainClass'] . '
*
* PHP version 5
*
* @category Yourcategory
* @package ' . $info['package'] . '
* @author Your Name <[email protected]>
* @copyright ' . date('Y') . ' Your Name
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version SVN: $Id$
* @link ' . $info['svn'] . '
*/
/**
* Main class for ' . $info['package'] . '
*
* @category Yourcategory
* @package ' . $info['package'] . '
* @author Your Name <[email protected]>
* @copyright ' . date('Y') . ' Your Name
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @link ' . $info['svn'] . '
*/
namespace ' . $info['mainNamespace'] . ';
class Main
{
}
');
mkdir('data');
// mkdir('customcommand');
// mkdir('customrole');
// mkdir('customtask');
mkdir('tests');
mkdir('docs');
mkdir('examples');
mkdir('www');
file_put_contents('README', 'Package ' . $info['package'] . " summary.\n" .
"\n" .
"Package detailed description here (found in README)");
file_put_contents('CREDITS', ";; put your info here\n" .
'Your Name [handle] <[email protected]> (lead)');
file_put_contents('RELEASE-0.1.0', 'Package ' . $info['package'] . " release notes for version 0.1.0.");
file_put_contents('API-0.1.0', 'Package ' . $info['package'] . " API release notes for version 0.1.0.");
file_put_contents('extrasetup.php', "<?php
/**
* This file is used to provide extra files/packages outside package.xml
* More information: http://pear.php.net/manual/en/pyrus.commands.package.php#pyrus.commands.package.extrasetup
*/
\$extrafiles = array();

/**
* for example:
if (basename(__DIR__) == 'trunk') {
\$extrafiles = array(
new \Pyrus\Package(__DIR__ . '/../../HTTP_Request/trunk/package.xml'),
new \Pyrus\Package(__DIR__ . '/../../sandbox/Console_CommandLine/trunk/package.xml'),
new \Pyrus\Package(__DIR__ . '/../../MultiErrors/trunk/package.xml'),
new \Pyrus\Package(__DIR__ . '/../../Exception/trunk/package.xml'),
);
} else {
\$extrafiles = array(
new \Pyrus\Package(__DIR__ . '/../HTTP_Request/package.xml'),
new \Pyrus\Package(__DIR__ . '/../sandbox/Console_CommandLine/package.xml'),
new \Pyrus\Package(__DIR__ . '/../MultiErrors/package.xml'),
new \Pyrus\Package(__DIR__ . '/../Exception/package.xml'),
);
}
*/
");
file_put_contents('packagexmlsetup.php', "<?php
/**
* Extra package.xml settings such as dependencies.
* More information: http://pear.php.net/manual/en/pyrus.commands.make.php#pyrus.commands.make.packagexmlsetup
*/
/**
* for example:
\$package->dependencies['required']->package['pear2.php.net/PEAR2_Autoload']->save();
\$package->dependencies['required']->package['pear2.php.net/PEAR2_Exception']->save();
\$package->dependencies['required']->package['pear2.php.net/PEAR2_MultiErrors']->save();
\$package->dependencies['required']->package['pear2.php.net/PEAR2_HTTP_Request']->save();
\$compatible->dependencies['required']->package['pear2.php.net/PEAR2_Autoload']->save();
\$compatible->dependencies['required']->package['pear2.php.net/PEAR2_Exception']->save();
\$compatible->dependencies['required']->package['pear2.php.net/PEAR2_MultiErrors']->save();
\$compatible->dependencies['required']->package['pear2.php.net/PEAR2_HTTP_Request']->save();
// ignore files
unset(\$package->files['www/config.inc.php']);
unset(\$package->files['www/.htaccess']);
*/
?>
");
file_put_contents('stub.php', "#!/usr/bin/env php
<?php
/**
* If your package does special stuff in phar format, use this file. Remove if
* no phar format is ever generated
* More information: http://pear.php.net/manual/en/pyrus.commands.package.php#pyrus.commands.package.stub
*/
if (version_compare(phpversion(), '5.3.1', '<')) {
if (substr(phpversion(), 0, 5) != '5.3.1') {
// this small hack is because of running RCs of 5.3.1
echo \"" . $info['package'] . " requires PHP 5.3.1 or newer.\n\";
exit -1;
}
}
foreach (array('phar', 'spl', 'pcre', 'simplexml') as \$ext) {
if (!extension_loaded(\$ext)) {
echo 'Extension ', \$ext, \" is required\n\";
exit -1;
}
}
try {
Phar::mapPhar();
} catch (Exception \$e) {
echo \"Cannot process " . $info['package'] . " phar:\n\";
echo \$e->getMessage(), \"\n\";
exit -1;
}
function " . $info['package'] . "_autoload(\$class)
{
\$class = str_replace(array('_', '\\\'), '/', \$class);
if (file_exists('phar://' . __FILE__ . '/" . $info['package'] . "-@PACKAGE_VERSION@/php/' . \$class . '.php')) {
include 'phar://' . __FILE__ . '/" . $info['package'] . "-@PACKAGE_VERSION@/php/' . \$class . '.php';
}
}
spl_autoload_register(\"" . $info['package'] . "_autoload\");
\$phar = new Phar(__FILE__);
\$sig = \$phar->getSignature();
define('" . $info['package'] . "_SIG', \$sig['hash']);
define('" . $info['package'] . "_SIGTYPE', \$sig['hash_type']);
// your package-specific stuff here, for instance, here is what Pyrus does:
/**
* \$frontend = new \Pyrus\ScriptFrontend\Commands;
* @array_shift(\$_SERVER['argv']);
* \$frontend->run(\$_SERVER['argv']);
*/
__HALT_COMPILER();
");
$info = $this->parsePackageName($args['package'], $args['channel']);

$options['stub'] = 'stub.php';
$options['extrasetup'] = 'extrasetup.php';
$options['packagexmlsetup'] = 'packagexmlsetup.php';
$skeleton = new Commands\PEAR2Skeleton($info);
$skeleton->generate();

$options['stub'] = $skeleton->getStub();
$options['extrasetup'] = $skeleton->getExtraSetup();
$options['packagexmlsetup'] = $skeleton->getPackageXmlSetup();
$options['package'] = false;
$options['nocompatible'] = false;
$this->makePackageXml($frontend, array('packagename' => $info['package'], 'channel' => $args['channel']),
$options);

$this->makePackageXml(
$frontend,
array('packagename' => $info['package'], 'channel' => $args['channel']),
$options
);
}

/**
* Returns an array with:
* - path
* - mainNamespace
* - mainClass
* - mainPath
* - svn
*
* @param string $package E.g. PEAR2_Foo_Bar
* @param string $channel E.g. pear2.php.net
*
* @return array
* @see \Pyrus\Developer\PackageFile\Commands\PEAR2Skeleton
*/
protected function parsePackageName($package, $channel)
{
$ret = array();
Expand Down
Loading

0 comments on commit 87abc45

Please sign in to comment.