Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 17 additions & 4 deletions ext/ext_skel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function print_help() {
Very simple. First, change to the ext/ directory of the PHP sources. Then run
the following

php ext_skel.php --ext extension_name
php ext_skel.php --ext extension_name --vendor vendor_name

and everything you need will be placed in directory ext/extension_name.

Expand Down Expand Up @@ -90,11 +90,12 @@ functions strictly needed by others. Exposed internal function must be named

OPTIONS

php ext_skel.php --ext <name> [--experimental] [--author <name>]
[--dir <path>] [--std] [--onlyunix]
[--onlywindows] [--help]
php ext_skel.php --ext <name> --vendor <name> [--experimental]
[--author <name>] [--dir <path>] [--std]
[--onlyunix] [--onlywindows] [--help]

--ext <name> The name of the extension defined as <name>
--vendor <name> The vendor of the extension for Packagist
--experimental Passed if this extension is experimental, this creates
the EXPERIMENTAL file in the root of the extension
--author <name> Your name, this is used if --std is passed and for the
Expand Down Expand Up @@ -147,6 +148,7 @@ function process_args($argv, $argc) {
'unix' => true,
'windows' => true,
'ext' => '',
'vendor' => '',
'dir' => __DIR__ . DIRECTORY_SEPARATOR,
'skel' => __DIR__ . DIRECTORY_SEPARATOR . 'skeleton' . DIRECTORY_SEPARATOR,
'author' => false,
Expand Down Expand Up @@ -185,6 +187,7 @@ function process_args($argv, $argc) {
}
break;
case 'ext':
case 'vendor':
case 'dir':
case 'author': {
if (!isset($argv[$i + 1]) || ($argv[$i + 1][0] == '-' && $argv[$i + 1][1] == '-')) {
Expand All @@ -204,6 +207,8 @@ function process_args($argv, $argc) {

if (empty($options['ext'])) {
error('No extension name passed, use "--ext <name>"');
} else if (empty($options['vendor'])) {
error('No vendor name passed, use "--vendor <name>"');
} else if (!$options['unix'] && !$options['windows']) {
error('Cannot pass both --onlyunix and --onlywindows');
} else if (!is_dir($options['skel'])) {
Expand All @@ -217,6 +222,12 @@ function process_args($argv, $argc) {
.' Using only lower case letters is preferred.');
}

// Validate vendor
if (!preg_match('/^[a-z][a-z0-9_-]+$/i', $options['vendor'])) {
error('Invalid vendor name. Valid names start with a letter,'
.' followed by any number of letters, numbers, hypens, or underscores.');
}

$options['ext'] = str_replace(['\\', '/'], '', strtolower($options['ext']));

return $options;
Expand All @@ -231,6 +242,7 @@ function process_source_tags($file, $short_name) {
error('Unable to open file for reading: ' . $short_name);
}

$source = str_replace('%VENDORNAME%', $options['vendor'], $source);
$source = str_replace('%EXTNAME%', $options['ext'], $source);
$source = str_replace('%EXTNAMECAPS%', strtoupper($options['ext']), $source);

Expand Down Expand Up @@ -290,6 +302,7 @@ function copy_config_scripts() {
}

$files[] = '.gitignore';
$files[] = 'composer.json';

foreach($files as $config_script) {
$new_config_script = $options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . $config_script;
Expand Down
19 changes: 19 additions & 0 deletions ext/skeleton/composer.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "%VENDORNAME%/%EXTNAME%",
"type": "php-ext",
"license": "BSD-3-Clause",
"description": "Describe your extension here",
"require": {
"php": "^8.3"
},
"php-ext": {
"extension-name": "%EXTNAME%",
"configure-options": [
{
"name": "enable-%EXTNAME%",
"needs-value": false,
"description": "whether to enable %EXTNAME% support"
}
]
}
}