Skip to content
This repository has been archived by the owner on Nov 28, 2020. It is now read-only.

Make it work with Symfony 4 #12

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
composer.lock
code-coverage
build
vendor
phpunit.xml
50 changes: 1 addition & 49 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1 @@
sudo: false

language: php

cache:
directories:
- $HOME/.composer/cache/files

php:
- 5.3
- 5.4
- 5.5
- 7.0
- hhvm

matrix:
fast_finish: true
include:
- php: 5.3
env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_DEPRECATIONS_HELPER=weak
# Test against Symfony LTS versions
- php: 5.6
env: SYMFONY_VERSION="2.3.*"
- php: 5.6
env: SYMFONY_VERSION="2.7.*"
- php: 5.6
env: SYMFONY_VERSION="2.8.*" DEPENDENCIES=dev
# Test against dev versions
- php: 5.6
env: DEPENDENCIES=dev
allow_failures:
- env: DEPENDENCIES=dev

before_install:
- composer self-update
- if [ "$DEPENDENCIES" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --dev --no-update symfony/symfony:"$SYMFONY_VERSION"; fi

install:
- composer update $COMPOSER_FLAGS

before_script:
- mkdir -p build/logs

script:
- composer phpunit

after_script:
- composer coveralls
# TODO: HANDLE CI WITH TRAVIS
38 changes: 29 additions & 9 deletions Command/IncrementCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,36 @@

namespace Kachkaev\AssetsVersionBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;

use Kachkaev\AssetsVersionBundle\AssetsVersionManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class IncrementCommand extends ContainerAwareCommand
class IncrementCommand extends Command
{
protected function configure()
private AssetsVersionManager $assetsVersionManager;
private string $parameterName;
private string $filePath;

/**
* IncrementCommand constructor.
*
* @param AssetsVersionManager $assetsVersionManager
* @param string $parameterName
* @param string $filePath
*/
public function __construct(AssetsVersionManager $assetsVersionManager, string $parameterName, string $filePath)
{
parent::__construct();
$this->assetsVersionManager = $assetsVersionManager;
$this->parameterName = $parameterName;
$this->filePath = $filePath;
}

protected function configure(): void
{
$this
->setName('assets-version:increment')
->setDescription('Increments assets version parameter')
->addArgument(
'delta',
Expand All @@ -24,13 +42,15 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): ?int
{
$output->writeln('Incrementing parameter <info>'.$this->getContainer()->getParameter('kachkaev_assets_version.parameter_name').'</info> in <info>'.basename($this->getContainer()->getParameter('kachkaev_assets_version.file_path')).'</info> by <info>'.var_export($input->getArgument('delta'), true).'</info>...');
$output->writeln('Incrementing parameter <info>'.$this->parameterName.'</info> in <info>'.basename($this->filePath).'</info> by <info>'.var_export($input->getArgument('delta'), true).'</info>...');

$assetsVersionUpdater = $this->getContainer()->get('kachkaev_assets_version.assets_version_manager');
$assetsVersionUpdater = $this->assetsVersionManager;
$assetsVersionUpdater->incrementVersion($input->getArgument('delta'));

$output->writeln('Done. New value for <info>'.$this->getContainer()->getParameter('kachkaev_assets_version.parameter_name').'</info> is <info>'.$assetsVersionUpdater->getVersion().'</info>. Clearing of <info>prod</info> cache is required.');
$output->writeln('Done. New value for <info>'.$this->parameterName.'</info> is <info>'.$assetsVersionUpdater->getVersion().'</info>. Clearing of <info>prod</info> cache is required.');

return self::SUCCESS;
}
}
36 changes: 28 additions & 8 deletions Command/SetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,36 @@

namespace Kachkaev\AssetsVersionBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;

use Kachkaev\AssetsVersionBundle\AssetsVersionManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class SetCommand extends ContainerAwareCommand
class SetCommand extends Command
{
protected function configure()
private AssetsVersionManager $assetsVersionManager;
private string $parameterName;
private string $filePath;

/**
* SetCommand constructor.
*
* @param AssetsVersionManager $assetsVersionManager
* @param string $parameterName
* @param string $filePath
*/
public function __construct(AssetsVersionManager $assetsVersionManager, string $parameterName, string $filePath)
{
parent::__construct();
$this->assetsVersionManager = $assetsVersionManager;
$this->parameterName = $parameterName;
$this->filePath = $filePath;
}

protected function configure(): void
{
$this
->setName('assets-version:set')
->setDescription('Sets assets version parameter to a given value')
->addArgument(
'value',
Expand All @@ -23,14 +41,16 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): ?int
{

$output->writeln('Setting parameter <info>'.$this->getContainer()->getParameter('kachkaev_assets_version.parameter_name').'</info> in <info>'.basename($this->getContainer()->getParameter('kachkaev_assets_version.file_path')).'</info> to <info>'.var_export($input->getArgument('value'), true).'</info>...');
$output->writeln('Setting parameter <info>'.$this->parameterName.'</info> in <info>'.basename($this->filePath).'</info> to <info>'.var_export($input->getArgument('value'), true).'</info>...');

$assetsVersionUpdater = $this->getContainer()->get('kachkaev_assets_version.assets_version_manager');
$assetsVersionUpdater = $this->assetsVersionManager;
$assetsVersionUpdater->setVersion($input->getArgument('value'));

$output->writeln('Done. Clearing of <info>prod</info> cache is required.');

return self::SUCCESS;
}
}
10 changes: 5 additions & 5 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('assets_version');
$treeBuilder = new TreeBuilder('assets_version');

$rootNode
$treeBuilder
->getRootNode()
->children()
->scalarNode('file_path')
->defaultValue('%kernel.root_dir%/config/parameters.yml')
->defaultValue('%kernel.project_dir%/app/config/parameters.yml')
->info('path to the file that contains the assets version parameter')
->end()
->scalarNode('parameter_name')
Expand Down
3 changes: 2 additions & 1 deletion DependencyInjection/KachkaevAssetsVersionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ class KachkaevAssetsVersionExtension extends Extension
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.yml');
$loader->load('services.yml');

if (null !== $config['file_path']) {
$container->setParameter('kachkaev_assets_version.file_path', $config['file_path']);
Expand Down
15 changes: 15 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
Kachkaev\AssetsVersionBundle\Command\IncrementCommand:
arguments:
- '@kachkaev_assets_version.assets_version_manager'
- '%kachkaev_assets_version.parameter_name%'
- '%kachkaev_assets_version.file_path%'
tags:
- { name: 'console.command', command: 'assets-version:increment' }
Kachkaev\AssetsVersionBundle\Command\SetCommand:
arguments:
- '@kachkaev_assets_version.assets_version_manager'
- '%kachkaev_assets_version.parameter_name%'
- '%kachkaev_assets_version.file_path%'
tags:
- { name: 'console.command', command: 'assets-version:set' }
Loading