diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 2550e93d..96b53c36 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -3,10 +3,11 @@ import * as extensions from '../src/extensions'; describe('Extension tests', () => { it('checking addExtensionOnWindows', async () => { let win32: string = await extensions.addExtension( - 'Xdebug, pcov, sqlite, :intl, phalcon4, pecl_http, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2, sqlsrv-1.2.3preview1', + 'none, Xdebug, pcov, sqlite, :intl, phalcon4, pecl_http, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2, sqlsrv-1.2.3preview1', '7.4', 'win32' ); + expect(win32).toContain('Disable-AllShared'); expect(win32).toContain('Add-Extension xdebug'); expect(win32).toContain('Add-Extension pcov'); expect(win32).toContain('Add-Extension sqlite3'); @@ -72,10 +73,11 @@ describe('Extension tests', () => { it('checking addExtensionOnLinux', async () => { let linux: string = await extensions.addExtension( - 'Xdebug, pcov, sqlite, :intl, ast, ast-beta, pdo_mysql, pdo-odbc, xdebug-alpha, grpc-1.2.3', + 'none, Xdebug, pcov, sqlite, :intl, ast, ast-beta, pdo_mysql, pdo-odbc, xdebug-alpha, grpc-1.2.3', '7.4', 'linux' ); + expect(linux).toContain('disable_all_shared'); expect(linux).toContain('add_extension xdebug'); expect(linux).toContain('add_extension sqlite3'); expect(linux).toContain('disable_extension intl'); @@ -160,10 +162,11 @@ describe('Extension tests', () => { it('checking addExtensionOnDarwin', async () => { let darwin: string = await extensions.addExtension( - 'amqp, apcu, Xdebug, pcov, grpc, igbinary, imagick, imap, memcache, memcached, mongodb, msgpack, phalcon3, phalcon4, protobuf, psr, rdkafka, redis, swoole, yaml, sqlite, oci8, pdo_oci, :intl, ast-beta, grpc-1.2.3', + 'none, amqp, apcu, Xdebug, pcov, grpc, igbinary, imagick, imap, memcache, memcached, mongodb, msgpack, phalcon3, phalcon4, protobuf, psr, rdkafka, redis, swoole, yaml, sqlite, oci8, pdo_oci, :intl, ast-beta, grpc-1.2.3', '7.2', 'darwin' ); + expect(darwin).toContain('disable_all_shared'); expect(darwin).toContain('add_brew_extension amqp extension'); expect(darwin).toContain('add_brew_extension apcu extension'); expect(darwin).toContain('add_brew_extension xdebug zend_extension'); diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index 21178c9d..ecc58938 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -127,8 +127,8 @@ describe('Utils tests', () => { it('checking extensionArray', async () => { expect( - await utils.extensionArray('a, :b, php_c, php-d, Zend e, :Zend f') - ).toEqual(['a', ':b', 'c', 'd', 'e', ':f']); + await utils.extensionArray('a, :b, php_c, none, php-d, Zend e, :Zend f') + ).toEqual(['none', 'a', ':b', 'c', 'd', 'e', ':f']); expect(await utils.extensionArray('')).toEqual([]); expect(await utils.extensionArray(' ')).toEqual([]); diff --git a/dist/index.js b/dist/index.js index ee3457b1..95ac905c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -212,6 +212,9 @@ async function addExtensionDarwin(extension_csv, version) { case /^:/.test(ext_name): remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' '); return; + case /^none$/.test(ext_name): + add_script += '\ndisable_all_shared'; + return; case /.+-.+\/.+@.+/.test(extension): add_script += await utils.parseExtensionSource(extension, ext_prefix); return; @@ -258,6 +261,9 @@ async function addExtensionWindows(extension_csv, version) { case /^:/.test(ext_name): remove_script += '\nDisable-Extension' + ext_name.replace(/:/g, ' '); break; + case /^none$/.test(ext_name): + add_script += '\nDisable-AllShared'; + break; case /^(5\.[3-6]|7\.[0-4]|8\.0)blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension): case /^pdo_oci$|^oci8$|^pdo_firebird$/.test(extension): case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension): @@ -315,6 +321,9 @@ async function addExtensionLinux(extension_csv, version) { case /^:/.test(ext_name): remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' '); return; + case /^none$/.test(ext_name): + add_script += '\ndisable_all_shared'; + return; case /.+-.+\/.+@.+/.test(extension): add_script += await utils.parseExtensionSource(extension, ext_prefix); return; @@ -1041,18 +1050,20 @@ async function extensionArray(extension_csv) { case ' ': return []; default: - return extension_csv - .split(',') - .map(function (extension) { - if (/.+-.+\/.+@.+/.test(extension)) { - return extension; - } - return extension - .trim() - .toLowerCase() - .replace(/^(:)?(php[-_]|zend )/, '$1'); - }) - .filter(Boolean); + return [ + extension_csv.match(/(^|,\s?)none(\s?,|$)/) ? 'none' : '', + ...extension_csv + .split(',') + .map(function (extension) { + if (/.+-.+\/.+@.+/.test(extension)) { + return extension; + } + return extension + .trim() + .toLowerCase() + .replace(/^(:)?(php[-_]|none|zend )/, '$1'); + }) + ].filter(Boolean); } } exports.extensionArray = extensionArray; diff --git a/src/extensions.ts b/src/extensions.ts index a49910df..7f7739e3 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -23,6 +23,10 @@ export async function addExtensionDarwin( case /^:/.test(ext_name): remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' '); return; + // Match none + case /^none$/.test(ext_name): + add_script += '\ndisable_all_shared'; + return; // match extensions for compiling from source case /.+-.+\/.+@.+/.test(extension): add_script += await utils.parseExtensionSource(extension, ext_prefix); @@ -117,6 +121,10 @@ export async function addExtensionWindows( case /^:/.test(ext_name): remove_script += '\nDisable-Extension' + ext_name.replace(/:/g, ' '); break; + // Match none + case /^none$/.test(ext_name): + add_script += '\nDisable-AllShared'; + break; // match 5.3blackfire...8.0blackfire // match 5.3blackfire-(semver)...8.0blackfire-(semver) // match pdo_oci and oci8 @@ -229,6 +237,10 @@ export async function addExtensionLinux( case /^:/.test(ext_name): remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' '); return; + // Match none + case /^none$/.test(ext_name): + add_script += '\ndisable_all_shared'; + return; // match extensions for compiling from source case /.+-.+\/.+@.+/.test(extension): add_script += await utils.parseExtensionSource(extension, ext_prefix); diff --git a/src/scripts/common.sh b/src/scripts/common.sh index 57792652..6c7c38d5 100644 --- a/src/scripts/common.sh +++ b/src/scripts/common.sh @@ -183,6 +183,13 @@ disable_extension() { fi } +# Function to disable shared extensions. +disable_all_shared() { + sudo sed -i.orig -E -e "/^(zend_)?extension\s*=/d" "${ini_file[@]}" "$pecl_file" 2>/dev/null || true + sudo find "${ini_dir:-$scan_dir}"/.. -name "*.ini" -not -path "*php.ini" -not -path "*mods-available*" -delete >/dev/null 2>&1 || true + add_log "${tick:?}" "none" "Disabled all shared extensions" +} + # Function to configure PHP configure_php() { ( diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index ae22670c..e2983964 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -307,6 +307,12 @@ Function Disable-Extension() { } } +# Function to disable shared extensions. +Function Disable-AllShared() { + (Get-Content $php_dir\php.ini) | Where-Object {$_ -notmatch '^(zend_)?extension\s*='} | Set-Content $php_dir\php.ini + Add-Log $tick "none" "Disabled all shared extensions" +} + # Function to configure composer. Function Edit-ComposerConfig() { Param( diff --git a/src/utils.ts b/src/utils.ts index 9ca471a5..eb716766 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -280,18 +280,21 @@ export async function extensionArray( case ' ': return []; default: - return extension_csv - .split(',') - .map(function (extension: string) { - if (/.+-.+\/.+@.+/.test(extension)) { - return extension; - } - return extension - .trim() - .toLowerCase() - .replace(/^(:)?(php[-_]|zend )/, '$1'); - }) - .filter(Boolean); + return [ + extension_csv.match(/(^|,\s?)none(\s?,|$)/) ? 'none' : '', + ...extension_csv + .split(',') + + .map(function (extension: string) { + if (/.+-.+\/.+@.+/.test(extension)) { + return extension; + } + return extension + .trim() + .toLowerCase() + .replace(/^(:)?(php[-_]|none|zend )/, '$1'); + }) + ].filter(Boolean); } }