testify/tools/productize.php

156 lines
3.6 KiB
PHP
Raw Permalink Normal View History

2009-06-14 00:18:46 +00:00
<?php
require_once 'cli.php';
/**
* Prints usage
*/
function usage() {
$usage = new Usage(
'Productizer 1.0',
2009-06-18 07:25:42 +00:00
'php ' . basename(__FIlE__),
2009-06-14 00:18:46 +00:00
'Creates the equivalent of C#.NET\'s "AssemblyInfo.cs"',
'Tommy Montgomery',
'2009'
);
global $switches;
$usage->setSwitches($switches);
echo $usage;
}
global $switches;
$switches = new CliSwitchCollection();
$switches->addSwitch(new CliSwitch('name', 'n', true, 'name', 'Product name'))
->addSwitch(new CliSwitch('version', 'v', true, 'version_number', 'Product version'))
->addSwitch(new CliSwitch('author', 'a', true, 'author_name', 'Product author'))
->addSwitch(new CliSwitch('website', 'w', true, 'url', 'Product website'))
->addSwitch(new CliSwitch('ezc', 'e', true, 'version', 'ezComponents version number'))
2009-06-14 00:18:46 +00:00
->addSwitch(new CliSwitch('package', 'p', true, 'package_name ', 'Name of the package for use in @package tag'))
->addSwitch(new CliSwitch('doc-version', 'd', false, 'version_number', 'Version number for use in @version tag'))
->addSwitch(new CliSwitch('output', 'o', false, 'file|dir', 'The file/directory to write the generated class to; default is stdout'));
array_shift($argv);
$args = Cli::parseArgs($argv, $switches);
$args = $args['switches'];
if (!isset($args['name'], $args['version'], $args['author'], $args['website'])) {
usage();
fwrite(STDERR, 'name, version, author, website and package are required');
exit(1);
}
$self = basename(__FILE__);
$datetime = date('Y-m-d H:i:s');
$args['name'] = addslashes($args['name']);
$args['version'] = addslashes($args['version']);
$args['author'] = addslashes($args['author']);
$args['website'] = addslashes($args['website']);
$code = <<<ENDCODE
<?php
/**
* Product
*
* @package $args[package]
2009-06-28 01:04:27 +00:00
* @since 1.0
* @version $args[version]
2009-06-14 00:18:46 +00:00
*/
/**
* Product meta information
*
* This class was auto-generated by $self on $datetime.
*
* @package $args[package]
2009-06-28 01:04:27 +00:00
* @since 1.0
* @version $args[version]
*/
2009-06-14 00:18:46 +00:00
final class Product {
/**#@+
* @var string
*/
/**
* Product name
*/
const NAME = '$args[name]';
2009-06-14 00:18:46 +00:00
/**
* Product version
*/
const VERSION = '$args[version]';
2009-06-14 00:18:46 +00:00
/**
* Product author
*/
const AUTHOR = '$args[author]';
2009-06-14 00:18:46 +00:00
/**
* Product website
*/
const WEBSITE = '$args[website]';
2009-06-14 00:18:46 +00:00
/**
* Product build date
*/
const DATE = '$datetime';
/**
* ezComponents version
*/
const EZC_VERSION = '$args[ezc]';
2009-06-14 00:18:46 +00:00
/**#@-*/
2009-06-20 03:54:48 +00:00
/**
* @ignore
*/
2009-06-14 00:18:46 +00:00
private function __construct() {}
2009-06-20 03:54:48 +00:00
/**
* Gets a human-readable version string
*
2009-06-28 01:04:27 +00:00
* @author Autogenerated by $self
* @since 1.0
* @version $args[version]
*
2009-06-20 03:54:48 +00:00
* @return string
*/
public static function getVersionString() {
return self::NAME . ' ' . self::VERSION . ' (' . self::DATE . ')';
}
2009-06-14 00:18:46 +00:00
}
?>
ENDCODE;
if (isset($args['output']) && !is_dir(dirname($args['output'])) && !mkdir(dirname($args['output']), 0777, true)) {
fwrite(STDERR, 'Unable to mkdir(): ' . dirname($args['output']));
exit(1);
} else if (!isset($args['output'])) {
$args['output'] = 'php://stdout';
}
if (is_dir($args['output'])) {
$args['output'] .= DIRECTORY_SEPARATOR . 'Product.php';
}
$fp = fopen($args['output'], 'w');
if (!$fp) {
fwrite(STDERR, 'Unable to open ' . $args['output'] . ' for writing');
exit(1);
}
fwrite($fp, $code);
fclose($fp);
echo 'Wrote data to ' . $args['output'] . ' (' . strlen($code) . ' bytes)' . "\n";
exit(0);
?>