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

Commit

Permalink
[Settings] Bundle clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Oct 14, 2016
1 parent 8976707 commit b0b5f2a
Show file tree
Hide file tree
Showing 22 changed files with 81 additions and 96 deletions.
7 changes: 2 additions & 5 deletions Controller/SettingsController.php
Expand Up @@ -27,9 +27,6 @@
class SettingsController extends FOSRestController
{
/**
* Get a specific settings data.
* This controller action only used for Rest API.
*
* @param Request $request
*
* @return Response
Expand Down Expand Up @@ -103,15 +100,15 @@ public function updateAction(Request $request)
*/
protected function getSettingsManager()
{
return $this->get('sylius.settings.manager');
return $this->get('sylius.manager.settings');
}

/**
* @return SettingsFormFactoryInterface
*/
protected function getSettingsFormFactory()
{
return $this->get('sylius.settings.form_factory');
return $this->get('sylius.form_factory.settings');
}

/**
Expand Down
6 changes: 4 additions & 2 deletions DependencyInjection/Compiler/RegisterResolversPass.php
Expand Up @@ -18,7 +18,7 @@
/**
* @author Steffen Brem <steffenbrem@gmail.com>
*/
class RegisterResolversPass implements CompilerPassInterface
final class RegisterResolversPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
Expand All @@ -34,7 +34,9 @@ public function process(ContainerBuilder $container)
foreach ($container->findTaggedServiceIds('sylius.settings_resolver') as $id => $tags) {
foreach ($tags as $attributes) {
if (!isset($attributes['schema'])) {
throw new \InvalidArgumentException(sprintf('Service "%s" must define the "schema" attribute on "sylius.settings_resolver" tags.', $id));
throw new \InvalidArgumentException(
sprintf('Service "%s" must define the "schema" attribute on "sylius.settings_resolver" tags.', $id)
);
}

$schemaAlias = $attributes['schema'];
Expand Down
10 changes: 5 additions & 5 deletions DependencyInjection/Compiler/RegisterSchemasPass.php
Expand Up @@ -16,12 +16,9 @@
use Symfony\Component\DependencyInjection\Reference;

/**
* Registers all settings schemas in the schema registry.
* Save the configuration names in parameter for the provider.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class RegisterSchemasPass implements CompilerPassInterface
final class RegisterSchemasPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
Expand All @@ -38,8 +35,11 @@ public function process(ContainerBuilder $container)
foreach ($taggedServicesIds as $id => $tags) {
foreach ($tags as $attributes) {
if (!isset($attributes['alias'])) {
throw new \InvalidArgumentException(sprintf('Service "%s" must define the "alias" attribute on "sylius.settings_schema" tags.', $id));
throw new \InvalidArgumentException(
sprintf('Service "%s" must define the "alias" attribute on "sylius.settings_schema" tags.', $id)
);
}

$schemaRegistry->addMethodCall('register', [$attributes['alias'], new Reference($id)]);
}
}
Expand Down
7 changes: 1 addition & 6 deletions DependencyInjection/Configuration.php
Expand Up @@ -21,14 +21,9 @@
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This class contains the configuration information for the bundle.
*
* This information is solely responsible for how the different configuration
* sections are normalized, and merged.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class Configuration implements ConfigurationInterface
final class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
Expand Down
8 changes: 4 additions & 4 deletions Exception/ParameterNotFoundException.php
Expand Up @@ -14,17 +14,17 @@
/**
* @author Steffen Brem <steffenbrem@gmail.com>
*/
class ParameterNotFoundException extends \InvalidArgumentException
final class ParameterNotFoundException extends \InvalidArgumentException
{
/**
* @param string $parameter
* @param int $code
* @param Exception $previous
* @param \Exception|null $previousException
*/
public function __construct($parameter, $code = 0, \Exception $previous = null)
public function __construct($parameter, $code = 0, \Exception $previousException = null)
{
$message = sprintf('Parameter with name "%s" does not exist.', $parameter);

parent::__construct($message, $code, $previous);
parent::__construct($message, $code, $previousException);
}
}
2 changes: 1 addition & 1 deletion Form/Factory/SettingsFormFactoryInterface.php
Expand Up @@ -20,7 +20,7 @@ interface SettingsFormFactoryInterface
{
/**
* @param string $schemaAlias
* @param null|mixed $data
* @param mixed|null $data
* @param array $options
*
* @return FormInterface
Expand Down
3 changes: 1 addition & 2 deletions Manager/SettingsManager.php
Expand Up @@ -84,7 +84,6 @@ public function load($schemaAlias, $namespace = null, $ignoreUnknown = true)
/** @var SettingsResolverInterface $resolver */
$resolver = $this->resolverRegistry->get($schemaAlias);

// try to resolve settings for schema alias and namespace
$settings = $resolver->resolve($schemaAlias, $namespace);

if (!$settings) {
Expand All @@ -99,7 +98,7 @@ public function load($schemaAlias, $namespace = null, $ignoreUnknown = true)
$schema->buildSettings($settingsBuilder);

// Remove unknown settings' parameters (e.g. From a previous version of the settings schema)
if (true === $ignoreUnknown) {
if ($ignoreUnknown) {
foreach ($parameters as $name => $value) {
if (!$settingsBuilder->isDefined($name)) {
unset($parameters[$name]);
Expand Down
3 changes: 0 additions & 3 deletions Resolver/DefaultSettingsResolver.php
Expand Up @@ -15,9 +15,6 @@
use Sylius\Component\Resource\Repository\RepositoryInterface;

/**
* Default implementation that resolves settings in the simplest way possible. It tries to find a schema by it's name
* and optionally the given namespace.
*
* @author Steffen Brem <steffenbrem@gmail.com>
*/
final class DefaultSettingsResolver implements SettingsResolverInterface
Expand Down
4 changes: 1 addition & 3 deletions Resolver/ResolverServiceRegistry.php
Expand Up @@ -11,14 +11,12 @@

namespace Sylius\Bundle\SettingsBundle\Resolver;

use Sylius\Component\Registry\NonExistingServiceException;
use Sylius\Component\Registry\ServiceRegistry;
use Sylius\Component\Registry\ServiceRegistryInterface;

/**
* @author Steffen Brem <steffenbrem@gmail.com>
*/
/* final */class ResolverServiceRegistry implements ServiceRegistryInterface
final class ResolverServiceRegistry implements ServiceRegistryInterface
{
/**
* @var ServiceRegistryInterface
Expand Down
6 changes: 0 additions & 6 deletions Resources/config/routing.yml

This file was deleted.

21 changes: 8 additions & 13 deletions Resources/config/services.xml
Expand Up @@ -12,24 +12,19 @@
-->

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="sylius.settings.schema_interface">Sylius\Bundle\SettingsBundle\Schema\SchemaInterface</parameter>
<parameter key="sylius.settings.resolver_interface">Sylius\Bundle\SettingsBundle\Resolver\SettingsResolverInterface</parameter>
</parameters>

<services>
<service id="sylius.controller.settings" class="Sylius\Bundle\SettingsBundle\Controller\SettingsController">
<call method="setContainer">
<argument type="service" id="service_container" />
</call>
</service>

<service id="sylius.settings.form_factory" class="Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory">
<service id="sylius.form_factory.settings" class="Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory">
<argument type="service" id="sylius.registry.settings_schema" />
<argument type="service" id="form.factory" />
</service>

<service id="sylius.settings.manager" class="Sylius\Bundle\SettingsBundle\Manager\SettingsManager">
<service id="sylius.manager.settings" class="Sylius\Bundle\SettingsBundle\Manager\SettingsManager">
<argument type="service" id="sylius.registry.settings_schema" />
<argument type="service" id="sylius.registry.settings_resolver" />
<argument type="service" id="sylius.manager.settings" />
Expand All @@ -38,33 +33,33 @@
</service>

<service id="sylius.registry.settings_schema" class="Sylius\Component\Registry\ServiceRegistry" lazy="true">
<argument>%sylius.settings.schema_interface%</argument>
<argument>Sylius\Bundle\SettingsBundle\Schema\SchemaInterface</argument>
<argument>Settings schema</argument>
</service>

<service id="sylius.registry.settings_resolver" class="Sylius\Bundle\SettingsBundle\Resolver\ResolverServiceRegistry" lazy="true">
<argument type="service">
<service class="Sylius\Component\Registry\ServiceRegistry">
<argument>%sylius.settings.resolver_interface%</argument>
<argument>Sylius\Bundle\SettingsBundle\Resolver\SettingsResolverInterface</argument>
<argument>Settings resolver</argument>
</service>
</argument>
<argument type="service" id="sylius.settings.default_resolver"/>
<argument type="service" id="sylius.settings_resolver.default"/>
</service>

<service id="sylius.settings.default_resolver" class="Sylius\Bundle\SettingsBundle\Resolver\DefaultSettingsResolver">
<service id="sylius.settings_resolver.default" class="Sylius\Bundle\SettingsBundle\Resolver\DefaultSettingsResolver">
<argument type="service" id="sylius.repository.settings" />
</service>

<service id="sylius.settings.doctrine.transform_settings_listener" class="Sylius\Bundle\SettingsBundle\Doctrine\EventListener\ParameterTransformerListener">
<service id="sylius.doctrine.settings_parameter_transformer_listener" class="Sylius\Bundle\SettingsBundle\Doctrine\EventListener\ParameterTransformerListener">
<argument type="service" id="service_container"/>
<tag name="doctrine.event_listener" event="onFlush"/>
<tag name="doctrine.event_listener" event="postFlush"/>
<tag name="doctrine.event_listener" event="postLoad"/>
</service>

<service id="sylius.templating.helper.settings" class="Sylius\Bundle\SettingsBundle\Templating\Helper\SettingsHelper">
<argument type="service" id="sylius.settings.manager" />
<argument type="service" id="sylius.manager.settings" />
<tag name="templating.helper" alias="sylius_settings" />
</service>

Expand Down
10 changes: 4 additions & 6 deletions Schema/SettingsBuilder.php
Expand Up @@ -27,18 +27,16 @@ class SettingsBuilder extends OptionsResolver implements SettingsBuilderInterfac
/**
* {@inheritdoc}
*/
public function setTransformer($parameterName, ParameterTransformerInterface $transformer)
public function getTransformers()
{
$this->transformers[$parameterName] = $transformer;

return $this;
return $this->transformers;
}

/**
* {@inheritdoc}
*/
public function getTransformers()
public function setTransformer($parameterName, ParameterTransformerInterface $transformer)
{
return $this->transformers;
$this->transformers[$parameterName] = $transformer;
}
}
2 changes: 0 additions & 2 deletions SyliusSettingsBundle.php
Expand Up @@ -18,8 +18,6 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Settings system for ecommerce Symfony2 applications.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class SyliusSettingsBundle extends AbstractResourceBundle
Expand Down
4 changes: 0 additions & 4 deletions Transformer/ParameterTransformerInterface.php
Expand Up @@ -17,17 +17,13 @@
interface ParameterTransformerInterface
{
/**
* Transform the parameter into format which is suitable for storage.
*
* @param mixed $value
*
* @return mixed
*/
public function transform($value);

/**
* Transform parameter value back into it's original form.
*
* @param mixed $value
*
* @return mixed
Expand Down
17 changes: 10 additions & 7 deletions spec/Form/Factory/SettingsFormFactorySpec.php
Expand Up @@ -12,14 +12,17 @@
namespace spec\Sylius\Bundle\SettingsBundle\Form\Factory;

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory;
use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactoryInterface;
use Sylius\Bundle\SettingsBundle\Schema\SchemaInterface;
use Sylius\Component\Registry\ServiceRegistryInterface;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;

/**
* @mixin SettingsFormFactory
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
final class SettingsFormFactorySpec extends ObjectBehavior
Expand All @@ -33,20 +36,20 @@ function let(

function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory');
$this->shouldHaveType(SettingsFormFactory::class);
}

function it_should_implement_settings_form_factory_interface()
function it_implements_settings_form_factory_interface()
{
$this->shouldImplement(SettingsFormFactoryInterface::class);
}

function it_should_create_a_form_for_given_schema_namespace(
$schemaRegistry,
SchemaInterface $schema,
$formFactory,
FormInterface $form,
FormBuilder $formBuilder,
Form $form
FormFactoryInterface $formFactory,
SchemaInterface $schema,
ServiceRegistryInterface $schemaRegistry
) {
$schemaRegistry->get('sylius_general')->willReturn($schema);
$formFactory->createBuilder('form', null, ['data_class' => null])->willReturn($formBuilder);
Expand Down
7 changes: 5 additions & 2 deletions spec/Manager/SettingsManagerSpec.php
Expand Up @@ -13,12 +13,15 @@

use Doctrine\Common\Persistence\ObjectManager;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\SettingsBundle\Manager\SettingsManager;
use Sylius\Bundle\SettingsBundle\Manager\SettingsManagerInterface;
use Sylius\Component\Registry\ServiceRegistryInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* @mixin SettingsManager
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
final class SettingsManagerSpec extends ObjectBehavior
Expand All @@ -41,10 +44,10 @@ function let(

function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\SettingsBundle\Manager\SettingsManager');
$this->shouldHaveType(SettingsManager::class);
}

function it_should_be_a_Sylius_settings_manager()
function it_should_be_a_settings_manager()
{
$this->shouldImplement(SettingsManagerInterface::class);
}
Expand Down
10 changes: 5 additions & 5 deletions spec/Model/SettingsSpec.php
Expand Up @@ -13,16 +13,19 @@

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\SettingsBundle\Exception\ParameterNotFoundException;
use Sylius\Bundle\SettingsBundle\Model\Settings;
use Sylius\Bundle\SettingsBundle\Model\SettingsInterface;

/**
* @mixin Settings
*
* @author Steffen Brem <steffenbrem@gmail.com>
*/
final class SettingsSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\SettingsBundle\Model\Settings');
$this->shouldHaveType(Settings::class);
}

function it_implements_settings_interface()
Expand Down Expand Up @@ -78,10 +81,7 @@ function its_parameters_has_empty_array_by_default()
function it_can_set_a_parameter()
{
$this->set('key', 'value');
$this->getParameters()->shouldReturn([
'key' => 'value',
])
;
$this->getParameters()->shouldReturn(['key' => 'value']);
}

function it_throws_parameter_not_found_exception_when_getting_non_existing_parameter()
Expand Down

0 comments on commit b0b5f2a

Please sign in to comment.