Skip to content

Commit

Permalink
A bit of spring cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude committed May 6, 2022
1 parent ccf1145 commit 93d0547
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 99 deletions.
16 changes: 0 additions & 16 deletions .editorconfig

This file was deleted.

8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
### Composer
composer.phar
composer.lock
vendor/

### Node
node_modules/

### PHPStorm
.idea/
27 changes: 27 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => array('syntax' => 'short'),
'no_unreachable_default_argument_value' => false,
'braces' => array('allow_single_line_closure' => true),
'heredoc_to_nowdoc' => false,
'phpdoc_annotation_without_dot' => false,
'php_unit_test_annotation' => ['style' => 'annotation'],
'php_unit_method_casing' => false,
'psr_autoloading' => false,
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->notPath('conf/')
->notPath('tmp/')
->notPath('node_modules/')
->notPath('var/cache')
->notPath('vendor/')
->notPath('www')
)
;
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# content-mapping-bundle #
# content-mapping-bundle

Symfony bundle for [webfactory/content-mapping](https://github.com/webfactory/content-mapping). If you configure your
Synchronizers as services, you can use the provided console commands to list and start them. This is useful e.g. for
cronjobs.


## Installation ##
## Installation

Install the package via composer

Expand All @@ -26,7 +26,7 @@ public function registerBundles()
```


## Usage ##
## Usage

First, register your Synchronizers as a service, e.g. in your services.xml:

Expand Down Expand Up @@ -79,11 +79,11 @@ the destination systems even if no changes are detected. Be aware that `objectcl
you'd like to synchronize, but the value you defined in the service definition (see above).


## Credits, Copyright and License ##
## Credits, Copyright and License

This project was started at webfactory GmbH, Bonn.

- <https://www.webfactory.de>
- <https://twitter.com/webfactory>

Copyright 2015-2018 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).
Copyright 2015-2022 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],

"require": {
"php": "7.2.*|7.4.*",
"php": "7.2.*|7.4.*|8.0.*|8.1.*",
"symfony/config": "^2.4|^3.0|^4.0|^5.0",
"symfony/console": "^2.4|^3.0|^4.0|^5.0",
"symfony/dependency-injection": "^2.4|^3.0|^4.0|^5.0",
Expand Down
11 changes: 1 addition & 10 deletions src/Command/ListSynchronizersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,18 @@ class ListSynchronizersCommand extends Command
*/
private $synchronizerRegistry;

/**
* @param Registry $synchronizerRegistry
*/
public function __construct(Registry $synchronizerRegistry)
{
parent::__construct();
$this->synchronizerRegistry = $synchronizerRegistry;
}

/**
* {@inheritDoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('content-mapping:list-synchronizers')
->setDescription('Lists the available synchronizers');
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
foreach ($this->synchronizerRegistry->getObjectclasses() as $objectclass) {
Expand Down
23 changes: 7 additions & 16 deletions src/Command/SynchronizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Webfactory\ContentMappingBundle\Command;

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Webfactory\ContentMappingBundle\Synchronizer\Registry;

/**
Expand All @@ -24,21 +25,14 @@ final class SynchronizeCommand extends Command
*/
private $logger;

/**
* @param Registry $synchronizerRegistry
* @param LoggerInterface $logger
*/
public function __construct(Registry $synchronizerRegistry, LoggerInterface $logger)
public function __construct(Registry $synchronizerRegistry, LoggerInterface $logger = null)
{
parent::__construct();
$this->synchronizerRegistry = $synchronizerRegistry;
$this->logger = $logger;
$this->logger = $logger ?? new NullLogger();
}

/**
* {@inheritDoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('content-mapping:synchronize')
->setDescription('Starts the synchronizer(s).');
Expand All @@ -56,21 +50,18 @@ protected function configure()
);
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$force = $input->getOption('force');
$only = $input->getOption('only');

foreach ($this->synchronizerRegistry->getObjectclasses() as $objectclass) {
if ($only && !in_array($objectclass, $only)) {
if ($only && !\in_array($objectclass, $only)) {
$this->logger->debug("Skipping Synchronizer for object class $objectclass");
continue;
}

$this->logger->debug('Use Synchronizer for object class ' . $objectclass);
$this->logger->debug('Use Synchronizer for object class '.$objectclass);

$this->synchronizerRegistry->getSynchronizer($objectclass)
->synchronize($objectclass, $force);
Expand Down
9 changes: 3 additions & 6 deletions src/DependencyInjection/Compiler/RegisterSynchronizerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@

namespace Webfactory\ContentMappingBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Fills the Synchronizer\Registry with services tagged as "contentmapping.synchronizer".
*/
final class RegisterSynchronizerPass implements CompilerPassInterface
{
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$definition = $container->getDefinition('contentmapping.synchronizer_registry');

Expand All @@ -29,7 +26,7 @@ public function process(ContainerBuilder $container)
throw new \Exception('The contentmapping.synchronizer tag requires the objectclass attribute.');
}

$definition->addMethodCall('addSynchronizer', array($tag['objectclass'], $id));
$definition->addMethodCall('addSynchronizer', [$tag['objectclass'], $id]);

// Prevents Symfony from optimizing these services away if they're anonymous
$container->getDefinition($id)->setPublic(true);
Expand Down
16 changes: 5 additions & 11 deletions src/DependencyInjection/WebfactoryContentMappingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@

namespace Webfactory\ContentMappingBundle\DependencyInjection;

use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

/**
* Symfony dependency injection extension.
*/
class WebfactoryContentMappingExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
}
}
24 changes: 7 additions & 17 deletions src/Synchronizer/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,34 @@ final class Registry
/**
* @var array(string objectClass => string serviceId)
*/
private $services = array();
private $services = [];

/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

/**
* @param string $objectclass
* @param string $serviceId
*/
public function addSynchronizer($objectclass, $serviceId)
public function addSynchronizer(string $objectclass, string $serviceId)
{
$this->services[$objectclass] = $serviceId;
}

/**
* @return string[]
*/
public function getObjectclasses()
public function getObjectclasses(): array
{
return array_keys($this->services);
}

/**
* @param string $objectclass The objectclass to retrieve the Synchronizer for.
* @return Synchronizer
*/
public function getSynchronizer($objectclass)
public function getSynchronizer(string $objectclass): Synchronizer
{
if (array_key_exists($objectclass, $this->services) === false) {
throw new \RuntimeException('No Synchronizer for objectclass "' . $objectclass . '" configured.');
if (false === \array_key_exists($objectclass, $this->services)) {
throw new \RuntimeException('No Synchronizer for objectclass "'.$objectclass.'" configured.');
}

$serviceId = $this->services[$objectclass];

return $this->container->get($serviceId);
}
}
11 changes: 2 additions & 9 deletions src/WebfactoryContentMappingBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@

namespace Webfactory\ContentMappingBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Webfactory\ContentMappingBundle\DependencyInjection\Compiler\RegisterSynchronizerPass;

/**
* Symfony Bundle class.
*/
class WebfactoryContentMappingBundle extends Bundle
{
/**
* {@inheritDoc}
*/
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);
$container->addCompilerPass(new RegisterSynchronizerPass());
}
}

0 comments on commit 93d0547

Please sign in to comment.