Skip to content

Commit

Permalink
Add support for phalcon on windows #128
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Dec 23, 2019
1 parent 935e74f commit cb28730
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
6 changes: 4 additions & 2 deletions __tests__/extensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ import * as extensions from '../src/extensions';
describe('Extension tests', () => {
it('checking addExtensionOnWindows', async () => {
let win32: string = await extensions.addExtension(
'xdebug, pcov, redis',
'xdebug, pcov, redis, phalcon4',
'7.4',
'win32'
);
expect(win32).toContain('Add-Extension xdebug');
expect(win32).toContain('Add-Extension pcov');
expect(win32).toContain('Add-Extension redis beta');
expect(win32).toContain('Add-Phalcon phalcon4');

win32 = await extensions.addExtension(
'does_not_exist',
'phalcon3, does_not_exist',
'7.2',
'win32',
true
);
expect(win32).toContain('Add-Phalcon phalcon3');
expect(win32).toContain('Add-Extension does_not_exist');

win32 = await extensions.addExtension('xdebug', '7.2', 'fedora');
Expand Down
7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2231,10 +2231,13 @@ function addExtensionWindows(extension_csv, version) {
yield utils.asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () {
// add script to enable extension is already installed along with php
switch (version + extension) {
case '7.4redis':
switch (true) {
case /^7\.4redis$/.test(version + extension):
script += '\nAdd-Extension ' + extension + ' beta';
break;
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension):
script += '\nAdd-Phalcon ' + extension;
break;
default:
script += '\nAdd-Extension ' + extension;
break;
Expand Down
7 changes: 5 additions & 2 deletions src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ export async function addExtensionWindows(
let script = '\n';
await utils.asyncForEach(extensions, async function(extension: string) {
// add script to enable extension is already installed along with php
switch (version + extension) {
case '7.4redis':
switch (true) {
case /^7\.4redis$/.test(version + extension):
script += '\nAdd-Extension ' + extension + ' beta';
break;
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension):
script += '\nAdd-Phalcon ' + extension;
break;
default:
script += '\nAdd-Extension ' + extension;
break;
Expand Down
21 changes: 21 additions & 0 deletions src/scripts/win32.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ if ($version -eq 'master') {
Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir
}

Function Add-Phalcon {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateSet('phalcon3', 'phalcon4')]
[string]
$extension
)
Install-Phpextension psr
$extension_version = $extension.substring($extension.Length - 1)
$domain_uri = "https://github.com"
$uri = Invoke-WebRequest -UseBasicParsing -Uri $domain_uri/phalcon/cphalcon/releases | `
Select-String -Pattern "href=`"(.*phalcon_${arch}_.*_php${version}_${extension_version}.*[0-9].zip)`"" | `
ForEach-Object { $_.matches.groups[1].value } | `
Select-Object -Index 0
Invoke-WebRequest -UseBasicParsing -Uri $domain_uri/$uri -OutFile $ENV:TEMP\phalcon.zip
Expand-Archive -Path $ENV:TEMP\phalcon.zip -DestinationPath $ENV:TEMP\phalcon -Force
Copy-Item -Path $ENV:TEMP\phalcon\php_phalcon.dll -Destination $ext_dir
Enable-Phpextension phalcon
}

Function Add-Extension {
Param (
[Parameter(Position = 0, Mandatory = $true)]
Expand Down

0 comments on commit cb28730

Please sign in to comment.