From dd1997caf868f8c5f28456f97dfdf1c3b1971413 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Mon, 15 Sep 2025 22:12:41 +0100 Subject: [PATCH 1/2] Add composer.json.in to ext/skeleton for PIE support --- ext/ext_skel.php | 1 + ext/skeleton/composer.json.in | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 ext/skeleton/composer.json.in diff --git a/ext/ext_skel.php b/ext/ext_skel.php index cd82abb34697a..00ac823ff1011 100755 --- a/ext/ext_skel.php +++ b/ext/ext_skel.php @@ -290,6 +290,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; diff --git a/ext/skeleton/composer.json.in b/ext/skeleton/composer.json.in new file mode 100644 index 0000000000000..24a0e278d3abb --- /dev/null +++ b/ext/skeleton/composer.json.in @@ -0,0 +1,19 @@ +{ + "name": "/%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" + } + ] + } +} From f12266bfdbb4f4a738d25f18648d7e1223728f8c Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Mon, 22 Sep 2025 20:04:20 +0100 Subject: [PATCH 2/2] Add --vendor param to ext_skel.php to provide vendor name for PIE packages --- ext/ext_skel.php | 20 ++++++++++++++++---- ext/skeleton/composer.json.in | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ext/ext_skel.php b/ext/ext_skel.php index 00ac823ff1011..d396dfa3da749 100755 --- a/ext/ext_skel.php +++ b/ext/ext_skel.php @@ -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. @@ -90,11 +90,12 @@ functions strictly needed by others. Exposed internal function must be named OPTIONS - php ext_skel.php --ext [--experimental] [--author ] - [--dir ] [--std] [--onlyunix] - [--onlywindows] [--help] + php ext_skel.php --ext --vendor [--experimental] + [--author ] [--dir ] [--std] + [--onlyunix] [--onlywindows] [--help] --ext The name of the extension defined as + --vendor 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 Your name, this is used if --std is passed and for the @@ -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, @@ -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] == '-')) { @@ -204,6 +207,8 @@ function process_args($argv, $argc) { if (empty($options['ext'])) { error('No extension name passed, use "--ext "'); + } else if (empty($options['vendor'])) { + error('No vendor name passed, use "--vendor "'); } else if (!$options['unix'] && !$options['windows']) { error('Cannot pass both --onlyunix and --onlywindows'); } else if (!is_dir($options['skel'])) { @@ -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; @@ -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); diff --git a/ext/skeleton/composer.json.in b/ext/skeleton/composer.json.in index 24a0e278d3abb..8f12bdee475ba 100644 --- a/ext/skeleton/composer.json.in +++ b/ext/skeleton/composer.json.in @@ -1,5 +1,5 @@ { - "name": "/%EXTNAME%", + "name": "%VENDORNAME%/%EXTNAME%", "type": "php-ext", "license": "BSD-3-Clause", "description": "Describe your extension here",