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
|
||||
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);
|
||||
}
|
||||
catch (Exception $e)
|
||||
|
|
|
@ -87,7 +87,8 @@
|
|||
* @throws PathNotFoundException
|
||||
* @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->setOptions(array_merge($configuration->getOptions(), $options));
|
||||
|
@ -327,7 +328,8 @@
|
|||
* @param string $build_configuration
|
||||
* @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());
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
* @inheritDoc
|
||||
* @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);
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
|
||||
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
|
||||
* @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
|
||||
{
|
||||
$package_path = (new ProjectManager($project_detection->getProjectFilePath()))->build(
|
||||
BuildConfigurationValues::DEFAULT,
|
||||
BuildConfigurationValues::DEFAULT->value,
|
||||
[BuildConfigurationOptions::OUTPUT_FILE => PathFinder::getCachePath() . DIRECTORY_SEPARATOR . hash('sha1', $archive) . '.ncc']
|
||||
);
|
||||
|
||||
|
@ -829,7 +829,7 @@
|
|||
{
|
||||
$project_manager = ProjectManager::initializeFromComposer(dirname($project_detection->getProjectFilePath()), $options);
|
||||
$package_path = $project_manager->build(
|
||||
BuildConfigurationValues::DEFAULT,
|
||||
BuildConfigurationValues::DEFAULT->value,
|
||||
[BuildConfigurationOptions::OUTPUT_FILE => PathFinder::getCachePath() . DIRECTORY_SEPARATOR . hash('sha1', $archive) . '.ncc']
|
||||
);
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@
|
|||
* @throws NotSupportedException
|
||||
* @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);
|
||||
|
||||
|
@ -275,7 +275,7 @@
|
|||
* @throws IOException
|
||||
* @throws PathNotFoundException
|
||||
*/
|
||||
public function getExecutionUnits(string $build_configuration=BuildConfigurationValues::DEFAULT): array
|
||||
public function getExecutionUnits(string $build_configuration=BuildConfigurationValues::DEFAULT->value): array
|
||||
{
|
||||
$execution_units = [];
|
||||
|
||||
|
@ -301,7 +301,7 @@
|
|||
* @return array
|
||||
* @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);
|
||||
|
||||
|
@ -317,7 +317,7 @@
|
|||
* @return array
|
||||
* @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);
|
||||
|
||||
|
@ -334,7 +334,7 @@
|
|||
* @param string $build_configuration
|
||||
* @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);
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@
|
|||
* @return string[]
|
||||
* @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)
|
||||
{
|
||||
|
@ -287,7 +287,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
if($build_configuration === BuildConfigurationValues::ALL)
|
||||
if($build_configuration === BuildConfigurationValues::ALL->value)
|
||||
{
|
||||
/** @var BuildConfiguration $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()));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
public function __construct(string $source_path, ?string $default_configuration=null)
|
||||
{
|
||||
$this->source_path = $source_path;
|
||||
$this->default_configuration = $default_configuration ?? BuildConfigurationValues::DEFAULT;
|
||||
$this->default_configuration = $default_configuration ?? BuildConfigurationValues::DEFAULT->value;
|
||||
$this->exclude_files = [];
|
||||
$this->options = [];
|
||||
$this->define_constants = [];
|
||||
|
@ -484,7 +484,7 @@
|
|||
*/
|
||||
public function getBuildConfiguration(string $name): BuildConfiguration
|
||||
{
|
||||
if($name === BuildConfigurationValues::DEFAULT)
|
||||
if($name === BuildConfigurationValues::DEFAULT->value)
|
||||
{
|
||||
$name = $this->default_configuration;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue