Convert InitializeProjectOptions constants to enum cases
This commit is contained in:
parent
87844ab00a
commit
2bd2d757fd
3 changed files with 14 additions and 14 deletions
|
@ -22,25 +22,25 @@
|
|||
|
||||
namespace ncc\Enums\Options;
|
||||
|
||||
final class InitializeProjectOptions
|
||||
enum InitializeProjectOptions : string
|
||||
{
|
||||
/**
|
||||
* A custom path to the project's source directory
|
||||
*/
|
||||
public const PROJECT_SRC_PATH = 'PROJECT_SRC_PATH';
|
||||
case PROJECT_SRC_PATH = 'PROJECT_SRC_PATH';
|
||||
|
||||
/**
|
||||
* A boolean option that indicates whether to overwrite the project file if it already exists
|
||||
*/
|
||||
public const OVERWRITE_PROJECT_FILE = 'OVERWRITE_PROJECT_FILE';
|
||||
case OVERWRITE_PROJECT_FILE = 'OVERWRITE_PROJECT_FILE';
|
||||
|
||||
/**
|
||||
* Composer Only, used to define the package's real version
|
||||
*/
|
||||
public const COMPOSER_PACKAGE_VERSION = 'COMPOSER_PACKAGE_VERSION';
|
||||
case COMPOSER_PACKAGE_VERSION = 'COMPOSER_PACKAGE_VERSION';
|
||||
|
||||
/**
|
||||
* Composer Only, used to define the package's update source
|
||||
*/
|
||||
public const COMPOSER_REMOTE_SOURCE = 'COMPOSER_REMOTE_SOURCE';
|
||||
case COMPOSER_REMOTE_SOURCE = 'COMPOSER_REMOTE_SOURCE';
|
||||
}
|
|
@ -598,8 +598,8 @@
|
|||
|
||||
$archive_path = $this->downloadFile($results->getUrl(), PathFinder::getCachePath());
|
||||
$package_path = $this->buildFromSource($archive_path, [
|
||||
InitializeProjectOptions::COMPOSER_PACKAGE_VERSION => $results->getVersion(),
|
||||
InitializeProjectOptions::COMPOSER_REMOTE_SOURCE => $input->toString()
|
||||
InitializeProjectOptions::COMPOSER_PACKAGE_VERSION->value => $results->getVersion(),
|
||||
InitializeProjectOptions::COMPOSER_REMOTE_SOURCE->value => $input->toString()
|
||||
]);
|
||||
}
|
||||
catch(Exception $e)
|
||||
|
|
|
@ -378,7 +378,7 @@
|
|||
|
||||
if(is_file($project_path . DIRECTORY_SEPARATOR . 'project.json'))
|
||||
{
|
||||
if(!isset($options[InitializeProjectOptions::OVERWRITE_PROJECT_FILE]))
|
||||
if(!isset($options[InitializeProjectOptions::OVERWRITE_PROJECT_FILE->value]))
|
||||
{
|
||||
throw new IOException('A project has already been initialized in \'' . $project_path . DIRECTORY_SEPARATOR . 'project.json' . '\'');
|
||||
}
|
||||
|
@ -387,7 +387,7 @@
|
|||
unlink($project_path . DIRECTORY_SEPARATOR . 'project.json');
|
||||
}
|
||||
|
||||
$project_src = $options[InitializeProjectOptions::PROJECT_SRC_PATH] ?? ('src' . DIRECTORY_SEPARATOR . $name);
|
||||
$project_src = $options[InitializeProjectOptions::PROJECT_SRC_PATH->value] ?? ('src' . DIRECTORY_SEPARATOR . $name);
|
||||
if(str_ends_with($project_src, DIRECTORY_SEPARATOR))
|
||||
{
|
||||
$project_src = substr($project_src, 0, -1);
|
||||
|
@ -455,7 +455,7 @@
|
|||
|
||||
if(is_file($project_file))
|
||||
{
|
||||
if(!isset($options[InitializeProjectOptions::OVERWRITE_PROJECT_FILE]))
|
||||
if(!isset($options[InitializeProjectOptions::OVERWRITE_PROJECT_FILE->value]))
|
||||
{
|
||||
throw new IOException('A project has already been initialized in \'' . $project_file . '\'');
|
||||
}
|
||||
|
@ -464,7 +464,7 @@
|
|||
unlink($project_file);
|
||||
}
|
||||
|
||||
if(!isset($options[InitializeProjectOptions::COMPOSER_PACKAGE_VERSION]))
|
||||
if(!isset($options[InitializeProjectOptions::COMPOSER_PACKAGE_VERSION->value]))
|
||||
{
|
||||
throw new OperationException('Unable to initialize project from composer.json without a version option');
|
||||
}
|
||||
|
@ -489,7 +489,7 @@
|
|||
$assembly = new ProjectConfiguration\Assembly(
|
||||
Resolver::composerName($composer_json->getName()),
|
||||
Resolver::composerNameToPackage($composer_json->getName()),
|
||||
$options[InitializeProjectOptions::COMPOSER_PACKAGE_VERSION]
|
||||
$options[InitializeProjectOptions::COMPOSER_PACKAGE_VERSION->value]
|
||||
);
|
||||
$assembly->setDescription($composer_json->getDescription());
|
||||
|
||||
|
@ -645,10 +645,10 @@
|
|||
$build->addBuildConfiguration($executable_release_configuration);
|
||||
|
||||
// Create an update source for the project
|
||||
if(isset($options[InitializeProjectOptions::COMPOSER_REMOTE_SOURCE]))
|
||||
if(isset($options[InitializeProjectOptions::COMPOSER_REMOTE_SOURCE->value]))
|
||||
{
|
||||
$project->setUpdateSource(new ProjectConfiguration\UpdateSource(
|
||||
$options[InitializeProjectOptions::COMPOSER_REMOTE_SOURCE],
|
||||
$options[InitializeProjectOptions::COMPOSER_REMOTE_SOURCE->value],
|
||||
(new RepositoryManager())->getRepository('packagist')->getProjectRepository()
|
||||
));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue