Convert BuildConfigurationValues constants to enum cases
This commit is contained in:
parent
ae21d98290
commit
c24fce2ee5
9 changed files with 23 additions and 20 deletions
|
@ -92,7 +92,7 @@
|
||||||
// Build the project
|
// Build the project
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$build_configuration = $args['config'] ?? $args['c'] ?? BuildConfigurationValues::DEFAULT;
|
$build_configuration = $args['config'] ?? $args['c'] ?? BuildConfigurationValues::DEFAULT->value;
|
||||||
$output = $project_manager->build($build_configuration, $options);
|
$output = $project_manager->build($build_configuration, $options);
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
|
|
|
@ -87,7 +87,8 @@
|
||||||
* @throws PathNotFoundException
|
* @throws PathNotFoundException
|
||||||
* @noinspection UnusedFunctionResultInspection
|
* @noinspection UnusedFunctionResultInspection
|
||||||
*/
|
*/
|
||||||
public function build(string $build_configuration=BuildConfigurationValues::DEFAULT, array $options=[]): string
|
// TODO: $build_configuration could use enum case
|
||||||
|
public function build(string $build_configuration=BuildConfigurationValues::DEFAULT->value, array $options=[]): string
|
||||||
{
|
{
|
||||||
$configuration = $this->project_manager->getProjectConfiguration()->getBuild()->getBuildConfiguration($build_configuration);
|
$configuration = $this->project_manager->getProjectConfiguration()->getBuild()->getBuildConfiguration($build_configuration);
|
||||||
$configuration->setOptions(array_merge($configuration->getOptions(), $options));
|
$configuration->setOptions(array_merge($configuration->getOptions(), $options));
|
||||||
|
@ -327,7 +328,8 @@
|
||||||
* @param string $build_configuration
|
* @param string $build_configuration
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function processMetadata(PackageWriter $package_writer, string $build_configuration=BuildConfigurationValues::DEFAULT): void
|
// TODO: $build_configuration could use the enum case
|
||||||
|
public function processMetadata(PackageWriter $package_writer, string $build_configuration=BuildConfigurationValues::DEFAULT->value): void
|
||||||
{
|
{
|
||||||
$metadata = new Metadata($this->project_manager->getProjectConfiguration()->getProject()->getCompiler());
|
$metadata = new Metadata($this->project_manager->getProjectConfiguration()->getProject()->getCompiler());
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
* @throws BuildException
|
* @throws BuildException
|
||||||
*/
|
*/
|
||||||
public function build(string $build_configuration = BuildConfigurationValues::DEFAULT, array $options=[]): string
|
public function build(string $build_configuration = BuildConfigurationValues::DEFAULT->value, array $options=[]): string
|
||||||
{
|
{
|
||||||
$configuration = $this->getProjectManager()->getProjectConfiguration()->getBuild()->getBuildConfiguration($build_configuration);
|
$configuration = $this->getProjectManager()->getProjectConfiguration()->getBuild()->getBuildConfiguration($build_configuration);
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,9 @@
|
||||||
|
|
||||||
namespace ncc\Enums\Options;
|
namespace ncc\Enums\Options;
|
||||||
|
|
||||||
final class BuildConfigurationValues
|
enum BuildConfigurationValues : string
|
||||||
{
|
{
|
||||||
public const DEFAULT = 'default';
|
case DEFAULT = 'default';
|
||||||
|
|
||||||
public const ALL = 'all';
|
case ALL = 'all';
|
||||||
}
|
}
|
|
@ -41,5 +41,6 @@
|
||||||
* @param array $options Optional. The options to use/override for this build
|
* @param array $options Optional. The options to use/override for this build
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function build(string $build_configuration=BuildConfigurationValues::DEFAULT, array $options=[]): string;
|
// TODO: $build_configuration could use the enum case directly
|
||||||
|
public function build(string $build_configuration=BuildConfigurationValues::DEFAULT->value, array $options=[]): string;
|
||||||
}
|
}
|
|
@ -805,7 +805,7 @@
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$package_path = (new ProjectManager($project_detection->getProjectFilePath()))->build(
|
$package_path = (new ProjectManager($project_detection->getProjectFilePath()))->build(
|
||||||
BuildConfigurationValues::DEFAULT,
|
BuildConfigurationValues::DEFAULT->value,
|
||||||
[BuildConfigurationOptions::OUTPUT_FILE => PathFinder::getCachePath() . DIRECTORY_SEPARATOR . hash('sha1', $archive) . '.ncc']
|
[BuildConfigurationOptions::OUTPUT_FILE => PathFinder::getCachePath() . DIRECTORY_SEPARATOR . hash('sha1', $archive) . '.ncc']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -829,7 +829,7 @@
|
||||||
{
|
{
|
||||||
$project_manager = ProjectManager::initializeFromComposer(dirname($project_detection->getProjectFilePath()), $options);
|
$project_manager = ProjectManager::initializeFromComposer(dirname($project_detection->getProjectFilePath()), $options);
|
||||||
$package_path = $project_manager->build(
|
$package_path = $project_manager->build(
|
||||||
BuildConfigurationValues::DEFAULT,
|
BuildConfigurationValues::DEFAULT->value,
|
||||||
[BuildConfigurationOptions::OUTPUT_FILE => PathFinder::getCachePath() . DIRECTORY_SEPARATOR . hash('sha1', $archive) . '.ncc']
|
[BuildConfigurationOptions::OUTPUT_FILE => PathFinder::getCachePath() . DIRECTORY_SEPARATOR . hash('sha1', $archive) . '.ncc']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@
|
||||||
* @throws NotSupportedException
|
* @throws NotSupportedException
|
||||||
* @throws PathNotFoundException
|
* @throws PathNotFoundException
|
||||||
*/
|
*/
|
||||||
public function build(string $build_configuration=BuildConfigurationValues::DEFAULT, array $options=[]): string
|
public function build(string $build_configuration=BuildConfigurationValues::DEFAULT->value, array $options=[]): string
|
||||||
{
|
{
|
||||||
$configuration = $this->project_configuration->getBuild()->getBuildConfiguration($build_configuration);
|
$configuration = $this->project_configuration->getBuild()->getBuildConfiguration($build_configuration);
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws PathNotFoundException
|
* @throws PathNotFoundException
|
||||||
*/
|
*/
|
||||||
public function getExecutionUnits(string $build_configuration=BuildConfigurationValues::DEFAULT): array
|
public function getExecutionUnits(string $build_configuration=BuildConfigurationValues::DEFAULT->value): array
|
||||||
{
|
{
|
||||||
$execution_units = [];
|
$execution_units = [];
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@
|
||||||
* @return array
|
* @return array
|
||||||
* @throws NotSupportedException
|
* @throws NotSupportedException
|
||||||
*/
|
*/
|
||||||
public function getComponents(string $build_configuration=BuildConfigurationValues::DEFAULT): array
|
public function getComponents(string $build_configuration=BuildConfigurationValues::DEFAULT->value): array
|
||||||
{
|
{
|
||||||
$configuration = $this->project_configuration->getBuild()->getBuildConfiguration($build_configuration);
|
$configuration = $this->project_configuration->getBuild()->getBuildConfiguration($build_configuration);
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@
|
||||||
* @return array
|
* @return array
|
||||||
* @throws NotSupportedException
|
* @throws NotSupportedException
|
||||||
*/
|
*/
|
||||||
public function getResources(string $build_configuration=BuildConfigurationValues::DEFAULT): array
|
public function getResources(string $build_configuration=BuildConfigurationValues::DEFAULT->value): array
|
||||||
{
|
{
|
||||||
$configuration = $this->project_configuration->getBuild()->getBuildConfiguration($build_configuration);
|
$configuration = $this->project_configuration->getBuild()->getBuildConfiguration($build_configuration);
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@
|
||||||
* @param string $build_configuration
|
* @param string $build_configuration
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getRuntimeConstants(string $build_configuration=BuildConfigurationValues::DEFAULT): array
|
public function getRuntimeConstants(string $build_configuration=BuildConfigurationValues::DEFAULT->value): array
|
||||||
{
|
{
|
||||||
$configuration = $this->project_configuration->getBuild()->getBuildConfiguration($build_configuration);
|
$configuration = $this->project_configuration->getBuild()->getBuildConfiguration($build_configuration);
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@
|
||||||
* @return string[]
|
* @return string[]
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
*/
|
*/
|
||||||
public function getRequiredExecutionPolicies(string $build_configuration=BuildConfigurationValues::DEFAULT): array
|
public function getRequiredExecutionPolicies(string $build_configuration=BuildConfigurationValues::DEFAULT->value): array
|
||||||
{
|
{
|
||||||
if(count($this->execution_policies) === 0)
|
if(count($this->execution_policies) === 0)
|
||||||
{
|
{
|
||||||
|
@ -287,7 +287,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($build_configuration === BuildConfigurationValues::ALL)
|
if($build_configuration === BuildConfigurationValues::ALL->value)
|
||||||
{
|
{
|
||||||
/** @var BuildConfiguration $configuration */
|
/** @var BuildConfiguration $configuration */
|
||||||
foreach($this->build->getBuildConfigurations() as $configuration)
|
foreach($this->build->getBuildConfigurations() as $configuration)
|
||||||
|
@ -424,7 +424,7 @@
|
||||||
throw new ConfigurationException(sprintf('Build configuration build.main points to a undefined execution policy "%s"', $this->build->getMain()));
|
throw new ConfigurationException(sprintf('Build configuration build.main points to a undefined execution policy "%s"', $this->build->getMain()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->build->getMain() === BuildConfigurationValues::ALL)
|
if($this->build->getMain() === BuildConfigurationValues::ALL->value)
|
||||||
{
|
{
|
||||||
throw new ConfigurationException(sprintf('Build configuration build.main cannot be set to "%s"', BuildConfigurationValues::ALL));
|
throw new ConfigurationException(sprintf('Build configuration build.main cannot be set to "%s"', BuildConfigurationValues::ALL));
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@
|
||||||
public function __construct(string $source_path, ?string $default_configuration=null)
|
public function __construct(string $source_path, ?string $default_configuration=null)
|
||||||
{
|
{
|
||||||
$this->source_path = $source_path;
|
$this->source_path = $source_path;
|
||||||
$this->default_configuration = $default_configuration ?? BuildConfigurationValues::DEFAULT;
|
$this->default_configuration = $default_configuration ?? BuildConfigurationValues::DEFAULT->value;
|
||||||
$this->exclude_files = [];
|
$this->exclude_files = [];
|
||||||
$this->options = [];
|
$this->options = [];
|
||||||
$this->define_constants = [];
|
$this->define_constants = [];
|
||||||
|
@ -484,7 +484,7 @@
|
||||||
*/
|
*/
|
||||||
public function getBuildConfiguration(string $name): BuildConfiguration
|
public function getBuildConfiguration(string $name): BuildConfiguration
|
||||||
{
|
{
|
||||||
if($name === BuildConfigurationValues::DEFAULT)
|
if($name === BuildConfigurationValues::DEFAULT->value)
|
||||||
{
|
{
|
||||||
$name = $this->default_configuration;
|
$name = $this->default_configuration;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue