forked from mevdschee/php-crud-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
// download composer and install dependencies | ||
|
||
if (!file_exists('composer.phar')) { | ||
$composer = file_get_contents('https://getcomposer.org/composer.phar'); | ||
file_put_contents('composer.phar', $composer); | ||
} | ||
exec('php composer.phar install'); | ||
|
||
include 'patch.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
// patch files for PHP 7.0 compatibility | ||
|
||
function patchDir(string $base, string $dir): int | ||
{ | ||
$count = 0; | ||
$entries = scandir($dir); | ||
foreach ($entries as $entry) { | ||
if ($entry === '.' || $entry === '..') { | ||
continue; | ||
} | ||
$filename = "$base/$dir/$entry"; | ||
if (is_dir($filename)) { | ||
$count += patchDir($base, "$dir/$entry"); | ||
} | ||
} | ||
foreach ($entries as $entry) { | ||
$filename = "$base/$dir/$entry"; | ||
if (is_file($filename)) { | ||
if (substr($entry, -4) != '.php') { | ||
continue; | ||
} | ||
$patched = $original = file_get_contents($filename); | ||
$patched = preg_replace('/\):\s*(\?[a-zA-Z]+|void)\s*\n/', ") /*:$1*/\n", $patched); | ||
$patched = preg_replace('/(private|public|protected) const/', "/*$1*/ const", $patched); | ||
if ($patched && $patched != $original) { | ||
file_put_contents($filename, $patched); | ||
$count++; | ||
} | ||
} | ||
} | ||
return $count; | ||
} | ||
|
||
function patch(string $base, array $dirs) | ||
{ | ||
$start = microtime(true); | ||
$count = 0; | ||
foreach ($dirs as $dir) { | ||
$count += patchDir($base, $dir); | ||
} | ||
$end = microtime(true); | ||
$time = ($end - $start) * 1000; | ||
if ($count) { | ||
fwrite(STDERR, sprintf("%d files patched in %d ms\n", $count, $time)); | ||
} | ||
} | ||
|
||
patch(__DIR__, ['vendor']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters