Skip to content

Commit 79fa73b

Browse files
committed
Merge branch '2.0.0-alpha' for 2.0.0 release
2 parents 5e80126 + d7a2a50 commit 79fa73b

26 files changed

+748
-486
lines changed

.gitattributes

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/tests export-ignore
2+
/.gitattributes export-ignore
3+
/.gitignore export-ignore
4+
/.travis.yml export-ignore
5+
/phpunit.xml.dist export-ignore
6+
/.scrutinizer.yml export-ignore

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
/.idea/
3+
/bin/
4+
/vendor/

.scrutinizer.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
filter:
2+
excluded_paths:
3+
- 'vendor/*'
4+
5+
before_commands:
6+
- 'composer install --dev --prefer-source'
7+
8+
tools:
9+
external_code_coverage: true
10+
php_mess_detector: true
11+
php_code_sniffer: true
12+
sensiolabs_security_checker: true
13+
php_code_coverage: true
14+
php_pdepend: true
15+
php_loc:
16+
enabled: true
17+
excluded_dirs: [vendor, Tests]
18+
php_cpd:
19+
enabled: true
20+
excluded_dirs: [vendor, Tests]

.travis.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: php
2+
php:
3+
- 5.6
4+
- 7
5+
- hhvm
6+
- nightly
7+
8+
before_script:
9+
- curl -s http://getcomposer.org/installer | php
10+
- php composer.phar install
11+
12+
script: phpunit --coverage-clover=coverage.clover
13+
14+
after_script:
15+
- wget https://scrutinizer-ci.com/ocular.phar
16+
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

Command/VersionBumpCommand.php

+55-54
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?php
2+
23
namespace Shivas\VersioningBundle\Command;
34

4-
use Herrera\Version\Dumper;
5-
use Herrera\Version\Parser as VersionParser;
6-
use Herrera\Version\Version;
7-
use Shivas\VersioningBundle\Handler\HandlerInterface;
5+
use RuntimeException;
6+
use Shivas\VersioningBundle\Provider\ProviderInterface;
87
use Shivas\VersioningBundle\Service\VersionsManager;
98
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
109
use Symfony\Component\Console\Helper\Table;
@@ -14,6 +13,7 @@
1413
use Symfony\Component\Console\Output\OutputInterface;
1514
use Symfony\Component\Yaml\Parser;
1615
use Symfony\Component\Yaml\Yaml;
16+
use Version\Version;
1717

1818
class VersionBumpCommand extends ContainerAwareCommand
1919
{
@@ -22,16 +22,16 @@ protected function configure()
2222
$this
2323
->setName('app:version:bump')
2424
->setDescription(
25-
'Bumping of application version using one of available handlers'
25+
'Bumping of application version using one of the available providers'
2626
)
2727
->addArgument('version', InputArgument::OPTIONAL, 'Version to set, should be compatible with Semantic versioning 2.0.0', null)
2828
->addOption('dry-run', 'd', InputOption::VALUE_NONE, 'Dry run, not update parameters file, just print it')
29-
->addOption('list-handlers', 'l', InputOption::VALUE_NONE, 'List registered version handlers')
29+
->addOption('list-providers', 'l', InputOption::VALUE_NONE, 'List registered version providers')
3030
->addOption('major', null, InputOption::VALUE_OPTIONAL, 'Bump MAJOR version by given number', 0)
3131
->addOption('minor', null, InputOption::VALUE_OPTIONAL, 'Bump MINOR version by given number', 0)
3232
->addOption('patch', null, InputOption::VALUE_OPTIONAL, 'Bump PATCH version by given number', 0)
33-
->addOption('prerelease', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Add PRERELEASE to version', null)
34-
->addOption('build', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Add BUILD to version', null);
33+
->addOption('prerelease', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Add PRERELEASE to version', array())
34+
->addOption('build', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Add BUILD to version', array());
3535
}
3636

3737
protected function execute(InputInterface $input, OutputInterface $output)
@@ -44,68 +44,70 @@ protected function execute(InputInterface $input, OutputInterface $output)
4444
/** @var VersionsManager $manager */
4545
$manager = $this->getContainer()->get('shivas_versioning.manager');
4646

47-
if ($input->getOption('list-handlers')) {
48-
$this->listHandlers($manager, $output);
47+
if ($input->getOption('list-providers')) {
48+
$this->listProviders($manager, $output);
4949
return;
5050
}
5151

5252
if ($input->getArgument('version') === null) {
53-
5453
$version = $manager->getVersion();
5554

5655
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
57-
$output->writeln(sprintf('Handler: <comment>%s</comment>', $manager->getActiveHandler()->getName()));
56+
$output->writeln(sprintf('Provider: <comment>%s</comment>', $manager->getActiveProvider()->getName()));
5857
}
5958

60-
$builder = VersionParser::toBuilder(Dumper::toString($version));
61-
62-
63-
if ($input->getOption('major') > 0) {
64-
$builder->incrementMajor(intval($input->getOption('major')));
59+
$incrementMajor = (int) $input->getOption('major');
60+
if ($incrementMajor > 0) {
61+
for ($i = 0; $i < $incrementMajor; $i++) {
62+
$version = $version->withMajorIncremented();
63+
}
6564
}
6665

67-
if ($input->getOption('minor') > 0) {
68-
$builder->incrementMinor(intval($input->getOption('minor')));
66+
$incrementMinor = (int) $input->getOption('minor');
67+
if ($incrementMinor > 0) {
68+
for ($i = 0; $i < $incrementMinor; $i++) {
69+
$version = $version->withMinorIncremented();
70+
}
6971
}
7072

71-
if ($input->getOption('patch') > 0) {
72-
$builder->incrementPatch(intval($input->getOption('patch')));
73+
$incrementPatch = (int) $input->getOption('patch');
74+
if ($incrementPatch > 0) {
75+
for ($i = 0; $i < $incrementPatch; $i++) {
76+
$version = $version->withPatchIncremented();
77+
}
7378
}
7479

75-
if ($input->getOption('prerelease')) {
76-
$preRelease = $input->getOption('prerelease');
80+
$preRelease = $input->getOption('prerelease');
81+
if (!empty($preRelease)) {
7782
if (in_array(null, $preRelease)) {
7883
$preRelease = array();
7984
}
8085

81-
$builder->setPreRelease($preRelease);
86+
$version = $version->withPreRelease($preRelease);
8287
}
8388

84-
if ($input->getOption('build')) {
85-
$build = $input->getOption('build');
89+
$build = $input->getOption('build');
90+
if (!empty($build)) {
8691
if (in_array(null, $build)) {
8792
$build = array();
8893
}
8994

90-
$builder->setBuild($build);
95+
$version = $version->withBuild($build);
9196
}
92-
93-
$version = $builder->getVersion();
94-
9597
} else {
96-
$version = VersionParser::toVersion($input->getArgument('version'));
98+
$version = Version::fromString($input->getArgument('version'));
9799
}
98100

99101
if (!$input->getOption('dry-run')) {
100102
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
101103
$output->writeln(
102104
sprintf(
103105
'Updating parameters file with version number: <info>%s</info>',
104-
Dumper::toString($version)
106+
$version->getVersionString()
105107
)
106108
);
107109
} else {
108-
$output->writeln(Dumper::toString($version));
110+
$output->writeln($version->getVersionString());
109111
}
110112

111113
if (!file_exists($paramFile)) {
@@ -115,9 +117,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
115117
}
116118
} else {
117119
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
118-
$output->writeln(sprintf('Version: <comment>%s</comment>', Dumper::toString($version)));
120+
$output->writeln(sprintf('Version: <comment>%s</comment>', $version->getVersionString()));
119121
} else {
120-
$output->writeln(Dumper::toString($version));
122+
$output->writeln($version->getVersionString());
121123
}
122124
}
123125
}
@@ -126,52 +128,51 @@ protected function execute(InputInterface $input, OutputInterface $output)
126128
* @param VersionsManager $manager
127129
* @param OutputInterface $output
128130
*/
129-
protected function listHandlers(VersionsManager $manager, OutputInterface $output)
131+
protected function listProviders(VersionsManager $manager, OutputInterface $output)
130132
{
131-
$output->writeln('Registered Version handlers');
132-
$handlers = $manager->getHandlers();
133+
$output->writeln('Registered Version providers');
134+
$providers = $manager->getProviders();
133135
$table = new Table($output);
134136
$table->setHeaders(array('Alias', 'Priority', 'Name', 'Supported'))
135137
->setStyle('borderless');
136138

137-
foreach ($handlers as $key => $handlerEntry) {
138-
/** @var $handler HandlerInterface */
139-
$handler = $handlerEntry['handler'];
140-
$supported = $handler->isSupported() ? 'Yes' : 'No';
141-
$table->addRow(array($key, $handlerEntry['priority'], $handler->getName(), $supported));
139+
foreach ($providers as $key => $providerEntry) {
140+
/** @var $provider ProviderInterface */
141+
$provider = $providerEntry['provider'];
142+
$supported = $provider->isSupported() ? 'Yes' : 'No';
143+
$table->addRow(array($key, $providerEntry['priority'], $provider->getName(), $supported));
142144
}
143145

144146
$table->render();
145147
}
146148

147149
/**
148-
* @param Version $version
149-
* @param $file
150-
* @param $param
150+
* @param Version $version
151+
* @param string $file
152+
* @param string $param
151153
*/
152154
protected function createParametersFile(Version $version, $file, $param)
153155
{
154-
$params = array('parameters' => array($param => Dumper::toString($version)));
156+
$params = array('parameters' => array($param => $version->getVersionString()));
155157
file_put_contents($file, Yaml::dump($params));
156158
}
157159

158160
/**
159-
* @param Version $version
160-
* @param $file
161-
* @param $param
162-
* @throws \RuntimeException
161+
* @param Version $version
162+
* @param string $file
163+
* @param string $param
164+
* @throws RuntimeException
163165
*/
164166
protected function updateParametersFile(Version $version, $file, $param)
165167
{
166168
$yamlParser = new Parser();
167169

168170
$params = $yamlParser->parse(file_get_contents($file));
169171
if (!empty($params['parameters'])) {
170-
$params['parameters'][$param] = Dumper::toString($version);
172+
$params['parameters'][$param] = $version->getVersionString();
171173
file_put_contents($file, Yaml::dump($params));
172174
} else {
173-
throw new \RuntimeException('Not valid parameters file?');
175+
throw new RuntimeException('Not valid parameters file?');
174176
}
175177
}
176178
}
177-

DependencyInjection/Compiler/HandlerCompilerPass.php renamed to DependencyInjection/Compiler/ProviderCompilerPass.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@
55
use Symfony\Component\DependencyInjection\ContainerBuilder;
66
use Symfony\Component\DependencyInjection\Reference;
77

8-
class HandlerCompilerPass implements CompilerPassInterface
8+
/**
9+
* Class ProviderCompilerPass
10+
*/
11+
class ProviderCompilerPass implements CompilerPassInterface
912
{
13+
/**
14+
* @param ContainerBuilder $container
15+
*/
1016
public function process(ContainerBuilder $container)
1117
{
1218
if (!$container->hasDefinition('shivas_versioning.manager')) {
1319
return;
1420
}
1521

1622
$definition = $container->getDefinition('shivas_versioning.manager');
17-
$handlers = $container->findTaggedServiceIds('shivas_versioning.handler');
23+
$providers = $container->findTaggedServiceIds('shivas_versioning.provider');
1824

19-
foreach ($handlers as $id => $attributes) {
25+
foreach ($providers as $id => $attributes) {
2026
$attributes = reset($attributes);
2127
$definition->addMethodCall(
22-
'addHandler',
28+
'addProvider',
2329
array(new Reference($id), $attributes['alias'], $attributes['priority'])
2430
);
2531
}

DependencyInjection/Configuration.php

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public function getConfigTreeBuilder()
2222
->scalarNode('version_file')
2323
->defaultValue('parameters.yml')
2424
->end()
25+
->scalarNode(('version_formatter'))
26+
->defaultValue('shivas_versioning.formatters.git')
27+
->end()
2528
->end();
2629

2730
return $treeBuilder;

DependencyInjection/ShivasVersioningExtension.php

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Symfony\Component\DependencyInjection\ContainerBuilder;
66
use Symfony\Component\Config\FileLocator;
7+
use Symfony\Component\DependencyInjection\Reference;
78
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
89
use Symfony\Component\DependencyInjection\Loader;
910

@@ -27,5 +28,9 @@ public function load(array $configs, ContainerBuilder $container)
2728

2829
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2930
$loader->load('services.xml');
31+
32+
if (null !== $config['version_formatter']) {
33+
$container->getDefinition('shivas_versioning.manager')->addArgument(new Reference($config['version_formatter']));
34+
}
3035
}
3136
}

Formatter/FormatterInterface.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Shivas\VersioningBundle\Formatter;
4+
5+
use Version\Version;
6+
7+
/**
8+
* Interface FormatterInterface
9+
*/
10+
interface FormatterInterface
11+
{
12+
/**
13+
* @param Version $version
14+
* @return Version
15+
*/
16+
public function format(Version $version);
17+
}

0 commit comments

Comments
 (0)