-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: MarioRadu <[email protected]>
- Loading branch information
Showing
3 changed files
with
107 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
Check warning on line 1 in bin/composer-post-install-script.php GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-ac...
|
||
|
||
declare(strict_types=1); | ||
|
||
function copyFile(string $source, string $destination): void | ||
{ | ||
if (! copy($source, $destination)) { | ||
echo "Could not copy $source to $destination." . PHP_EOL; | ||
exit(1); | ||
} | ||
} | ||
|
||
function validateInput(array $options, string $projectRoot): array | ||
{ | ||
$sourceFile = $options['sourceFile'] ?? null; | ||
$destinationDirectory = $options['destinationDirectory'] ?? null; | ||
|
||
$sourceFilePath = realpath($projectRoot . DIRECTORY_SEPARATOR . $sourceFile); | ||
if (! $sourceFilePath || ! file_exists($sourceFilePath)) { | ||
echo "Error: Source file $sourceFile does not exist." . PHP_EOL; | ||
exit(1); | ||
} | ||
|
||
$destDirectoryPath = realpath($projectRoot . DIRECTORY_SEPARATOR . $destinationDirectory); | ||
if (! $destDirectoryPath || ! is_dir($destDirectoryPath) || ! is_writable($destDirectoryPath)) { | ||
echo "Error: Destination directory $destinationDirectory does not exist or is not writable." . PHP_EOL; | ||
exit(1); | ||
} | ||
|
||
return [$sourceFilePath, $destDirectoryPath]; | ||
} | ||
|
||
$projectRoot = realpath(__DIR__ . '/..'); | ||
$options = getopt("", ["sourceFile:", "destinationDirectory:"]); | ||
|
||
[$sourceFilePath, $destinationDirectoryPath] = validateInput($options, $projectRoot); | ||
|
||
$sourceFileName = basename($sourceFilePath); | ||
$destinationFilePath = $destinationDirectoryPath . DIRECTORY_SEPARATOR . $sourceFileName; | ||
$destinationFileWithoutDist = str_replace('.dist', '', $destinationFilePath); | ||
|
||
if (! file_exists($destinationFileWithoutDist)) { | ||
copyFile($sourceFilePath, $destinationFileWithoutDist); | ||
echo "Files copied successfully from {$options['sourceFile']} to {$options['destinationDirectory']}." . PHP_EOL; | ||
} | ||
|
||
exit(0); |
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,60 @@ | ||
<?php | ||
Check warning on line 1 in bin/composer-post-package-install-script.php GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-ac...
|
||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use Composer\InstalledVersions; | ||
|
||
const VENDOR_DIR = 'vendor'; | ||
|
||
function copyFile(string $source, string $destination): void | ||
{ | ||
if (! copy($source, $destination)) { | ||
echo "Could not copy $source to $destination." . PHP_EOL; | ||
exit(1); | ||
} | ||
} | ||
|
||
function validateInput(array $options, string $projectRoot): array | ||
{ | ||
$package = $options['package'] ?? null; | ||
$sourceFile = $options['sourceFile'] ?? null; | ||
$destinationDirectory = $options['destinationDirectory'] ?? null; | ||
|
||
if (empty($package) || ! InstalledVersions::isInstalled($package)) { | ||
echo "Error: Package $package is not installed." . PHP_EOL; | ||
exit(1); | ||
} | ||
|
||
$vendorDir = $projectRoot . DIRECTORY_SEPARATOR . VENDOR_DIR; | ||
$sourceFilePath = realpath($vendorDir . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR . $sourceFile); | ||
|
||
if (! $sourceFilePath || ! file_exists($sourceFilePath)) { | ||
echo "Error: Source file $sourceFile does not exist." . PHP_EOL; | ||
exit(1); | ||
} | ||
|
||
$destDirectoryPath = realpath($projectRoot . DIRECTORY_SEPARATOR . $destinationDirectory); | ||
if (! $destDirectoryPath || ! is_dir($destDirectoryPath) || ! is_writable($destDirectoryPath)) { | ||
echo "Error: Destination directory $destinationDirectory does not exist or is not writable." . PHP_EOL; | ||
exit(1); | ||
} | ||
|
||
return [$sourceFilePath, $destDirectoryPath]; | ||
} | ||
|
||
$projectRoot = realpath(__DIR__ . '/..'); | ||
$options = getopt("", ["package:", "sourceFile:", "destinationDirectory:"]); | ||
|
||
[$sourceFilePath, $destinationDirectoryPath] = validateInput($options, $projectRoot); | ||
|
||
$sourceFileName = basename($sourceFilePath); | ||
$destinationFilePath = $destinationDirectoryPath . DIRECTORY_SEPARATOR . $sourceFileName; | ||
$destinationFileWithoutDist = str_replace('.dist', '', $destinationFilePath); | ||
|
||
copyFile($sourceFilePath, $destinationFilePath); | ||
copyFile($sourceFilePath, $destinationFileWithoutDist); | ||
|
||
echo "Files copied successfully from {$options['package']}." . PHP_EOL; | ||
exit(0); |
This file was deleted.
Oops, something went wrong.