mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
Introduce resource metadata
This commit is contained in:
parent
5434de22a5
commit
6be08f847f
86 changed files with 2096 additions and 1769 deletions
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\AddressingBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
|
|
@ -29,13 +31,19 @@ class SyliusAddressingExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS | self::CONFIGURE_TRANSLATIONS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.scope.zone', $config['scopes']);
|
||||
|
||||
$container
|
||||
|
|
|
|||
|
|
@ -65,26 +65,6 @@ class Configuration implements ConfigurationInterface
|
|||
->arrayNode('resources')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->arrayNode('api')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->arrayNode('classes')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('controller')->isRequired()->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('validation_groups')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->arrayNode('default')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius'))
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('api_user')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
|
|
|
|||
|
|
@ -12,9 +12,11 @@
|
|||
namespace Sylius\Bundle\ApiBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Api extension.
|
||||
|
|
@ -23,21 +25,23 @@ use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
|||
*/
|
||||
class SyliusApiExtension extends AbstractResourceExtension implements PrependExtensionInterface
|
||||
{
|
||||
protected $configFiles = array(
|
||||
'services.xml'
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml'
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,13 +56,14 @@ class SyliusApiExtension extends AbstractResourceExtension implements PrependExt
|
|||
}
|
||||
|
||||
$config = $this->processConfiguration(new Configuration(), $container->getExtensionConfig($this->getAlias()));
|
||||
$resourcesConfig = $config['resources'];
|
||||
|
||||
$container->prependExtensionConfig('fos_oauth_server', array(
|
||||
'db_driver' => 'orm',
|
||||
'client_class' => $config['resources']['api_client']['classes']['model'],
|
||||
'access_token_class' => $config['resources']['api_access_token']['classes']['model'],
|
||||
'refresh_token_class' => $config['resources']['api_refresh_token']['classes']['model'],
|
||||
'auth_code_class' => $config['resources']['api_auth_code']['classes']['model'],
|
||||
'client_class' => $resourcesConfig['api_client']['classes']['model'],
|
||||
'access_token_class' => $resourcesConfig['api_access_token']['classes']['model'],
|
||||
'refresh_token_class' => $resourcesConfig['api_refresh_token']['classes']['model'],
|
||||
'auth_code_class' => $resourcesConfig['api_auth_code']['classes']['model'],
|
||||
|
||||
'service' => array(
|
||||
'user_provider' => 'sylius.user_provider.name_or_email',
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@
|
|||
namespace Sylius\Bundle\ArchetypeBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
|
|
@ -28,68 +30,83 @@ class SyliusArchetypeExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_TRANSLATIONS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $this->resolveResources($config['resources'], $container), $container);
|
||||
|
||||
foreach ($config['resources'] as $subjectName => $subjectConfig) {
|
||||
foreach ($subjectConfig as $resourceName => $resourceConfig) {
|
||||
if (!is_array($resourceConfig)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$formDefinition = $container->getDefinition('sylius.form.type.'.$subjectName.'_'.$resourceName);
|
||||
$formDefinition->addArgument($subjectName);
|
||||
|
||||
if (isset($resourceConfig['translation'])) {
|
||||
$formTranslationDefinition = $container->getDefinition('sylius.form.type.'.$subjectName.'_'.$resourceName.'_translation');
|
||||
$formTranslationDefinition->addArgument($subjectName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($config['resources'] as $resource => $parameters) {
|
||||
$formDefinition = $container->getDefinition('sylius.form.type.'.$resource);
|
||||
$formDefinition->addArgument($parameters['subject']);
|
||||
|
||||
if (isset($parameters['translation'])) {
|
||||
$formTranslationDefinition = $container->getDefinition('sylius.form.type.'.$resource.'_translation');
|
||||
$formTranslationDefinition->addArgument($parameters['subject']);
|
||||
}
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Resolve resources for every subject.
|
||||
*
|
||||
* @param array $resources
|
||||
* @param ContainerBuilder $container
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function process(array $config, ContainerBuilder $container)
|
||||
private function resolveResources(array $resources, ContainerBuilder $container)
|
||||
{
|
||||
$subjects = array();
|
||||
$convertedConfig = array();
|
||||
|
||||
foreach ($config['resources'] as $resource => $parameters) {
|
||||
$subjects[$resource] = $parameters;
|
||||
unset($parameters['subject'], $parameters['attribute'], $parameters['option']);
|
||||
|
||||
foreach ($parameters as $parameter => $classes) {
|
||||
$convertedConfig[$resource.'_'.$parameter] = $classes;
|
||||
$convertedConfig[$resource.'_'.$parameter]['subject'] = $resource;
|
||||
|
||||
if (!isset($classes['validation_groups'])) {
|
||||
$classes['validation_groups']['default'] = array('sylius');
|
||||
}
|
||||
}
|
||||
|
||||
$this->createSubjectServices($container, $resource);
|
||||
foreach ($resources as $subject => $parameters) {
|
||||
$subjects[$subject] = $parameters;
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.archetype.subjects', $subjects);
|
||||
|
||||
$config['resources'] = $convertedConfig;
|
||||
$resolvedResources = array();
|
||||
|
||||
return parent::process($config, $container);
|
||||
foreach ($resources as $subjectName => $subjectConfig) {
|
||||
$this->createPrototypeBuilder($container, $subjectName);
|
||||
|
||||
foreach ($subjectConfig as $resourceName => $resourceConfig) {
|
||||
if (is_array($resourceConfig)) {
|
||||
$resolvedResources[$subjectName.'_'.$resourceName] = $resourceConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $resolvedResources;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create services for every subject.
|
||||
* Create prototype builder for subject.
|
||||
*
|
||||
* @param ContainerBuilder $container
|
||||
* @param string $subject
|
||||
* @param string $subjectName
|
||||
*/
|
||||
private function createSubjectServices(ContainerBuilder $container, $subject)
|
||||
private function createPrototypeBuilder(ContainerBuilder $container, $subjectName)
|
||||
{
|
||||
$builderDefintion = new Definition('Sylius\Component\Archetype\Builder\ArchetypeBuilder');
|
||||
$builderDefintion
|
||||
->setArguments(array(new Reference(sprintf('sylius.factory.%s_attribute_value', $subject))))
|
||||
->setArguments(array(new Reference(sprintf('sylius.factory.%s_attribute_value', $subjectName))))
|
||||
;
|
||||
|
||||
$container->setDefinition('sylius.builder.'.$subject.'_archetype', $builderDefintion);
|
||||
$container->setDefinition('sylius.builder.' . $subjectName . '_archetype', $builderDefintion);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
namespace Sylius\Bundle\ArchetypeBundle\Form\EventListener;
|
||||
|
||||
use Sylius\Component\Archetype\Model\ArchetypeInterface;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ class ParentArchetypeListener implements EventSubscriberInterface
|
|||
->createQueryBuilder('o')
|
||||
->where('o.id != :id')
|
||||
->setParameter('id', $currentArchetype->getId())
|
||||
;
|
||||
;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@
|
|||
namespace Sylius\Bundle\AttributeBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Attribute extension.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class SyliusAttributeExtension extends AbstractResourceExtension
|
||||
|
|
@ -26,49 +26,64 @@ class SyliusAttributeExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config, new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_TRANSLATIONS | self::CONFIGURE_FORMS
|
||||
);
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
foreach ($config['resources'] as $resource => $parameters) {
|
||||
$formDefinition = $container->getDefinition('sylius.form.type.'.$resource);
|
||||
$formDefinition->addArgument($parameters['subject']);
|
||||
$this->registerResources('sylius', $config['driver'], $this->resolveResources($config['resources'], $container), $container);
|
||||
|
||||
if (isset($parameters['translation'])) {
|
||||
$formTranslationDefinition = $container->getDefinition('sylius.form.type.'.$resource.'_translation');
|
||||
$formTranslationDefinition->addArgument($parameters['subject']);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($config['resources'] as $subjectName => $subjectConfig) {
|
||||
foreach ($subjectConfig as $resourceName => $resourceConfig) {
|
||||
if (!is_array($resourceConfig)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$subjects = array();
|
||||
$convertedConfig = array();
|
||||
$formDefinition = $container->getDefinition('sylius.form.type.'.$subjectName.'_'.$resourceName);
|
||||
$formDefinition->addArgument($subjectName);
|
||||
|
||||
foreach ($config['resources'] as $resource => $parameters) {
|
||||
$subjects[$resource] = $parameters;
|
||||
unset($parameters['subject']);
|
||||
|
||||
foreach ($parameters as $parameter => $classes) {
|
||||
$convertedConfig[$resource.'_'.$parameter] = $classes;
|
||||
$convertedConfig[$resource.'_'.$parameter]['subject'] = $resource;
|
||||
|
||||
if (!isset($classes['validation_groups'])) {
|
||||
$classes['validation_groups']['default'] = array('sylius');
|
||||
if (isset($resourceConfig['translation'])) {
|
||||
$formTranslationDefinition = $container->getDefinition('sylius.form.type.'.$subjectName.'_'.$resourceName.'_translation');
|
||||
$formTranslationDefinition->addArgument($subjectName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve resources for every subject.
|
||||
*
|
||||
* @param array $resources
|
||||
* @param ContainerBuilder $container
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function resolveResources(array $resources, ContainerBuilder $container)
|
||||
{
|
||||
$subjects = array();
|
||||
|
||||
foreach ($resources as $subject => $parameters) {
|
||||
$subjects[$subject] = $parameters;
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.attribute.subjects', $subjects);
|
||||
|
||||
$config['resources'] = $convertedConfig;
|
||||
$resolvedResources = array();
|
||||
|
||||
return parent::process($config, $container);
|
||||
foreach ($resources as $subjectName => $subjectConfig) {
|
||||
foreach ($subjectConfig as $resourceName => $resourceConfig) {
|
||||
if (is_array($resourceConfig)) {
|
||||
$resolvedResources[$subjectName.'_'.$resourceName] = $resourceConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $resolvedResources;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,10 +12,15 @@
|
|||
namespace Sylius\Bundle\CartBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\CartBundle\Controller\CartController;
|
||||
use Sylius\Bundle\CartBundle\Form\Type\CartType;
|
||||
use Sylius\Bundle\CartBundle\Controller\CartItemController;
|
||||
use Sylius\Bundle\CartBundle\Form\Type\CartItemType;
|
||||
use Sylius\Bundle\CartBundle\Form\Type\CartType;
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Sylius\Component\Cart\Model\Cart;
|
||||
use Sylius\Component\Cart\Model\CartInterface;
|
||||
use Sylius\Component\Cart\Model\CartItem;
|
||||
use Sylius\Component\Cart\Model\CartItemInterface;
|
||||
use Sylius\Component\Resource\Factory\Factory;
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
|
@ -42,6 +47,7 @@ class Configuration implements ConfigurationInterface
|
|||
$rootNode
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->cannotBeEmpty()->end()
|
||||
->scalarNode('provider')->defaultValue('sylius.cart_provider.default')->end()
|
||||
->scalarNode('resolver')->isRequired()->cannotBeEmpty()->end()
|
||||
->scalarNode('storage')->defaultValue('sylius.storage.session')->end()
|
||||
|
|
@ -70,8 +76,16 @@ class Configuration implements ConfigurationInterface
|
|||
->arrayNode('classes')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('model')->defaultValue(Cart::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('interface')->defaultValue(CartInterface::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('controller')->defaultValue(CartController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('form')->defaultValue(CartType::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
|
||||
->arrayNode('form')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('default')->defaultValue(CartType::class)->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('validation_groups')
|
||||
|
|
@ -85,13 +99,21 @@ class Configuration implements ConfigurationInterface
|
|||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('item')
|
||||
->arrayNode('cart_item')
|
||||
->children()
|
||||
->arrayNode('classes')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('model')->defaultValue(CartItem::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('interface')->defaultValue(CartItemInterface::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('controller')->defaultValue(CartItemController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('form')->defaultValue(CartItemType::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
|
||||
->arrayNode('form')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('default')->defaultValue(CartItemType::class)->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('validation_groups')
|
||||
|
|
|
|||
|
|
@ -12,48 +12,61 @@
|
|||
namespace Sylius\Bundle\CartBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Sylius\Component\Cart\Model\Cart;
|
||||
use Sylius\Component\Cart\Model\CartItem;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Carts extension.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Saša Stamenković <umpirsky@gmail.com>
|
||||
* @author Jérémy Leherpeur <jeremy@leherpeur.net>
|
||||
*/
|
||||
class SyliusCartExtension extends AbstractResourceExtension implements PrependExtensionInterface
|
||||
{
|
||||
protected $configFiles = array(
|
||||
'services.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure($config, new Configuration(), $container);
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setAlias('sylius.cart_provider', $config['provider']);
|
||||
$container->setAlias('sylius.cart_resolver', $config['resolver']);
|
||||
|
||||
$container->setAlias('sylius.repository.cart', 'sylius.repository.order');
|
||||
$container->setAlias('sylius.factory.cart', 'sylius.factory.order');
|
||||
$container->setAlias('sylius.manager.cart', 'sylius.manager.order');
|
||||
$container->setAlias('sylius.repository.cart_item', 'sylius.repository.order_item');
|
||||
$container->setAlias('sylius.factory.cart_item', 'sylius.factory.order_item');
|
||||
$container->setAlias('sylius.manager.cart_item', 'sylius.manager.order_item');
|
||||
|
||||
$cartConfig = $config['resources']['cart'];
|
||||
$cartItemConfig = $config['resources']['cart_item'];
|
||||
|
||||
$container->setParameter('sylius.controller.cart.class', $cartConfig['classes']['controller']);
|
||||
$container->setParameter('sylius.form.type.cart.class', $cartConfig['classes']['form']['default']);
|
||||
$container->setParameter('sylius.validation_groups.cart', $cartConfig['validation_groups']);
|
||||
$container->setParameter('sylius.controller.cart_item.class', $cartItemConfig['classes']['controller']);
|
||||
$container->setParameter('sylius.form.type.cart_item.class', $cartItemConfig['classes']['form']['default']);
|
||||
$container->setParameter('sylius.validation_groups.cart_item', $cartItemConfig['validation_groups']);
|
||||
|
||||
$definition = $container->findDefinition('sylius.context.cart');
|
||||
$definition->replaceArgument(0, new Reference($config['storage']));
|
||||
|
||||
$resources = $config['resources'];
|
||||
|
||||
$container->setParameter('sylius.controller.cart.class', $resources['cart']['classes']['controller']);
|
||||
$container->setParameter('sylius.form.type.cart.class', $resources['cart']['classes']['form']);
|
||||
|
||||
$container->setParameter('sylius.controller.cart_item.class', $resources['item']['classes']['controller']);
|
||||
$container->setParameter('sylius.form.type.cart_item.class', $resources['item']['classes']['form']);
|
||||
|
||||
$container->setParameter('sylius.validation_group.cart', $resources['cart']['validation_groups']);
|
||||
$container->setParameter('sylius.validation_group.cart_item', $resources['item']['validation_groups']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,21 +75,21 @@ class SyliusCartExtension extends AbstractResourceExtension implements PrependEx
|
|||
public function prepend(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasExtension('sylius_order')) {
|
||||
return;
|
||||
throw new \RuntimeException('Please install and configure SyliusOrderBundle in order to use SyliusCartBundle.');
|
||||
}
|
||||
|
||||
$container->prependExtensionConfig('sylius_order', array(
|
||||
'resources' => array(
|
||||
'order_item' => array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Component\Cart\Model\CartItem'
|
||||
)
|
||||
),
|
||||
'order' => array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Component\Cart\Model\Cart'
|
||||
)
|
||||
)
|
||||
'model' => Cart::class,
|
||||
),
|
||||
),
|
||||
'order_item' => array(
|
||||
'classes' => array(
|
||||
'model' => CartItem::class,
|
||||
),
|
||||
),
|
||||
))
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,31 +58,22 @@
|
|||
</call>
|
||||
</service>
|
||||
|
||||
<service id="sylius.context.cart" class="%sylius.context.cart.class%">
|
||||
<argument /> <!-- Storage service name comes from config -->
|
||||
</service>
|
||||
|
||||
<service id="sylius.manager.cart" alias="sylius.manager.order" />
|
||||
<service id="sylius.manager.cart_item" alias="sylius.manager.order_item" />
|
||||
|
||||
<service id="sylius.repository.cart" alias="sylius.repository.order" />
|
||||
<service id="sylius.repository.cart_item" alias="sylius.repository.order_item" />
|
||||
|
||||
<service id="sylius.factory.cart" alias="sylius.factory.order" />
|
||||
<service id="sylius.factory.cart_item" alias="sylius.factory.order_item" />
|
||||
|
||||
<service id="sylius.form.type.cart" class="%sylius.form.type.cart.class%">
|
||||
<argument>%sylius.model.cart.class%</argument>
|
||||
<argument>%sylius.validation_group.cart%</argument>
|
||||
<argument>%sylius.validation_groups.cart%</argument>
|
||||
<tag name="form.type" alias="sylius_cart" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.form.type.cart_item" class="%sylius.form.type.cart_item.class%">
|
||||
<argument>%sylius.model.cart_item.class%</argument>
|
||||
<argument>%sylius.validation_group.cart_item%</argument>
|
||||
<argument>%sylius.validation_groups.cart_item%</argument>
|
||||
<tag name="form.type" alias="sylius_cart_item" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.context.cart" class="%sylius.context.cart.class%">
|
||||
<argument /> <!-- Storage service name comes from config -->
|
||||
</service>
|
||||
|
||||
<service id="sylius.cart_provider.default" class="%sylius.cart_provider.default.class%">
|
||||
<argument type="service" id="sylius.context.cart" />
|
||||
<argument type="service" id="sylius.factory.cart" />
|
||||
|
|
|
|||
|
|
@ -12,12 +12,14 @@
|
|||
namespace Sylius\Bundle\ChannelBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Channel extension.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class SyliusChannelExtension extends AbstractResourceExtension
|
||||
{
|
||||
|
|
@ -26,11 +28,19 @@ class SyliusChannelExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$loader->load(sprintf('driver/%s.xml', $config['driver']));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\ContactBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Contact extension.
|
||||
|
|
@ -22,18 +24,22 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|||
*/
|
||||
class SyliusContactExtension extends AbstractResourceExtension
|
||||
{
|
||||
protected $configFiles = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS | self::CONFIGURE_TRANSLATIONS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
// ...
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
namespace Sylius\Bundle\ContentBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Content extension.
|
||||
|
|
@ -23,24 +23,22 @@ use Symfony\Component\DependencyInjection\Reference;
|
|||
*/
|
||||
class SyliusContentExtension extends AbstractResourceExtension
|
||||
{
|
||||
protected $configFiles = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
// ...
|
||||
);
|
||||
|
||||
$imagineBlock = $container->getDefinition('sylius.form.type.imagine_block');
|
||||
$imagineBlock->addArgument(new Reference('liip_imagine.filter.configuration'));
|
||||
|
||||
$imagineBlock = $container->getDefinition('sylius.form.type.menu');
|
||||
$imagineBlock->addArgument(new Parameter('cmf_menu.persistence.phpcr.menu_basepath'));
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@
|
|||
namespace Sylius\Bundle\CoreBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
|
|
@ -55,46 +57,36 @@ class SyliusCoreExtension extends AbstractResourceExtension implements PrependEx
|
|||
'sylius_rbac',
|
||||
);
|
||||
|
||||
protected $configFiles = array(
|
||||
'services.xml',
|
||||
'controller.xml',
|
||||
'form.xml',
|
||||
'api_form.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
'reports.xml',
|
||||
'email.xml',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
'controller.xml',
|
||||
'form.xml',
|
||||
'api_form.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
'reports.xml',
|
||||
'state_machine.xml',
|
||||
'email.xml',
|
||||
);
|
||||
|
||||
$this->loadServiceDefinitions($container, 'state_machine.xml');
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$this->loadCheckoutConfiguration($config['checkout'], $container);
|
||||
|
||||
$definition = $container->findDefinition('sylius.context.currency');
|
||||
$definition->replaceArgument(0, new Reference($config['currency_storage']));
|
||||
|
||||
$this->addClassesToCompile(array(
|
||||
'Symfony\Component\Config\Resource\FileResource',
|
||||
'Symfony\Component\HttpKernel\Config\FileLocator',
|
||||
'Symfony\Component\Config\Resource\DirectoryResource',
|
||||
'Symfony\Bundle\AsseticBundle\Config\AsseticResource',
|
||||
'Symfony\Bundle\AsseticBundle\Factory\Resource\FileResource',
|
||||
'Symfony\Bundle\FrameworkBundle\Templating\TemplateReference',
|
||||
'Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator',
|
||||
'Symfony\Bundle\FrameworkBundle\Templating\Loader\FilesystemLoader'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -111,6 +103,7 @@ class SyliusCoreExtension extends AbstractResourceExtension implements PrependEx
|
|||
}
|
||||
|
||||
$routeClasses = $controllerByClasses = $repositoryByClasses = $syliusByClasses = array();
|
||||
|
||||
foreach ($config['routing'] as $className => $routeConfig) {
|
||||
$routeClasses[$className] = array(
|
||||
'field' => $routeConfig['field'],
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@ imports:
|
|||
twig:
|
||||
exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'
|
||||
|
||||
doctrine_cache: ~
|
||||
doctrine_cache:
|
||||
providers:
|
||||
sylius_settings: %sylius.cache%
|
||||
sylius_rbac: %sylius.cache%
|
||||
|
||||
knp_gaufrette:
|
||||
adapters:
|
||||
|
|
|
|||
|
|
@ -51,12 +51,14 @@ sylius_channel:
|
|||
sylius_cart:
|
||||
resolver: sylius.cart_item_resolver.default
|
||||
resources:
|
||||
item:
|
||||
classes:
|
||||
form: Sylius\Bundle\CoreBundle\Form\Type\CartItemType
|
||||
cart:
|
||||
classes:
|
||||
form: Sylius\Bundle\CoreBundle\Form\Type\CartType
|
||||
form:
|
||||
default: Sylius\Bundle\CoreBundle\Form\Type\CartType
|
||||
cart_item:
|
||||
classes:
|
||||
form:
|
||||
default: Sylius\Bundle\CoreBundle\Form\Type\CartItemType
|
||||
|
||||
sylius_settings: ~
|
||||
|
||||
|
|
@ -155,11 +157,13 @@ sylius_promotion:
|
|||
classes:
|
||||
model: Sylius\Component\Core\Model\Promotion
|
||||
repository: Sylius\Bundle\CoreBundle\Doctrine\ORM\PromotionRepository
|
||||
form: Sylius\Bundle\CoreBundle\Form\Type\PromotionType
|
||||
form:
|
||||
default: Sylius\Bundle\CoreBundle\Form\Type\PromotionType
|
||||
promotion_coupon:
|
||||
classes:
|
||||
model: Sylius\Component\Core\Model\Coupon
|
||||
form: Sylius\Bundle\CoreBundle\Form\Type\CouponType
|
||||
form:
|
||||
default: Sylius\Bundle\CoreBundle\Form\Type\CouponType
|
||||
|
||||
sylius_inventory:
|
||||
backorders: %sylius.inventory.backorders_enabled%
|
||||
|
|
@ -764,16 +768,15 @@ sylius_rbac:
|
|||
it: [security_auditor, developer]
|
||||
|
||||
sylius_user:
|
||||
templates:
|
||||
user: SyliusWebBundle:Frontend/User
|
||||
customer: SyliusWebBundle:Frontend/Customer
|
||||
resources:
|
||||
user:
|
||||
templates: SyliusWebBundle:Frontend/User
|
||||
classes:
|
||||
model: Sylius\Component\Core\Model\User
|
||||
form:
|
||||
default: Sylius\Bundle\CoreBundle\Form\Type\UserType
|
||||
customer:
|
||||
templates: SyliusWebBundle:Frontend/Customer
|
||||
classes:
|
||||
model: Sylius\Component\Core\Model\Customer
|
||||
controller: Sylius\Bundle\CoreBundle\Controller\CustomerController
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
</service>
|
||||
<service id="sylius.checkout_form.shipping" class="%sylius.checkout_form.shipping.class%">
|
||||
<argument>%sylius.model.order.class%</argument>
|
||||
<argument>%sylius.validation_group.order%</argument>
|
||||
<argument>%sylius.validation_groups.order%</argument>
|
||||
<argument type="service" id="sylius.context.channel"/>
|
||||
<tag name="form.type" alias="sylius_checkout_shipping" />
|
||||
</service>
|
||||
|
|
@ -69,14 +69,14 @@
|
|||
</service>
|
||||
<service id="sylius.checkout_form.payment" class="%sylius.checkout_form.payment.class%">
|
||||
<argument>%sylius.model.order.class%</argument>
|
||||
<argument>%sylius.validation_group.order%</argument>
|
||||
<argument>%sylius.validation_groups.order%</argument>
|
||||
<argument type="service" id="sylius.context.channel" />
|
||||
<tag name="form.type" alias="sylius_checkout_payment" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.form.type.cart" class="%sylius.form.type.cart.class%">
|
||||
<argument>%sylius.model.cart.class%</argument>
|
||||
<argument>%sylius.validation_group.cart%</argument>
|
||||
<argument>%sylius.validation_groups.cart%</argument>
|
||||
<argument type="service" id="sylius.factory.promotion_coupon" />
|
||||
<tag name="form.type" alias="sylius_cart" />
|
||||
</service>
|
||||
|
|
@ -130,38 +130,38 @@
|
|||
|
||||
<!-- promotions -->
|
||||
<service id="sylius.form.type.promotion_rule.nth_order_configuration" class="%sylius.form.type.promotion_rule.nth_order_configuration.class%">
|
||||
<argument>%sylius.validation_group.promotion_rule_nth_order_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_rule_nth_order_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion_rule_nth_order_configuration" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_rule.customer_loyalty_configuration" class="%sylius.form.type.promotion_rule.customer_loyalty_configuration.class%">
|
||||
<argument>%sylius.validation_group.promotion_rule_customer_loyalty_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_rule_customer_loyalty_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion_rule_customer_loyalty_configuration" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_rule.shipping_country_configuration" class="%sylius.form.type.promotion_rule.shipping_country_configuration.class%">
|
||||
<argument>%sylius.model.country.class%</argument>
|
||||
<argument>%sylius.validation_group.promotion_rule_shipping_country_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_rule_shipping_country_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion_rule_shipping_country_configuration" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_rule.taxonomy_configuration" class="%sylius.form.type.promotion_rule.taxonomy_configuration.class%">
|
||||
<argument>%sylius.validation_group.promotion_rule_taxonomy_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_rule_taxonomy_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion_rule_taxonomy_configuration" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_rule.contains_product_configuration" class="%sylius.form.type.promotion_rule.contains_product_configuration.class%">
|
||||
<argument>%sylius.validation_group.promotion_rule_contains_product_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_rule_contains_product_configuration%</argument>
|
||||
<argument type="service" id="sylius.repository.product_variant" />
|
||||
<tag name="form.type" alias="sylius_promotion_rule_contains_product_configuration" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_rule.customer_group_configuration" class="%sylius.form.type.promotion_rule.customer_group_configuration.class%">
|
||||
<argument>%sylius.validation_group.promotion_rule_customer_group_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_rule_customer_group_configuration%</argument>
|
||||
<argument type="service" id="sylius.repository.group" />
|
||||
<tag name="form.type" alias="sylius_promotion_rule_customer_group_configuration" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_action.shipping_discount_configuration" class="%sylius.form.type.promotion_action.shipping_discount_configuration.class%">
|
||||
<argument>%sylius.validation_group.promotion_action_shipping_discount_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_action_shipping_discount_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion_action_shipping_discount_configuration" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_action.add_product_configuration" class="%sylius.form.type.promotion_action.add_product_configuration.class%">
|
||||
<argument>%sylius.validation_group.promotion_action_add_product_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_action_add_product_configuration%</argument>
|
||||
<argument type="service" id="sylius.repository.product_variant" />
|
||||
<tag name="form.type" alias="sylius_promotion_action_add_product_configuration" />
|
||||
</service>
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@
|
|||
|
||||
namespace Sylius\Bundle\CurrencyBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\CurrencyBundle\Controller\CurrencyController;
|
||||
use Sylius\Bundle\CurrencyBundle\Form\Type\CurrencyType;
|
||||
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
|
||||
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceChoiceType;
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Sylius\Component\Resource\Factory\Factory;
|
||||
use Sylius\Component\Currency\Model\Currency;
|
||||
use Sylius\Component\Currency\Model\CurrencyInterface;
|
||||
use Sylius\Component\Resource\Factory\Factory;
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
|
@ -65,7 +65,7 @@ class Configuration implements ConfigurationInterface
|
|||
->children()
|
||||
->scalarNode('model')->defaultValue(Currency::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('interface')->defaultValue(CurrencyInterface::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('controller')->defaultValue(CurrencyController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('repository')->cannotBeEmpty()->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->end()
|
||||
->arrayNode('form')
|
||||
|
|
|
|||
|
|
@ -12,34 +12,38 @@
|
|||
namespace Sylius\Bundle\CurrencyBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Currency extension.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class SyliusCurrencyExtension extends AbstractResourceExtension
|
||||
{
|
||||
protected $configFiles = array(
|
||||
'services.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$definition = $container->findDefinition('sylius.context.currency');
|
||||
$definition->replaceArgument(0, new Reference($config['storage']));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\InventoryBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Inventory extension.
|
||||
|
|
@ -22,24 +24,26 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|||
*/
|
||||
class SyliusInventoryExtension extends AbstractResourceExtension
|
||||
{
|
||||
protected $configFiles = array(
|
||||
'services.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'twig.xml',
|
||||
'templating.xml',
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.backorders', $config['backorders']);
|
||||
|
||||
$container->setAlias('sylius.availability_checker', $config['checker']);
|
||||
|
|
@ -47,6 +51,7 @@ class SyliusInventoryExtension extends AbstractResourceExtension
|
|||
|
||||
if (isset($config['events'])) {
|
||||
$listenerDefinition = $container->getDefinition('sylius.listener.inventory');
|
||||
|
||||
foreach ($config['events'] as $event) {
|
||||
$listenerDefinition->addTag(
|
||||
'kernel.event_listener',
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@
|
|||
|
||||
namespace Sylius\Bundle\LocaleBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Sylius\Component\Resource\Factory\Factory;
|
||||
use Sylius\Bundle\LocaleBundle\Controller\LocaleController;
|
||||
use Sylius\Bundle\LocaleBundle\Form\Type\LocaleChoiceType;
|
||||
use Sylius\Bundle\LocaleBundle\Form\Type\LocaleType;
|
||||
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceChoiceType;
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Sylius\Component\Locale\Model\Locale;
|
||||
use Sylius\Component\Locale\Model\LocaleInterface;
|
||||
use Sylius\Component\Resource\Factory\Factory;
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
|
@ -77,7 +77,7 @@ class Configuration implements ConfigurationInterface
|
|||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('default')->defaultValue(LocaleType::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('choice')->defaultValue(ResourceChoiceType::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('choice')->defaultValue(LocaleChoiceType::class)->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
|
|
|||
|
|
@ -12,32 +12,36 @@
|
|||
namespace Sylius\Bundle\LocaleBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class SyliusLocaleExtension extends AbstractResourceExtension
|
||||
{
|
||||
protected $configFiles = array(
|
||||
'services.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$definition = $container->findDefinition('sylius.context.locale');
|
||||
$definition->replaceArgument(0, new Reference($config['storage']));
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\MailerBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Mailer extension.
|
||||
|
|
@ -28,13 +30,19 @@ class SyliusMailerExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setAlias('sylius.email_sender.adapter', $config['sender_adapter']);
|
||||
$container->setAlias('sylius.email_renderer.adapter', $config['renderer_adapter']);
|
||||
|
||||
|
|
|
|||
|
|
@ -150,6 +150,7 @@ class Configuration implements ConfigurationInterface
|
|||
->children()
|
||||
->scalarNode('model')->defaultValue(Identity::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('interface')->defaultValue(IdentityInterface::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->end()
|
||||
->end()
|
||||
->end()
|
||||
|
|
|
|||
|
|
@ -12,10 +12,12 @@
|
|||
namespace Sylius\Bundle\OrderBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Order extension.
|
||||
* Sylius orders system extension.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
|
|
@ -26,13 +28,18 @@ class SyliusOrderExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
sprintf('driver/%s.xml', $config['driver'])
|
||||
);
|
||||
|
||||
$container->setParameter('sylius.order.allow_guest_order', $config['guest_order']);
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,10 +115,12 @@ class Configuration implements ConfigurationInterface
|
|||
->scalarNode('interface')->defaultValue(PaymentMethodTranslationInterface::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('repository')->cannotBeEmpty()->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
|
||||
->arrayNode('form')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('default')->defaultValue(PaymentMethodTranslationType::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('choice')->defaultValue(ResourceChoiceType::class)->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\PaymentBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
|
|
@ -27,13 +29,19 @@ class SyliusPaymentExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS | self::CONFIGURE_TRANSLATIONS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.payment_gateways', $config['gateways']);
|
||||
|
||||
$container
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\PayumBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Payum extension.
|
||||
|
|
@ -26,13 +28,19 @@ class SyliusPayumExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setParameter('payum.template.layout', $config['template']['layout']);
|
||||
$container->setParameter('payum.template.obtain_credit_card', $config['template']['obtain_credit_card']);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,27 @@
|
|||
|
||||
namespace Sylius\Bundle\ProductBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ProductBundle\Controller\VariantController;
|
||||
use Sylius\Bundle\ProductBundle\Form\Type\VariantType;
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Sylius\Component\Product\Model\Attribute;
|
||||
use Sylius\Component\Product\Model\AttributeInterface;
|
||||
use Sylius\Component\Product\Model\AttributeTranslation;
|
||||
use Sylius\Component\Product\Model\AttributeTranslationInterface;
|
||||
use Sylius\Component\Product\Model\AttributeValue;
|
||||
use Sylius\Component\Product\Model\AttributeValueInterface;
|
||||
use Sylius\Component\Product\Model\Option;
|
||||
use Sylius\Component\Product\Model\OptionInterface;
|
||||
use Sylius\Component\Product\Model\OptionTranslation;
|
||||
use Sylius\Component\Product\Model\OptionTranslationInterface;
|
||||
use Sylius\Component\Product\Model\OptionValue;
|
||||
use Sylius\Component\Product\Model\OptionValueInterface;
|
||||
use Sylius\Component\Product\Model\Variant;
|
||||
use Sylius\Component\Product\Model\VariantInterface;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Product catalog extension.
|
||||
|
|
@ -27,12 +45,18 @@ class SyliusProductExtension extends AbstractResourceExtension implements Prepen
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS | self::CONFIGURE_TRANSLATIONS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,24 +86,24 @@ class SyliusProductExtension extends AbstractResourceExtension implements Prepen
|
|||
'subject' => $config['resources']['product']['classes']['model'],
|
||||
'attribute' => array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Component\Product\Model\Attribute',
|
||||
'repository' => 'Sylius\Bundle\TranslationBundle\Doctrine\ORM\TranslatableResourceRepository',
|
||||
'model' => Attribute::class,
|
||||
'interface' => AttributeInterface::class,
|
||||
),
|
||||
'translation' => array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Component\Product\Model\AttributeTranslation',
|
||||
),
|
||||
),
|
||||
'model' => AttributeTranslation::class,
|
||||
'interface' => AttributeTranslationInterface::class,
|
||||
)
|
||||
)
|
||||
),
|
||||
'attribute_value' => array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Component\Product\Model\AttributeValue',
|
||||
'interface' => 'Sylius\Component\Product\Model\AttributeValueInterface',
|
||||
),
|
||||
'model' => AttributeValue::class,
|
||||
'interface' => AttributeValueInterface::class,
|
||||
)
|
||||
),
|
||||
),
|
||||
)
|
||||
)
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -97,35 +121,35 @@ class SyliusProductExtension extends AbstractResourceExtension implements Prepen
|
|||
'resources' => array(
|
||||
'product' => array(
|
||||
'variable' => $config['resources']['product']['classes']['model'],
|
||||
'variant' => array(
|
||||
'variant' => array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Component\Product\Model\Variant',
|
||||
'interface' => 'Sylius\Component\Product\Model\VariantInterface',
|
||||
'controller' => 'Sylius\Bundle\ProductBundle\Controller\VariantController',
|
||||
'model' => Variant::class,
|
||||
'interface' => VariantInterface::class,
|
||||
'controller' => VariantController::class,
|
||||
'form' => array(
|
||||
'default' => 'Sylius\Bundle\ProductBundle\Form\Type\VariantType'
|
||||
),
|
||||
),
|
||||
'default' => VariantType::class
|
||||
)
|
||||
)
|
||||
),
|
||||
'option' => array(
|
||||
'option' => array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Component\Product\Model\Option',
|
||||
'interface' => 'Sylius\Component\Product\Model\OptionInterface',
|
||||
'repository' => 'Sylius\Bundle\TranslationBundle\Doctrine\ORM\TranslatableResourceRepository',
|
||||
'model' => Option::class,
|
||||
'interface' => OptionInterface::class,
|
||||
),
|
||||
'translation' => array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Component\Product\Model\OptionTranslation',
|
||||
),
|
||||
),
|
||||
'model' => OptionTranslation::class,
|
||||
'interface' => OptionTranslationInterface::class
|
||||
)
|
||||
)
|
||||
),
|
||||
'option_value' => array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Component\Product\Model\OptionValue',
|
||||
'interface' => 'Sylius\Component\Product\Model\OptionValueInterface',
|
||||
),
|
||||
'model' => OptionValue::class,
|
||||
'interface' => OptionValueInterface::class,
|
||||
)
|
||||
),
|
||||
),
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,26 +22,9 @@
|
|||
<parameter key="sylius.generator.product_variant.class">Sylius\Bundle\ProductBundle\Generator\VariantGenerator</parameter>
|
||||
|
||||
<parameter key="sylius.validator.product.unique.class">Sylius\Bundle\ProductBundle\Validator\ProductUniqueValidator</parameter>
|
||||
<parameter key="sylius.form.type.product_translation.class">Sylius\Bundle\ProductBundle\Form\Type\ProductTranslationType</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="sylius.form.type.product" class="%sylius.form.type.product.class%">
|
||||
<argument>%sylius.model.product.class%</argument>
|
||||
<argument>%sylius.validation_group.product%</argument>
|
||||
<tag name="form.type" alias="sylius_product" />
|
||||
</service>
|
||||
<service id="sylius.form.type.product_archetype" class="%sylius.form.type.product_archetype.class%">
|
||||
<argument>%sylius.model.product_archetype.class%</argument>
|
||||
<argument>%sylius.validation_group.product_archetype%</argument>
|
||||
<tag name="form.type" alias="sylius_product_archetype" />
|
||||
</service>
|
||||
<service id="sylius.form.type.product_translation" class="%sylius.form.type.product_translation.class%">
|
||||
<argument>%sylius.model.product.class%</argument>
|
||||
<argument>%sylius.validation_group.product%</argument>
|
||||
<tag name="form.type" alias="sylius_product_translation" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.set_builder.cartesian" class="%sylius.set_builder.cartesian.class%" />
|
||||
<service id="sylius.generator.product_variant" class="%sylius.generator.product_variant.class%">
|
||||
<argument type="service" id="sylius.factory.product_variant" />
|
||||
|
|
|
|||
|
|
@ -163,7 +163,13 @@ class Configuration implements ConfigurationInterface
|
|||
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('repository')->cannotBeEmpty()->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->end()
|
||||
->scalarNode('form')->defaultValue(PromotionType::class)->cannotBeEmpty()->end()
|
||||
->arrayNode('form')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('default')->defaultValue(PromotionType::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('choice')->defaultValue(ResourceChoiceType::class)->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('validation_groups')
|
||||
|
|
@ -188,7 +194,12 @@ class Configuration implements ConfigurationInterface
|
|||
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('repository')->cannotBeEmpty()->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->end()
|
||||
->scalarNode('form')->defaultValue(RuleType::class)->cannotBeEmpty()->end()
|
||||
->arrayNode('form')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('default')->defaultValue(RuleType::class)->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('validation_groups')
|
||||
|
|
@ -213,7 +224,12 @@ class Configuration implements ConfigurationInterface
|
|||
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('repository')->cannotBeEmpty()->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->end()
|
||||
->scalarNode('form')->defaultValue(ActionType::class)->cannotBeEmpty()->end()
|
||||
->arrayNode('form')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('default')->defaultValue(ActionType::class)->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('validation_groups')
|
||||
|
|
@ -238,7 +254,12 @@ class Configuration implements ConfigurationInterface
|
|||
->scalarNode('controller')->defaultValue(CouponController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('repository')->cannotBeEmpty()->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->end()
|
||||
->scalarNode('form')->defaultValue(CouponType::class)->cannotBeEmpty()->end()
|
||||
->arrayNode('form')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('default')->defaultValue(CouponType::class)->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('validation_groups')
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@
|
|||
namespace Sylius\Bundle\PromotionBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Promotions extension.
|
||||
|
|
@ -26,11 +29,27 @@ class SyliusPromotionExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
$this->mapFormValidationGroupsParameters($config, $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container
|
||||
->getDefinition('sylius.form.type.promotion_action')
|
||||
->addArgument(new Reference('sylius.registry.promotion_action'))
|
||||
;
|
||||
$container
|
||||
->getDefinition('sylius.form.type.promotion_rule')
|
||||
->addArgument(new Reference('sylius.registry.promotion_rule_checker'))
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,11 +29,7 @@
|
|||
<parameter key="sylius.registry.promotion_rule_checker.class">Sylius\Component\Registry\ServiceRegistry</parameter>
|
||||
<parameter key="sylius.registry.promotion_action.class">Sylius\Component\Registry\ServiceRegistry</parameter>
|
||||
|
||||
<parameter key="sylius.form.type.promotion.class">Sylius\Bundle\PromotionBundle\Form\Type\PromotionType</parameter>
|
||||
<parameter key="sylius.form.type.promotion_coupon.class">Sylius\Bundle\PromotionBundle\Form\Type\CouponType</parameter>
|
||||
<parameter key="sylius.form.type.promotion_rule.class">Sylius\Bundle\PromotionBundle\Form\Type\RuleType</parameter>
|
||||
<parameter key="sylius.form.type.promotion_rule.collection.class">Sylius\Bundle\PromotionBundle\Form\Type\RuleCollectionType</parameter>
|
||||
<parameter key="sylius.form.type.promotion_action.class">Sylius\Bundle\PromotionBundle\Form\Type\ActionType</parameter>
|
||||
<parameter key="sylius.form.type.promotion_action.collection.class">Sylius\Bundle\PromotionBundle\Form\Type\ActionCollectionType</parameter>
|
||||
<parameter key="sylius.form.type.promotion_rule_choice.class">Sylius\Bundle\PromotionBundle\Form\Type\RuleChoiceType</parameter>
|
||||
<parameter key="sylius.form.type.promotion_rule.item_total_configuration.class">Sylius\Bundle\PromotionBundle\Form\Type\Rule\ItemTotalConfigurationType</parameter>
|
||||
|
|
@ -86,23 +82,23 @@
|
|||
|
||||
<service id="sylius.form.type.promotion" class="%sylius.form.type.promotion.class%">
|
||||
<argument>%sylius.model.promotion.class%</argument>
|
||||
<argument>%sylius.validation_group.promotion%</argument>
|
||||
<argument>%sylius.validation_groups.promotion%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_coupon" class="%sylius.form.type.promotion_coupon.class%">
|
||||
<argument>%sylius.model.promotion_coupon.class%</argument>
|
||||
<argument>%sylius.validation_group.promotion_coupon%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_coupon%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion_coupon" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_rule" class="%sylius.form.type.promotion_rule.class%">
|
||||
<argument>%sylius.model.promotion_rule.class%</argument>
|
||||
<argument>%sylius.validation_group.promotion_rule%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_rule%</argument>
|
||||
<argument type="service" id="sylius.registry.promotion_rule_checker" />
|
||||
<tag name="form.type" alias="sylius_promotion_rule" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_action" class="%sylius.form.type.promotion_action.class%">
|
||||
<argument>%sylius.model.promotion_action.class%</argument>
|
||||
<argument>%sylius.validation_group.promotion_action%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_action%</argument>
|
||||
<argument type="service" id="sylius.registry.promotion_action" />
|
||||
<tag name="form.type" alias="sylius_promotion_action" />
|
||||
</service>
|
||||
|
|
@ -111,11 +107,11 @@
|
|||
<tag name="form.type" alias="sylius_promotion_rule_choice" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_rule.item_total_configuration" class="%sylius.form.type.promotion_rule.item_total_configuration.class%">
|
||||
<argument>%sylius.validation_group.promotion_rule_item_total_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_rule_item_total_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion_rule_item_total_configuration" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_rule.item_count_configuration" class="%sylius.form.type.promotion_rule.item_count_configuration.class%">
|
||||
<argument>%sylius.validation_group.promotion_rule_item_count_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_rule_item_count_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion_rule_item_count_configuration" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_action_choice" class="%sylius.form.type.promotion_action_choice.class%">
|
||||
|
|
@ -123,11 +119,11 @@
|
|||
<tag name="form.type" alias="sylius_promotion_action_choice" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_action.fixed_discount_configuration" class="%sylius.form.type.promotion_action.fixed_discount_configuration.class%">
|
||||
<argument>%sylius.validation_group.promotion_action_fixed_discount_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_action_fixed_discount_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion_action_fixed_discount_configuration" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_action.percentage_discount_configuration" class="%sylius.form.type.promotion_action.percentage_discount_configuration.class%">
|
||||
<argument>%sylius.validation_group.promotion_action_percentage_discount_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_action_percentage_discount_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion_action_percentage_discount_configuration" />
|
||||
</service>
|
||||
<service id="sylius.form.type.promotion_coupon_to_code" class="%sylius.form.type.promotion_coupon_to_code.class%">
|
||||
|
|
@ -141,7 +137,7 @@
|
|||
|
||||
<service id="sylius.form.type.promotion_coupon_generate_instruction" class="%sylius.form.type.promotion_coupon_generate_instruction.class%">
|
||||
<argument>%sylius.generator.instructions.class%</argument>
|
||||
<argument>%sylius.validation_group.promotion_coupon_generate_instruction%</argument>
|
||||
<argument>%sylius.validation_groups.promotion_coupon_generate_instruction%</argument>
|
||||
<tag name="form.type" alias="sylius_promotion_coupon_generate_instruction" />
|
||||
</service>
|
||||
<service id="sylius.generator.promotion_coupon" class="%sylius.generator.promotion_coupon.class%">
|
||||
|
|
|
|||
|
|
@ -12,34 +12,38 @@
|
|||
namespace Sylius\Bundle\RbacBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Rbac extension.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class SyliusRbacExtension extends AbstractResourceExtension implements PrependExtensionInterface
|
||||
{
|
||||
protected $configFiles = array(
|
||||
'services.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$loader->load(sprintf('driver/%s.xml', $config['driver']));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setAlias('sylius.authorization_identity_provider', $config['identity_provider']);
|
||||
$container->setAlias('sylius.permission_map', $config['permission_map']);
|
||||
$container->setAlias('sylius.authorization_checker', $config['authorization_checker']);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\ReportBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
|
|
@ -27,13 +29,19 @@ class SyliusReportExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container
|
||||
->getDefinition('sylius.form.type.report')
|
||||
->addArgument(new Reference('sylius.registry.report.renderer'))
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ CHANGELOG
|
|||
### v0.16.0
|
||||
|
||||
* Introduce Factory for all resources.
|
||||
* New ``DriverInterface`` for resources.
|
||||
* Reworked all listeners to use new Registry.
|
||||
|
||||
### v0.10.0
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Sylius\Component\Resource\Metadata\Metadata;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Variable;
|
||||
|
||||
/**
|
||||
* Adds all resources to the registry.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class RegisterResourcesPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasParameter('sylius.resources')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$resources = $container->getParameter('sylius.resources');
|
||||
$registry = $container->getDefinition('sylius.resource_registry');
|
||||
|
||||
foreach ($resources as $alias => $configuration) {
|
||||
$registry->addMethodCall('addFromAliasAndConfiguration', array($alias, $configuration));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -57,28 +57,58 @@ class Configuration implements ConfigurationInterface
|
|||
->scalarNode('object_manager')->defaultValue('default')->end()
|
||||
->scalarNode('templates')->cannotBeEmpty()->end()
|
||||
->arrayNode('classes')
|
||||
->isRequired()
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('model')->isRequired()->cannotBeEmpty()->end()
|
||||
->scalarNode('interface')->isRequired()->cannotBeEmpty()->end()
|
||||
->scalarNode('interface')->cannotBeEmpty()->end()
|
||||
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('repository')->cannotBeEmpty()->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->end()
|
||||
->arrayNode('translation')
|
||||
->arrayNode('form')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('validation_groups')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->arrayNode('default')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array())
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('translation')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->arrayNode('classes')
|
||||
->isRequired()
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('model')->isRequired()->cannotBeEmpty()->end()
|
||||
->scalarNode('interface')->isRequired()->cannotBeEmpty()->end()
|
||||
->scalarNode('interface')->cannotBeEmpty()->end()
|
||||
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('repository')->cannotBeEmpty()->end()
|
||||
->arrayNode('mapping')
|
||||
->isRequired()
|
||||
->children()
|
||||
->arrayNode('fields')
|
||||
->prototype('scalar')
|
||||
->end()
|
||||
->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->end()
|
||||
->arrayNode('form')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('validation_groups')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->arrayNode('default')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array())
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('fields')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array())
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
|
|
|||
|
|
@ -1,225 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
|
||||
use Sylius\Component\Resource\Factory\Factory;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
*/
|
||||
abstract class AbstractDatabaseDriver implements DatabaseDriverInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerBuilder
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $managerName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resourceName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $templates;
|
||||
|
||||
public function __construct(ContainerBuilder $container, $prefix, $resourceName, $managerName, $templates = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->prefix = $prefix;
|
||||
$this->resourceName = $resourceName;
|
||||
$this->managerName = $managerName;
|
||||
$this->templates = $templates;
|
||||
}
|
||||
|
||||
public function load(array $parameters)
|
||||
{
|
||||
if (isset($parameters['classes']['controller'])) {
|
||||
$this->container->setDefinition(
|
||||
$this->getContainerKey('controller'),
|
||||
$this->getControllerDefinition($parameters['classes']['controller'])
|
||||
);
|
||||
}
|
||||
|
||||
$repositoryDefinition = $this->getRepositoryDefinition($parameters);
|
||||
$reflection = new \ReflectionClass($repositoryDefinition->getClass());
|
||||
|
||||
$translatableRepositoryInterface = 'Sylius\Component\Translation\Repository\TranslatableResourceRepositoryInterface';
|
||||
|
||||
if (interface_exists($translatableRepositoryInterface) && $reflection->implementsInterface($translatableRepositoryInterface)) {
|
||||
if (isset($parameters['translation']['fields'])) {
|
||||
$repositoryDefinition->addMethodCall('setTranslatableFields', array($parameters['translation']['fields']));
|
||||
}
|
||||
}
|
||||
|
||||
$this->container->setDefinition(
|
||||
$this->getContainerKey('repository'),
|
||||
$repositoryDefinition
|
||||
);
|
||||
|
||||
|
||||
if (isset($parameters['classes']['factory'])) {
|
||||
$factoryDefinition = $this->getFactoryDefinition($parameters['classes']['factory'], $parameters['classes']['model']);
|
||||
|
||||
$this->container->setDefinition(
|
||||
$this->getContainerKey('factory'),
|
||||
$factoryDefinition
|
||||
);
|
||||
}
|
||||
|
||||
$this->setManagerAlias();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity manager
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getManagerServiceKey();
|
||||
|
||||
/**
|
||||
* Get the doctrine ClassMetadata class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getClassMetadataClassname();
|
||||
|
||||
/**
|
||||
* Get the respository service
|
||||
*
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return Definition
|
||||
*/
|
||||
abstract protected function getRepositoryDefinition(array $parameters);
|
||||
|
||||
/**
|
||||
* @return Definition
|
||||
*/
|
||||
protected function getConfigurationDefinition()
|
||||
{
|
||||
$definition = new Definition(new Parameter('sylius.controller.configuration.class'));
|
||||
$definition
|
||||
->setFactory(array(new Reference('sylius.controller.configuration_factory'), 'createConfiguration'))
|
||||
->setArguments(array($this->prefix, $this->resourceName, $this->templates))
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
*
|
||||
* @return Definition
|
||||
*/
|
||||
protected function getControllerDefinition($class)
|
||||
{
|
||||
$definition = new Definition($class);
|
||||
$definition
|
||||
->setArguments(array($this->getConfigurationDefinition()))
|
||||
->addMethodCall('setContainer', array(new Reference('service_container')))
|
||||
;
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $factoryClass
|
||||
* @param $modelClass
|
||||
*
|
||||
* @return Definition
|
||||
*/
|
||||
protected function getFactoryDefinition($factoryClass, $modelClass)
|
||||
{
|
||||
$translatableFactoryInterface = 'Sylius\Component\Translation\Factory\TranslatableFactoryInterface';
|
||||
|
||||
$reflection = new \ReflectionClass($factoryClass);
|
||||
|
||||
$definition = new Definition($factoryClass);
|
||||
|
||||
if (interface_exists($translatableFactoryInterface) && $reflection->implementsInterface($translatableFactoryInterface)) {
|
||||
$decoratedDefinition = new Definition(Factory::class);
|
||||
$decoratedDefinition->setArguments(array($modelClass));
|
||||
|
||||
$definition->setArguments(array($decoratedDefinition, new Reference('sylius.translation.locale_provider')));
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
$definition->setArguments(array($modelClass));
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $models
|
||||
*
|
||||
* @return Definition
|
||||
*/
|
||||
protected function getClassMetadataDefinition($models)
|
||||
{
|
||||
$definition = new Definition($this->getClassMetadataClassname());
|
||||
$definition
|
||||
->setFactory(array(new Reference($this->getManagerServiceKey()), 'getClassMetadata'))
|
||||
->setArguments(array($models))
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
protected function setManagerAlias()
|
||||
{
|
||||
$this->container->setAlias(
|
||||
$this->getContainerKey('manager'),
|
||||
new Alias($this->getManagerServiceKey())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param Definition $definition
|
||||
*/
|
||||
protected function setDefinition($key, Definition $definition)
|
||||
{
|
||||
$this->container->setDefinition($this->getContainerKey($key), $definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $suffix
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getContainerKey($key, $suffix = null)
|
||||
{
|
||||
return sprintf('%s.%s.%s%s', $this->prefix, $key, $this->resourceName, $suffix);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
|
||||
use Sylius\Component\Resource\Factory\Factory;
|
||||
use Sylius\Component\Resource\Metadata\MetadataInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
*/
|
||||
abstract class AbstractDriver implements DriverInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(ContainerBuilder $container, MetadataInterface $metadata)
|
||||
{
|
||||
$this->setClassesParameters($container, $metadata);
|
||||
|
||||
if ($metadata->hasClass('controller')) {
|
||||
$this->addController($container, $metadata);
|
||||
}
|
||||
|
||||
$this->addManager($container, $metadata);
|
||||
$this->addRepository($container, $metadata);
|
||||
|
||||
if ($metadata->hasClass('factory')) {
|
||||
$this->addFactory($container, $metadata);
|
||||
}
|
||||
|
||||
if ($metadata->hasClass('form')) {
|
||||
$this->addForms($container, $metadata);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* @param MetadataInterface $metadata
|
||||
*/
|
||||
protected function setClassesParameters(ContainerBuilder $container, MetadataInterface $metadata)
|
||||
{
|
||||
if ($metadata->hasClass('model')) {
|
||||
$container->setParameter(sprintf('%s.model.%s.class', $metadata->getApplicationName(), $metadata->getName()), $metadata->getClass('model'));
|
||||
}
|
||||
if ($metadata->hasClass('controller')) {
|
||||
$container->setParameter(sprintf('%s.controller.%s.class', $metadata->getApplicationName(), $metadata->getName()), $metadata->getClass('controller'));
|
||||
}
|
||||
if ($metadata->hasClass('factory')) {
|
||||
$container->setParameter(sprintf('%s.factory.%s.class', $metadata->getApplicationName(), $metadata->getName()), $metadata->getClass('factory'));
|
||||
}
|
||||
if ($metadata->hasClass('repository')) {
|
||||
$container->setParameter(sprintf('%s.repository.%s.class', $metadata->getApplicationName(), $metadata->getName()), $metadata->getClass('repository'));
|
||||
}
|
||||
|
||||
if (!$metadata->hasParameter('validation_groups')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$validationGroups = $metadata->getParameter('validation_groups');
|
||||
|
||||
foreach ($validationGroups as $formName => $groups) {
|
||||
$suffix = 'default' === $formName ? '' : sprintf('_%s', $formName);
|
||||
$container->setParameter(sprintf('%s.validation_groups.%s%s', $metadata->getApplicationName(), $metadata->getName(), $suffix), $groups);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* @param MetadataInterface $metadata
|
||||
*/
|
||||
protected function addController(ContainerBuilder $container, MetadataInterface $metadata)
|
||||
{
|
||||
// @todo: Remove when ResourceController is reworked.
|
||||
$configurationDefinition = new Definition(new Parameter('sylius.controller.configuration.class'));
|
||||
$configurationDefinition
|
||||
->setFactory(array(new Reference('sylius.controller.configuration_factory'), 'createConfiguration'))
|
||||
->setArguments(array($metadata->getApplicationName(), $metadata->getName(), $metadata->getTemplatesNamespace()))
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
$definition = new Definition($metadata->getClass('controller'));
|
||||
$definition
|
||||
->setArguments(array($configurationDefinition))
|
||||
->addMethodCall('setContainer', array(new Reference('service_container')))
|
||||
;
|
||||
|
||||
$container->setDefinition($metadata->getServiceId('controller'), $definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* @param MetadataInterface $metadata
|
||||
*/
|
||||
protected function addFactory(ContainerBuilder $container, MetadataInterface $metadata)
|
||||
{
|
||||
$translatableFactoryInterface = 'Sylius\Component\Translation\Factory\TranslatableFactoryInterface';
|
||||
|
||||
$factoryClass = $metadata->getClass('factory');
|
||||
$modelClass = $metadata->getClass('model');
|
||||
|
||||
$reflection = new \ReflectionClass($factoryClass);
|
||||
$definition = new Definition($factoryClass);
|
||||
|
||||
if (interface_exists($translatableFactoryInterface) && $reflection->implementsInterface($translatableFactoryInterface)) {
|
||||
$decoratedDefinition = new Definition(Factory::class);
|
||||
$decoratedDefinition->setArguments(array($modelClass));
|
||||
|
||||
$definition->setArguments(array($decoratedDefinition, new Reference('sylius.translation.locale_provider')));
|
||||
|
||||
$container->setDefinition($metadata->getServiceId('factory'), $definition);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$definition->setArguments(array($modelClass));
|
||||
|
||||
$container->setDefinition($metadata->getServiceId('factory'), $definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* @param MetadataInterface $metadata
|
||||
*/
|
||||
protected function addForms(ContainerBuilder $container, MetadataInterface $metadata)
|
||||
{
|
||||
foreach ($metadata->getClass('form') as $formName => $formClass) {
|
||||
$suffix = 'default' === $formName ? '' : sprintf('_%s', $formName);
|
||||
$alias = sprintf('%s_%s%s', $metadata->getApplicationName(), $metadata->getName(), $suffix);
|
||||
|
||||
$definition = new Definition($formClass);
|
||||
|
||||
switch ($formName) {
|
||||
case 'choice':
|
||||
$definition->setArguments(array(
|
||||
$metadata->getClass('model'),
|
||||
$metadata->getDriver(),
|
||||
$alias,
|
||||
));
|
||||
break;
|
||||
|
||||
default:
|
||||
$validationGroupsParameterName = sprintf('%s.validation_groups.%s%s', $metadata->getApplicationName(), $metadata->getName(), $suffix);
|
||||
|
||||
if ($container->hasParameter($validationGroupsParameterName)) {
|
||||
$validationGroups = new Parameter($validationGroupsParameterName);
|
||||
} else {
|
||||
$validationGroups = array('Default');
|
||||
}
|
||||
|
||||
$definition->setArguments(array(
|
||||
$metadata->getClass('model'),
|
||||
$validationGroups,
|
||||
));
|
||||
break;
|
||||
}
|
||||
|
||||
$definition->addTag('form.type', array('alias' => $alias));
|
||||
|
||||
$container->setParameter(sprintf('%s.form.type.%s%s.class', $metadata->getApplicationName(), $metadata->getName(), $suffix), $formClass);
|
||||
$container->setDefinition(
|
||||
sprintf('%s.form.type.%s%s', $metadata->getApplicationName(), $metadata->getName(), $suffix),
|
||||
$definition
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* @param MetadataInterface $metadata
|
||||
*/
|
||||
abstract protected function addManager(ContainerBuilder $container, MetadataInterface $metadata);
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* @param MetadataInterface $metadata
|
||||
*/
|
||||
abstract protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata);
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Sylius\Component\Resource\Exception\Driver\UnknownDriverException;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
*/
|
||||
class DatabaseDriverFactory
|
||||
{
|
||||
public static function get(
|
||||
ContainerBuilder $container,
|
||||
$prefix,
|
||||
$resourceName,
|
||||
$managerName,
|
||||
$type = SyliusResourceBundle::DRIVER_DOCTRINE_ORM,
|
||||
$templates = null
|
||||
) {
|
||||
switch ($type) {
|
||||
case SyliusResourceBundle::DRIVER_DOCTRINE_ORM:
|
||||
return new DoctrineORMDriver($container, $prefix, $resourceName, $managerName, $templates);
|
||||
case SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM:
|
||||
return new DoctrineODMDriver($container, $prefix, $resourceName, $managerName, $templates);
|
||||
case SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM:
|
||||
return new DoctrinePHPCRDriver($container, $prefix, $resourceName, $managerName, $templates);
|
||||
default:
|
||||
throw new UnknownDriverException($type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
interface DatabaseDriverInterface
|
||||
{
|
||||
public function load(array $parameters);
|
||||
|
||||
public function getSupportedDriver();
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Doctrine;
|
||||
|
||||
use Sylius\Component\Resource\Metadata\MetadataInterface;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\AbstractDriver;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
*/
|
||||
abstract class AbstractDoctrineDriver extends AbstractDriver
|
||||
{
|
||||
/**
|
||||
* @param MetadataInterface $metadata
|
||||
*
|
||||
* @return Definition
|
||||
*/
|
||||
protected function getClassMetadataDefinition(MetadataInterface $metadata)
|
||||
{
|
||||
$definition = new Definition($this->getClassMetadataClassname());
|
||||
$definition
|
||||
->setFactory(array(new Reference($this->getManagerServiceId($metadata)), 'getClassMetadata'))
|
||||
->setArguments(array($metadata->getClass('model')))
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function addManager(ContainerBuilder $container, MetadataInterface $metadata)
|
||||
{
|
||||
$container->setAlias(
|
||||
$metadata->getServiceId('manager'),
|
||||
new Alias($this->getManagerServiceId($metadata))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MetadataInterface $metadata
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getManagerServiceId(MetadataInterface $metadata);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getClassMetadataClassname();
|
||||
}
|
||||
|
|
@ -9,9 +9,11 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Doctrine;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Sylius\Component\Resource\Metadata\MetadataInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
|
@ -20,12 +22,12 @@ use Symfony\Component\DependencyInjection\Reference;
|
|||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
*/
|
||||
class DoctrineODMDriver extends AbstractDatabaseDriver
|
||||
class DoctrineODMDriver extends AbstractDoctrineDriver
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSupportedDriver()
|
||||
public function getType()
|
||||
{
|
||||
return SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM;
|
||||
}
|
||||
|
|
@ -33,30 +35,33 @@ class DoctrineODMDriver extends AbstractDatabaseDriver
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getRepositoryDefinition(array $parameters)
|
||||
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
|
||||
{
|
||||
$reflection = new \ReflectionClass($parameters['classes']['model']);
|
||||
$modelClass = $metadata->getClass('model');
|
||||
|
||||
$reflection = new \ReflectionClass($modelClass);
|
||||
$translatableInterface = 'Sylius\Component\Translation\Model\TranslatableInterface';
|
||||
$translatable = (interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface));
|
||||
$translatable = interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface);
|
||||
|
||||
$repositoryClass = $translatable
|
||||
? 'Sylius\Bundle\TranslationBundle\Doctrine\ODM\MongoDB\TranslatableResourceRepository'
|
||||
: new Parameter('sylius.mongodb_odm.repository.class');
|
||||
|
||||
if (isset($parameters['classes']['repository'])) {
|
||||
$repositoryClass = $parameters['classes']['repository'];
|
||||
if ($metadata->hasClass('repository')) {
|
||||
$repositoryClass = $metadata->getClass('repository');
|
||||
}
|
||||
|
||||
$unitOfWorkDefinition = new Definition('Doctrine\\ODM\\MongoDB\\UnitOfWork');
|
||||
$unitOfWorkDefinition
|
||||
->setFactory(array(new Reference($this->getManagerServiceKey()), 'getUnitOfWork'))
|
||||
->setPublic(false);
|
||||
->setFactory(array(new Reference($this->getManagerServiceId($metadata)), 'getUnitOfWork'))
|
||||
->setPublic(false)
|
||||
;
|
||||
|
||||
$definition = new Definition($repositoryClass);
|
||||
$definition->setArguments(array(
|
||||
new Reference($this->getContainerKey('manager')),
|
||||
new Reference($metadata->getServiceId('manager')),
|
||||
$unitOfWorkDefinition,
|
||||
$this->getClassMetadataDefinition($parameters['classes']['model']),
|
||||
$this->getClassMetadataDefinition($modelClass),
|
||||
));
|
||||
|
||||
return $definition;
|
||||
|
|
@ -65,9 +70,9 @@ class DoctrineODMDriver extends AbstractDatabaseDriver
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getManagerServiceKey()
|
||||
protected function getManagerServiceId(MetadataInterface $metadata)
|
||||
{
|
||||
return sprintf('doctrine_mongodb.odm.%s_document_manager', $this->managerName);
|
||||
return sprintf('doctrine_mongodb.odm.%s_document_manager', 'default');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Doctrine;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Sylius\Component\Resource\Metadata\MetadataInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
|
||||
*/
|
||||
class DoctrineORMDriver extends AbstractDoctrineDriver
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return SyliusResourceBundle::DRIVER_DOCTRINE_ORM;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
|
||||
{
|
||||
$reflection = new \ReflectionClass($metadata->getClass('model'));
|
||||
|
||||
$translatableInterface = 'Sylius\Component\Translation\Model\TranslatableInterface';
|
||||
$translatable = interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface);
|
||||
|
||||
$repositoryClassParameterName = sprintf('%s.repository.%s.class', $metadata->getApplicationName(), $metadata->getName());
|
||||
$repositoryClass = $translatable
|
||||
? 'Sylius\Bundle\TranslationBundle\Doctrine\ORM\TranslatableResourceRepository'
|
||||
: 'Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository'
|
||||
;
|
||||
|
||||
if ($container->hasParameter($repositoryClassParameterName)) {
|
||||
$repositoryClass = $container->getParameter($repositoryClassParameterName);
|
||||
}
|
||||
|
||||
if ($metadata->hasClass('repository')) {
|
||||
$repositoryClass = $metadata->getClass('repository');
|
||||
}
|
||||
|
||||
$definition = new Definition($repositoryClass);
|
||||
$definition->setArguments(array(
|
||||
new Reference($metadata->getServiceId('manager')),
|
||||
$this->getClassMetadataDefinition($metadata),
|
||||
));
|
||||
|
||||
if ($metadata->hasParameter('translation')) {
|
||||
$repositoryReflection = new \ReflectionClass($repositoryClass);
|
||||
$translatableRepositoryInterface = 'Sylius\Component\Translation\Repository\TranslatableResourceRepositoryInterface';
|
||||
$translationConfig = $metadata->getParameter('translation');
|
||||
|
||||
if (interface_exists($translatableRepositoryInterface) && $repositoryReflection->implementsInterface($translatableRepositoryInterface)) {
|
||||
if (isset($translationConfig['fields'])) {
|
||||
$definition->addMethodCall('setTranslatableFields', array($translationConfig['fields']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$container->setDefinition($metadata->getServiceId('repository'), $definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getManagerServiceId(MetadataInterface $metadata)
|
||||
{
|
||||
return sprintf('doctrine.orm.%s_entity_manager', 'default');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getClassMetadataClassname()
|
||||
{
|
||||
return 'Doctrine\\ORM\\Mapping\\ClassMetadata';
|
||||
}
|
||||
}
|
||||
|
|
@ -9,9 +9,11 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Doctrine;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Sylius\Component\Resource\Metadata\MetadataInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
|
@ -20,12 +22,12 @@ use Symfony\Component\DependencyInjection\Reference;
|
|||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
*/
|
||||
class DoctrinePHPCRDriver extends AbstractDatabaseDriver
|
||||
class DoctrinePHPCRDriver extends AbstractDoctrineDriver
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSupportedDriver()
|
||||
public function getType()
|
||||
{
|
||||
return SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM;
|
||||
}
|
||||
|
|
@ -33,29 +35,29 @@ class DoctrinePHPCRDriver extends AbstractDatabaseDriver
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getRepositoryDefinition(array $parameters)
|
||||
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
|
||||
{
|
||||
$repositoryClass = new Parameter('sylius.phpcr_odm.repository.class');
|
||||
|
||||
if (isset($parameters['classes']['repository'])) {
|
||||
$repositoryClass = $parameters['classes']['repository'];
|
||||
if ($metadata->hasClass('repository')) {
|
||||
$repositoryClass = $metadata->getClass('repository');
|
||||
}
|
||||
|
||||
$definition = new Definition($repositoryClass);
|
||||
$definition->setArguments(array(
|
||||
new Reference($this->getContainerKey('manager')),
|
||||
$this->getClassMetadataDefinition($parameters['classes']['model']),
|
||||
new Reference($metadata->getServiceId('manager')),
|
||||
$this->getClassMetadataDefinition($metadata),
|
||||
));
|
||||
|
||||
return $definition;
|
||||
$container->setDefinition($metadata->getServiceId('repository'), $definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getManagerServiceKey()
|
||||
protected function getManagerServiceId(MetadataInterface $metadata)
|
||||
{
|
||||
return sprintf('doctrine_phpcr.odm.%s_document_manager', $this->managerName);
|
||||
return sprintf('doctrine_phpcr.odm.%s_document_manager', 'default');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
|
||||
*/
|
||||
class DoctrineORMDriver extends AbstractDatabaseDriver
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSupportedDriver()
|
||||
{
|
||||
return SyliusResourceBundle::DRIVER_DOCTRINE_ORM;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getRepositoryDefinition(array $parameters)
|
||||
{
|
||||
$reflection = new \ReflectionClass($parameters['classes']['model']);
|
||||
$translatableInterface = 'Sylius\Component\Translation\Model\TranslatableInterface';
|
||||
$translatable = (interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface));
|
||||
|
||||
$repositoryKey = $this->getContainerKey('repository', '.class');
|
||||
$repositoryClass = $translatable
|
||||
? 'Sylius\Bundle\TranslationBundle\Doctrine\ORM\TranslatableResourceRepository'
|
||||
: new Parameter('sylius.orm.repository.class');
|
||||
|
||||
if ($this->container->hasParameter($repositoryKey)) {
|
||||
$repositoryClass = $this->container->getParameter($repositoryKey);
|
||||
}
|
||||
|
||||
if (isset($parameters['classes']['repository'])) {
|
||||
$repositoryClass = $parameters['classes']['repository'];
|
||||
}
|
||||
|
||||
$definition = new Definition($repositoryClass);
|
||||
$definition->setArguments(array(
|
||||
new Reference($this->getContainerKey('manager')),
|
||||
$this->getClassMetadataDefinition($parameters['classes']['model']),
|
||||
));
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getManagerServiceKey()
|
||||
{
|
||||
return sprintf('doctrine.orm.%s_entity_manager', $this->managerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getClassMetadataClassname()
|
||||
{
|
||||
return 'Doctrine\\ORM\\Mapping\\ClassMetadata';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Doctrine\DoctrineODMDriver;
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Doctrine\DoctrineORMDriver;
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Doctrine\DoctrinePHPCRDriver;
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception\UnknownDriverException;
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Sylius\Component\Resource\Metadata\MetadataInterface;
|
||||
|
||||
/**
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
*/
|
||||
class DriverFactory
|
||||
{
|
||||
/**
|
||||
* @var DriverInterface[]
|
||||
*/
|
||||
static private $drivers = array();
|
||||
|
||||
/**
|
||||
* @param MetadataInterface $metadata
|
||||
*
|
||||
* @return DriverInterface
|
||||
*
|
||||
* @throws UnknownDriverException
|
||||
*/
|
||||
public static function get(MetadataInterface $metadata)
|
||||
{
|
||||
$type = $metadata->getDriver();
|
||||
|
||||
if (isset(self::$drivers[$type])) {
|
||||
return self::$drivers[$type];
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case SyliusResourceBundle::DRIVER_DOCTRINE_ORM:
|
||||
return self::$drivers[$type] = new DoctrineORMDriver();
|
||||
case SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM:
|
||||
return self::$drivers[$type] = new DoctrineODMDriver();
|
||||
case SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM:
|
||||
return self::$drivers[$type] = new DoctrinePHPCRDriver();
|
||||
}
|
||||
|
||||
throw new UnknownDriverException($type);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
|
||||
use Sylius\Component\Resource\Metadata\MetadataInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
interface DriverInterface
|
||||
{
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* @param MetadataInterface $metadata
|
||||
*/
|
||||
public function load(ContainerBuilder $container, MetadataInterface $metadata);
|
||||
|
||||
/**
|
||||
* Returns unique name of the driver.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType();
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Resource\Exception\Driver;
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception;
|
||||
|
||||
/**
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Resource\Exception\Driver;
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception;
|
||||
|
||||
/**
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Extension;
|
||||
|
||||
use Symfony\Component\Config\Exception\FileLoaderLoadException;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Config\Loader\DelegatingLoader;
|
||||
use Symfony\Component\Config\Loader\LoaderResolver;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
|
||||
/**
|
||||
* @author Arnaud Langlade <arn0d.dev@gmail.com>
|
||||
*/
|
||||
abstract class AbstractExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* Path where are stored your serive definition files.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $configDirectory = '/../Resources/config';
|
||||
|
||||
/**
|
||||
* Load the services service definitions
|
||||
*
|
||||
* @param ContainerBuilder $containerBuilder
|
||||
* @param string|array $files
|
||||
*
|
||||
* @throws FileLoaderLoadException
|
||||
*/
|
||||
protected function loadServiceDefinitions(ContainerBuilder $containerBuilder, $files)
|
||||
{
|
||||
$locator = new FileLocator($this->getDefinitionPath($containerBuilder));
|
||||
|
||||
$resolver = new LoaderResolver(
|
||||
array(
|
||||
new XmlFileLoader($containerBuilder, $locator),
|
||||
new YamlFileLoader($containerBuilder, $locator),
|
||||
) + $this->getExtraLoaders($containerBuilder)
|
||||
);
|
||||
|
||||
$loader = new DelegatingLoader($resolver);
|
||||
|
||||
if (!is_array($files)) {
|
||||
$files = array($files);
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$loader->load($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the driver service definitions
|
||||
*
|
||||
* @param ContainerBuilder $containerBuilder
|
||||
*/
|
||||
protected function loadDriverDefinition(ContainerBuilder $containerBuilder, $driver)
|
||||
{
|
||||
list($lib, $type) = explode('/', $driver);
|
||||
$rootPath = sprintf('%s/driver/%s', $this->getDefinitionPath(), $lib);
|
||||
|
||||
if (!is_dir($rootPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$finder = new Finder();
|
||||
$files = $finder
|
||||
->files()
|
||||
->in($rootPath)
|
||||
->name('/^'.$type.'\.*/')
|
||||
;
|
||||
|
||||
foreach ($files as $file) {
|
||||
/** @var SplFileInfo $file */
|
||||
$this->loadServiceDefinitions($containerBuilder, sprintf('driver/%s/%s', $lib, $file->getFilename()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration directory.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
protected function getDefinitionPath()
|
||||
{
|
||||
$reflector = new \ReflectionClass($this);
|
||||
$fileName = $reflector->getFileName();
|
||||
|
||||
if (!is_dir($directory = dirname($fileName).$this->configDirectory)) {
|
||||
throw new \RuntimeException(sprintf('The configuration directory "%s" does not exists.', $directory));
|
||||
}
|
||||
|
||||
return $directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register extra loaders
|
||||
*
|
||||
* @param ContainerBuilder $containerBuilder
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getExtraLoaders(ContainerBuilder $containerBuilder)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
|
@ -11,302 +11,65 @@
|
|||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Extension;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Configuration;
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DatabaseDriverFactory;
|
||||
use Sylius\Bundle\TranslationBundle\DependencyInjection\Mapper;
|
||||
use Sylius\Component\Resource\Exception\Driver\InvalidDriverException;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DriverFactory;
|
||||
use Sylius\Component\Resource\Metadata\Metadata;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
|
||||
/**
|
||||
* Base extension.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Gustavo Perdomo <gperdomor@gmail.com>
|
||||
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
|
||||
*/
|
||||
abstract class AbstractResourceExtension extends AbstractExtension
|
||||
abstract class AbstractResourceExtension extends Extension
|
||||
{
|
||||
const CONFIGURE_LOADER = 1;
|
||||
const CONFIGURE_DATABASE = 2;
|
||||
const CONFIGURE_PARAMETERS = 4;
|
||||
const CONFIGURE_VALIDATORS = 8;
|
||||
const CONFIGURE_FORMS = 16;
|
||||
const CONFIGURE_TRANSLATIONS = 32;
|
||||
|
||||
const DEFAULT_KEY = 'default';
|
||||
|
||||
protected $applicationName = 'sylius';
|
||||
protected $configFiles = array('services.xml');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$this->configure($config, new Configuration(), $container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param ConfigurationInterface $configuration
|
||||
* @param ContainerBuilder $container
|
||||
* @param integer $configure
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function configure(
|
||||
array $config,
|
||||
ConfigurationInterface $configuration,
|
||||
ContainerBuilder $container,
|
||||
$configure = self::CONFIGURE_LOADER
|
||||
) {
|
||||
$processor = new Processor();
|
||||
$config = $processor->processConfiguration($configuration, $config);
|
||||
$config = $this->process($config, $container);
|
||||
|
||||
$this->loadServiceDefinitions($container, $this->configFiles);
|
||||
|
||||
if ($configure & self::CONFIGURE_DATABASE) {
|
||||
$this->loadDatabaseDriver($config, $container);
|
||||
}
|
||||
|
||||
if ($this->isTranslationSupported() && $configure & self::CONFIGURE_TRANSLATIONS) {
|
||||
$this->configureTranslations($config, $container);
|
||||
}
|
||||
|
||||
$resources = isset($config['resources']) ? $config['resources'] : array();
|
||||
|
||||
if ($configure & self::CONFIGURE_PARAMETERS) {
|
||||
$this->mapClassParameters($resources, $container);
|
||||
}
|
||||
|
||||
if ($configure & self::CONFIGURE_VALIDATORS) {
|
||||
$this->mapValidationGroupParameters($config['resources'], $container);
|
||||
$this->mapFormsValidationGroupParameters($config, $container);
|
||||
}
|
||||
|
||||
if ($configure & self::CONFIGURE_FORMS) {
|
||||
$this->registerFormTypes($config, $container);
|
||||
}
|
||||
|
||||
$configClasses = array($this->applicationName => $resources);
|
||||
|
||||
if ($container->hasParameter('sylius.config.classes')) {
|
||||
$configClasses = array_merge_recursive(
|
||||
$configClasses,
|
||||
$container->getParameter('sylius.config.classes')
|
||||
);
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.config.classes', $configClasses);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remap class parameters.
|
||||
*
|
||||
* @param array $resources
|
||||
* @param string $applicationName
|
||||
* @param string $driver
|
||||
* @param array $resources
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function mapClassParameters(array $resources, ContainerBuilder $container)
|
||||
protected function registerResources($applicationName, $driver, array $resources, ContainerBuilder $container)
|
||||
{
|
||||
foreach ($resources as $resource => $parameters) {
|
||||
if (isset($parameters['translation'])) {
|
||||
$this->mapClassParameters(array(sprintf('%s_translation', $resource) => $parameters['translation']), $container);
|
||||
}
|
||||
$container->setParameter(sprintf('%s.driver.%s', $this->getAlias(), $driver), true);
|
||||
$container->setParameter(sprintf('%s.driver', $this->getAlias()), $driver);
|
||||
|
||||
foreach ($parameters['classes'] as $serviceName => $serviceClassOrClasses) {
|
||||
if (!is_array($serviceClassOrClasses)) {
|
||||
$container->setParameter(sprintf('%s.%s.%s.class', $this->applicationName, $serviceName, $resource), $serviceClassOrClasses);
|
||||
} else {
|
||||
$serviceClasses = $serviceClassOrClasses;
|
||||
foreach ($resources as $resourceName => $resourceConfig) {
|
||||
$alias = $applicationName.'.'.$resourceName;
|
||||
$resourceConfig = array_merge(array('driver' => $driver), $resourceConfig);
|
||||
|
||||
foreach ($serviceClasses as $serviceType => $serviceClass) {
|
||||
if (self::DEFAULT_KEY === $serviceType) {
|
||||
$container->setParameter(sprintf('%s.%s.%s.class', $this->applicationName, $serviceName, $resource), $serviceClass);
|
||||
} else {
|
||||
$container->setParameter(sprintf('%s.%s.%s_%s.class', $this->applicationName, $serviceName, $resource, $serviceType), $serviceClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
$resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : array();
|
||||
$resources = array_merge($resources, array($alias => $resourceConfig));
|
||||
$container->setParameter('sylius.resources', $resources);
|
||||
|
||||
$metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
|
||||
|
||||
DriverFactory::get($metadata)->load($container, $metadata);
|
||||
|
||||
if ($metadata->hasParameter('translation')) {
|
||||
$alias = $alias.'_translation';
|
||||
$resourceConfig = array_merge(array('driver' => $driver), $resourceConfig['translation']);
|
||||
|
||||
$resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : array();
|
||||
$resources = array_merge($resources, array($alias => $resourceConfig));
|
||||
$container->setParameter('sylius.resources', $resources);
|
||||
|
||||
$metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
|
||||
|
||||
DriverFactory::get($metadata)->load($container, $metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register resource form types.
|
||||
*
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function registerFormTypes(array $config, ContainerBuilder $container)
|
||||
{
|
||||
foreach ($config['resources'] as $resource => $parameters) {
|
||||
if (!isset($parameters['classes']['form']) || !is_array($parameters['classes']['form'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->isTranslationSupported() && isset($parameters['translation'])) {
|
||||
$this->registerFormTypes(array('resources' => array(sprintf('%s_translation', $resource) => $parameters['translation'])), $container);
|
||||
}
|
||||
|
||||
foreach ($parameters['classes']['form'] as $name => $class) {
|
||||
$suffix = ($name === self::DEFAULT_KEY ? '' : sprintf('_%s', $name));
|
||||
$alias = sprintf('%s_%s%s', $this->applicationName, $resource, $suffix);
|
||||
$definition = new Definition($class);
|
||||
if ('choice' === $name) {
|
||||
$definition->setArguments(array(
|
||||
$parameters['classes']['model'],
|
||||
$config['driver'],
|
||||
$alias,
|
||||
));
|
||||
} else {
|
||||
$validationGroupsParameterName = sprintf('%s.validation_group.%s%s', $this->applicationName, $resource, $suffix);
|
||||
$validationGroups = array('Default');
|
||||
|
||||
if ($container->hasParameter($validationGroupsParameterName)) {
|
||||
$validationGroups = new Parameter($validationGroupsParameterName);
|
||||
}
|
||||
|
||||
$definition->setArguments(array(
|
||||
$parameters['classes']['model'],
|
||||
$validationGroups,
|
||||
));
|
||||
}
|
||||
$definition->addTag('form.type', array('alias' => $alias));
|
||||
$container->setDefinition(
|
||||
sprintf('%s.form.type.%s%s', $this->applicationName, $resource, $suffix),
|
||||
$definition
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remap validation group parameters.
|
||||
*
|
||||
* @param array $resources
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function mapValidationGroupParameters(array $resources, ContainerBuilder $container)
|
||||
{
|
||||
foreach ($resources as $resource => $parameters) {
|
||||
if (isset($parameters['validation_groups'])) {
|
||||
$container->setParameter(sprintf('%s.validation_group.%s', $this->applicationName, $resource), $parameters['validation_groups']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remap validation group parameters for forms.
|
||||
*
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function mapFormsValidationGroupParameters(array $config, ContainerBuilder $container)
|
||||
protected function mapFormValidationGroupsParameters(array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (isset($config['validation_groups'])) {
|
||||
foreach ($config['validation_groups'] as $validationGroups => $class) {
|
||||
$container->setParameter(sprintf('%s.validation_group.%s', $this->applicationName, $validationGroups), $validationGroups);
|
||||
foreach ($config['validation_groups'] as $name => $groups) {
|
||||
$container->setParameter(sprintf('sylius.validation_groups.%s', $name), $groups);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load bundle driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*
|
||||
* @throws InvalidDriverException
|
||||
*/
|
||||
protected function loadDatabaseDriver(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$bundle = str_replace(array('Extension', 'DependencyInjection\\'), array('Bundle', ''), get_class($this));
|
||||
$driver = $config['driver'];
|
||||
$manager = isset($config['object_manager']) ? $config['object_manager'] : 'default';
|
||||
|
||||
if (!in_array($driver, call_user_func(array($bundle, 'getSupportedDrivers')))) {
|
||||
throw new InvalidDriverException($driver, basename($bundle));
|
||||
}
|
||||
|
||||
$this->loadDriverDefinition($container, $driver);
|
||||
|
||||
$container->setParameter(sprintf('%s.driver', $this->getAlias()), $driver);
|
||||
$container->setParameter(sprintf('%s.driver.%s', $this->getAlias(), $driver), true);
|
||||
$container->setParameter(sprintf('%s.object_manager', $this->getAlias()), $manager);
|
||||
|
||||
if (!isset($config['resources'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($config['resources'] as $resource => $parameters) {
|
||||
if (array_key_exists('model', $parameters['classes'])) {
|
||||
DatabaseDriverFactory::get(
|
||||
$container,
|
||||
$this->applicationName,
|
||||
$resource,
|
||||
$manager,
|
||||
$driver,
|
||||
isset($config['templates'][$resource]) ? $config['templates'][$resource] : null
|
||||
)->load($parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function configureTranslations(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$driver = $config['driver'];
|
||||
$manager = isset($config['object_manager']) ? $config['object_manager'] : 'default';
|
||||
$mapper = new Mapper();
|
||||
|
||||
foreach ($config['resources'] as $resource => $parameters) {
|
||||
if (isset($parameters['classes']['model']) && isset($parameters['translation']['classes']['model'])) {
|
||||
$mapper->mapTranslations($parameters, $container);
|
||||
$this->mapValidationGroupParameters($parameters['translation'], $container);
|
||||
|
||||
DatabaseDriverFactory::get(
|
||||
$container,
|
||||
$this->applicationName,
|
||||
sprintf('%s_translation', $resource),
|
||||
$manager,
|
||||
$driver,
|
||||
isset($config['templates'][$resource]) ? $config['templates'][$resource] : null
|
||||
)->load($parameters['translation']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In case any extra processing is needed.
|
||||
*
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function process(array $config, ContainerBuilder $container)
|
||||
{
|
||||
// Override if needed.
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Are translations supported in this app?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isTranslationSupported()
|
||||
{
|
||||
return class_exists('Sylius\Bundle\TranslationBundle\DependencyInjection\Mapper');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,19 +11,19 @@
|
|||
|
||||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DatabaseDriverFactory;
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractExtension;
|
||||
use Sylius\Bundle\TranslationBundle\DependencyInjection\Mapper;
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DriverFactory;
|
||||
use Sylius\Component\Resource\Metadata\Metadata;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Resource system extension.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
|
||||
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
|
||||
*/
|
||||
class SyliusResourceExtension extends AbstractExtension
|
||||
class SyliusResourceExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
@ -31,85 +31,43 @@ class SyliusResourceExtension extends AbstractExtension
|
|||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$processor = new Processor();
|
||||
$config = $processor->processConfiguration(new Configuration(), $config);
|
||||
$config = $processor->processConfiguration(new Configuration(), $config);
|
||||
|
||||
$this->loadServiceDefinitions($container, array(
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
'storage.xml',
|
||||
'routing.xml',
|
||||
'twig.xml',
|
||||
));
|
||||
'twig.xml'
|
||||
);
|
||||
|
||||
$resources = isset($config['resources']) ? $config['resources'] : array();
|
||||
|
||||
$container->setParameter('sylius.resource.settings', $config['settings']);
|
||||
|
||||
foreach ($resources as $resource)
|
||||
$this->createResourceServices($resources, $container);
|
||||
|
||||
$configClasses = array('default' => $this->getClassesFromConfig($resources));
|
||||
|
||||
if ($container->hasParameter('sylius.config.classes')) {
|
||||
$configClasses = array_merge_recursive(
|
||||
$configClasses,
|
||||
$container->getParameter('sylius.config.classes')
|
||||
);
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.config.classes', $configClasses);
|
||||
}
|
||||
foreach ($config['resources'] as $alias => $resourceConfig) {
|
||||
$metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
|
||||
|
||||
/**
|
||||
* @param array $resource
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
private function createResourceServices(array $resource, ContainerBuilder $container)
|
||||
{
|
||||
$translationsEnabled = class_exists('Sylius\Bundle\TranslationBundle\DependencyInjection\Mapper');
|
||||
$resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : array();
|
||||
$resources = array_merge($resources, array($alias => $resourceConfig));
|
||||
$container->setParameter('sylius.resources', $resources);
|
||||
|
||||
if ($translationsEnabled) {
|
||||
$mapper = new Mapper();
|
||||
}
|
||||
DriverFactory::get($metadata)->load($container, $metadata);
|
||||
|
||||
foreach ($resource as $name => $config) {
|
||||
list($prefix, $resourceName) = explode('.', $name);
|
||||
$manager = isset($config['object_manager']) ? $config['object_manager'] : 'default';
|
||||
if (isset($resourceConfig['translation'])) {
|
||||
$alias = $alias.'_translation';
|
||||
$resourceConfig = array_merge(array('driver' => $resourceConfig['driver']), $resourceConfig['translation']);
|
||||
|
||||
DatabaseDriverFactory::get(
|
||||
$container,
|
||||
$prefix,
|
||||
$resourceName,
|
||||
$manager,
|
||||
$config['driver'],
|
||||
array_key_exists('templates', $config) ? $config['templates'] : null
|
||||
)->load($config['classes']);
|
||||
$resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : array();
|
||||
$resources = array_merge($resources, array($alias => $resourceConfig));
|
||||
$container->setParameter('sylius.resources', $resources);
|
||||
|
||||
if ($translationsEnabled && array_key_exists('model', $config['classes']) && array_key_exists('translation', $config['classes'])) {
|
||||
$mapper->mapTranslations($config['classes'], $container);
|
||||
$metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
|
||||
|
||||
DatabaseDriverFactory::get(
|
||||
$container,
|
||||
$prefix,
|
||||
sprintf('%s_translation', $resourceName),
|
||||
$manager,
|
||||
$config['driver']
|
||||
)->load($config['translation']);
|
||||
DriverFactory::get($metadata)->load($container, $metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $configs
|
||||
* @return array
|
||||
*/
|
||||
private function getClassesFromConfig($configs)
|
||||
{
|
||||
$classes = array();
|
||||
|
||||
foreach ($configs as $config) {
|
||||
$classes[] = $config['classes'];
|
||||
}
|
||||
|
||||
return $classes;
|
||||
$container->setParameter('sylius.resource.settings', $config['settings']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,18 +24,16 @@ use Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo;
|
|||
class LoadODMMetadataSubscriber implements EventSubscriber
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
* @var RegistryInterface
|
||||
*/
|
||||
protected $classes;
|
||||
private $resourceRegistry;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $classes
|
||||
* @param RegistryInterface $resourceRegistry
|
||||
*/
|
||||
public function __construct(array $classes)
|
||||
public function __construct(RegistryInterface $resourceRegistry)
|
||||
{
|
||||
$this->classes = $classes;
|
||||
$this->resourceRegistry = $resourceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -56,7 +54,7 @@ class LoadODMMetadataSubscriber implements EventSubscriber
|
|||
/** @var ClassMetadata $metadata */
|
||||
$metadata = $eventArgs->getClassMetadata();
|
||||
|
||||
$this->setCustomRepositoryClasses($metadata);
|
||||
$this->convertToDocumentIfNeeded($metadata);
|
||||
|
||||
if (!$metadata->isMappedSuperclass) {
|
||||
$this->setAssociationMappings($metadata, $eventArgs->getDocumentManager()->getConfiguration());
|
||||
|
|
@ -65,20 +63,25 @@ class LoadODMMetadataSubscriber implements EventSubscriber
|
|||
}
|
||||
}
|
||||
|
||||
private function setCustomRepositoryClasses(ClassMetadataInfo $metadata)
|
||||
/**
|
||||
* @param ClassMetadataInfo $metadata
|
||||
*/
|
||||
private function convertToDocumentIfNeeded(ClassMetadataInfo $metadata)
|
||||
{
|
||||
foreach ($this->classes as $application => $classes) {
|
||||
foreach ($classes as $class) {
|
||||
if (isset($class['model']) && $class['model'] === $metadata->getName()) {
|
||||
$metadata->isMappedSuperclass = false;
|
||||
if (isset($class['repository'])) {
|
||||
$metadata->setCustomRepositoryClass($class['repository']);
|
||||
}
|
||||
}
|
||||
foreach ($this->resourceRegistry->getAll() as $alias => $resourceMetadata) {
|
||||
if ($resourceMetadata->hasClass('repository') && $resourceMetadata->getClass('model') === $metadata->getName()) {
|
||||
$metadata->setCustomRepositoryClass($resourceMetadata->getClass('repository'));
|
||||
}
|
||||
if ($resourceMetadata->hasClass('model') && $resourceMetadata->getClass('model') === $metadata->getName()) {
|
||||
$metadata->isMappedSuperclass = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMetadataInfo $metadata
|
||||
* @param $configuration
|
||||
*/
|
||||
private function setAssociationMappings(ClassMetadataInfo $metadata, $configuration)
|
||||
{
|
||||
foreach (class_parents($metadata->getName()) as $parent) {
|
||||
|
|
@ -96,6 +99,9 @@ class LoadODMMetadataSubscriber implements EventSubscriber
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMetadataInfo $metadata
|
||||
*/
|
||||
private function unsetAssociationMappings(ClassMetadataInfo $metadata)
|
||||
{
|
||||
foreach ($metadata->associationMappings as $key => $value) {
|
||||
|
|
@ -105,6 +111,11 @@ class LoadODMMetadataSubscriber implements EventSubscriber
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasRelation($type)
|
||||
{
|
||||
return in_array(
|
||||
|
|
|
|||
|
|
@ -15,25 +15,25 @@ use Doctrine\Common\EventSubscriber;
|
|||
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
use Sylius\Component\Resource\Metadata\RegistryInterface;
|
||||
|
||||
/**
|
||||
* Doctrine listener used to manipulate mappings.
|
||||
*
|
||||
* @author Ivan Molchanov <ivan.molchanov@opensoftdev.ru>
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class LoadORMMetadataSubscriber implements EventSubscriber
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
* @var RegistryInterface
|
||||
*/
|
||||
protected $resources;
|
||||
private $resourceRegistry;
|
||||
|
||||
/**
|
||||
* @param array $resources
|
||||
* @param RegistryInterface $resourceRegistry
|
||||
*/
|
||||
public function __construct($resources)
|
||||
public function __construct(RegistryInterface $resourceRegistry)
|
||||
{
|
||||
$this->resources = $resources;
|
||||
$this->resourceRegistry = $resourceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,7 +54,7 @@ class LoadORMMetadataSubscriber implements EventSubscriber
|
|||
/** @var ClassMetadata $metadata */
|
||||
$metadata = $eventArgs->getClassMetadata();
|
||||
|
||||
$this->process($metadata);
|
||||
$this->convertToEntityIfNeeded($metadata);
|
||||
|
||||
if (!$metadata->isMappedSuperclass) {
|
||||
$this->setAssociationMappings($metadata, $eventArgs->getEntityManager()->getConfiguration());
|
||||
|
|
@ -63,36 +63,25 @@ class LoadORMMetadataSubscriber implements EventSubscriber
|
|||
}
|
||||
}
|
||||
|
||||
private function process(ClassMetadataInfo $metadata)
|
||||
/**
|
||||
* @param ClassMetadataInfo $metadata
|
||||
*/
|
||||
private function convertToEntityIfNeeded(ClassMetadataInfo $metadata)
|
||||
{
|
||||
foreach ($this->resources as $application => $resources) {
|
||||
foreach ($resources as $resource => $resourceParameters) {
|
||||
$classes = $resourceParameters['classes'];
|
||||
|
||||
if (isset($classes['model']) && $classes['model'] === $metadata->getName()) {
|
||||
$metadata->isMappedSuperclass = false;
|
||||
|
||||
if (isset($classes['repository'])) {
|
||||
$metadata->setCustomRepositoryClass($classes['repository']);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($resourceParameters['translation'])) {
|
||||
$translationClasses = $resourceParameters['translation']['classes'];
|
||||
|
||||
if (isset($translationClasses['model']) && $translationClasses['model'] === $metadata->getName()) {
|
||||
$metadata->isMappedSuperclass = false;
|
||||
|
||||
if (isset($translationClasses['repository'])) {
|
||||
$metadata->setCustomRepositoryClass($translationClasses['repository']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
foreach ($this->resourceRegistry->getAll() as $alias => $resourceMetadata) {
|
||||
if ($resourceMetadata->hasClass('repository') && $resourceMetadata->getClass('model') === $metadata->getName()) {
|
||||
$metadata->setCustomRepositoryClass($resourceMetadata->getClass('repository'));
|
||||
}
|
||||
if ($resourceMetadata->hasClass('model') && $resourceMetadata->getClass('model') === $metadata->getName()) {
|
||||
$metadata->isMappedSuperclass = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMetadataInfo $metadata
|
||||
* @param $configuration
|
||||
*/
|
||||
private function setAssociationMappings(ClassMetadataInfo $metadata, $configuration)
|
||||
{
|
||||
foreach (class_parents($metadata->getName()) as $parent) {
|
||||
|
|
@ -113,6 +102,9 @@ class LoadORMMetadataSubscriber implements EventSubscriber
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMetadataInfo $metadata
|
||||
*/
|
||||
private function unsetAssociationMappings(ClassMetadataInfo $metadata)
|
||||
{
|
||||
foreach ($metadata->getAssociationMappings() as $key => $value) {
|
||||
|
|
@ -122,6 +114,11 @@ class LoadORMMetadataSubscriber implements EventSubscriber
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasRelation($type)
|
||||
{
|
||||
return in_array(
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="sylius.resource_registry.class">Sylius\Component\Resource\Metadata\Registry</parameter>
|
||||
|
||||
<parameter key="sylius.orm.repository.class">Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository</parameter>
|
||||
<parameter key="sylius.mongodb_odm.repository.class">Sylius\Bundle\ResourceBundle\Doctrine\ODM\MongoDB\DocumentRepository</parameter>
|
||||
<parameter key="sylius.phpcr_odm.repository.class">Sylius\Bundle\ResourceBundle\Doctrine\ODM\PHPCR\DocumentRepository</parameter>
|
||||
|
|
@ -49,6 +51,8 @@
|
|||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="sylius.resource_registry" class="%sylius.resource_registry.class%" />
|
||||
|
||||
<service id="sylius.controller.configuration_factory" class="%sylius.controller.configuration_factory.class%">
|
||||
<argument type="service" id="sylius.controller.parameters_parser" />
|
||||
<argument>%sylius.controller.configuration.class%</argument>
|
||||
|
|
@ -66,11 +70,11 @@
|
|||
</service>
|
||||
|
||||
<service id="sylius.event_subscriber.load_orm_metadata" class="%sylius.event_subscriber.load_orm_metadata.class%">
|
||||
<argument>%sylius.config.classes%</argument>
|
||||
<argument type="service" id="sylius.resource_registry" />
|
||||
<tag name="doctrine.event_subscriber" priority="8192" />
|
||||
</service>
|
||||
<service id="sylius.event_subscriber.load_odm_metadata" class="%sylius.event_subscriber.load_odm_metadata.class%">
|
||||
<argument>%sylius.config.classes%</argument>
|
||||
<argument type="service" id="sylius.resource_registry" />
|
||||
<tag name="doctrine_mongodb.odm.event_subscriber" priority="8192" />
|
||||
</service>
|
||||
<service id="sylius.event_subscriber.kernel_controller" class="%sylius.event_subscriber.kernel_controller.class%">
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
namespace Sylius\Bundle\ResourceBundle;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\ObjectToIdentifierServicePass;
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterResourcesPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
|
|
@ -32,6 +33,7 @@ class SyliusResourceBundle extends Bundle
|
|||
*/
|
||||
public function build(ContainerBuilder $container)
|
||||
{
|
||||
$container->addCompilerPass(new RegisterResourcesPass());
|
||||
$container->addCompilerPass(new ObjectToIdentifierServicePass());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
*/
|
||||
class DatabaseDriverFactorySpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DatabaseDriverFactory');
|
||||
}
|
||||
|
||||
function it_should_create_a_orm_driver_by_default(ContainerBuilder $container)
|
||||
{
|
||||
$this::get($container, 'prefix', 'resource', 'default')
|
||||
->shouldhaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DoctrineORMDriver');
|
||||
}
|
||||
|
||||
function it_should_create_a_odm_driver(ContainerBuilder $container)
|
||||
{
|
||||
$this::get($container, 'prefix', 'resource', 'default', SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM)
|
||||
->shouldhaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DoctrineODMDriver');
|
||||
}
|
||||
|
||||
function it_should_create_a_phpcr_driver(ContainerBuilder $container)
|
||||
{
|
||||
$this::get($container, 'prefix', 'resource', 'default', SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM)
|
||||
->shouldhaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DoctrinePHPCRDriver');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
*/
|
||||
class DoctrineODMDriverSpec extends ObjectBehavior
|
||||
{
|
||||
function let(ContainerBuilder $container)
|
||||
{
|
||||
$this->beConstructedWith($container, 'prefix', 'resource', 'default');
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DoctrineODMDriver');
|
||||
}
|
||||
|
||||
function it_should_implement_database_interface()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DatabaseDriverInterface');
|
||||
}
|
||||
|
||||
function it_should_create_definition(ContainerBuilder $container)
|
||||
{
|
||||
$container->setDefinition(
|
||||
'prefix.controller.resource',
|
||||
Argument::type('Symfony\Component\DependencyInjection\Definition')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$container->setDefinition(
|
||||
'prefix.repository.resource',
|
||||
Argument::type('Symfony\Component\DependencyInjection\Definition')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$alias = new Alias('doctrine_mongodb.odm.default_document_manager');
|
||||
$container->setAlias(
|
||||
'prefix.manager.resource',
|
||||
$alias
|
||||
)->shouldBeCalled();
|
||||
|
||||
$this->beConstructedWith($container, 'prefix', 'resource', 'default');
|
||||
|
||||
$this->load(
|
||||
array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Bundle\ResourceBundle\SyliusResourceBundle',
|
||||
'controller' => 'Sylius\Controller',
|
||||
'repository' => 'Sylius\Bundle\ResourceBundle\SyliusResourceBundle',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
*/
|
||||
class DoctrineORMDriverSpec extends ObjectBehavior
|
||||
{
|
||||
function let(ContainerBuilder $container)
|
||||
{
|
||||
$this->beConstructedWith($container, 'prefix', 'resource', 'default');
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DoctrineORMDriver');
|
||||
}
|
||||
|
||||
function it_should_implement_database_interface()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DatabaseDriverInterface');
|
||||
}
|
||||
|
||||
function it_should_create_definition(ContainerBuilder $container)
|
||||
{
|
||||
$container->hasParameter("prefix.repository.resource.class")->shouldBeCalled();
|
||||
|
||||
$container->setDefinition(
|
||||
'prefix.controller.resource',
|
||||
Argument::type('Symfony\Component\DependencyInjection\Definition')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$container->setDefinition(
|
||||
'prefix.repository.resource',
|
||||
Argument::type('Symfony\Component\DependencyInjection\Definition')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$container->setAlias(
|
||||
'prefix.manager.resource',
|
||||
Argument::type('Symfony\Component\DependencyInjection\Alias')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$this->beConstructedWith($container, 'prefix', 'resource', 'default');
|
||||
|
||||
$this->load(
|
||||
array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Bundle\ResourceBundle\SyliusResourceBundle',
|
||||
'controller' => 'Sylius\Controller',
|
||||
'repository' => 'Sylius\Bundle\ResourceBundle\SyliusResourceBundle',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function it_should_create_definition_and_get_repository_in_container(ContainerBuilder $container)
|
||||
{
|
||||
$container->hasParameter("prefix.repository.resource.class")
|
||||
->willReturn(true);
|
||||
|
||||
$container->getParameter("prefix.repository.resource.class")
|
||||
->shouldBeCalled();
|
||||
|
||||
$container->setDefinition(
|
||||
'prefix.controller.resource',
|
||||
Argument::type('Symfony\Component\DependencyInjection\Definition')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$container->setDefinition(
|
||||
'prefix.repository.resource',
|
||||
Argument::type('Symfony\Component\DependencyInjection\Definition')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$container->setAlias(
|
||||
'prefix.manager.resource',
|
||||
Argument::type('Symfony\Component\DependencyInjection\Alias')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$this->beConstructedWith($container, 'prefix', 'resource', 'default');
|
||||
|
||||
$this->load(
|
||||
array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Bundle\ResourceBundle\SyliusResourceBundle',
|
||||
'controller' => 'Sylius\Controller',
|
||||
'repository' => 'Sylius\Bundle\ResourceBundle\SyliusResourceBundle',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Driver;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* @author Arnaud Langlade <aRn0D.dev@gmail.com>
|
||||
*/
|
||||
class DoctrinePHPCRDriverSpec extends ObjectBehavior
|
||||
{
|
||||
function let(ContainerBuilder $container)
|
||||
{
|
||||
$this->beConstructedWith($container, 'prefix', 'resource', 'default');
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DoctrinePHPCRDriver');
|
||||
}
|
||||
|
||||
function it_should_implement_database_interface()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DatabaseDriverInterface');
|
||||
}
|
||||
|
||||
function it_should_create_definition(ContainerBuilder $container)
|
||||
{
|
||||
$container->setDefinition(
|
||||
'prefix.controller.resource',
|
||||
Argument::type('Symfony\Component\DependencyInjection\Definition')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$container->setDefinition(
|
||||
'prefix.repository.resource',
|
||||
Argument::type('Symfony\Component\DependencyInjection\Definition')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$alias = new Alias('doctrine_phpcr.odm.default_document_manager');
|
||||
$container->setAlias(
|
||||
'prefix.manager.resource',
|
||||
$alias
|
||||
)->shouldBeCalled();
|
||||
|
||||
$this->beConstructedWith($container, 'prefix', 'resource', 'default');
|
||||
|
||||
$this->load(
|
||||
array(
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Bundle\ResourceBundle\SyliusResourceBundle',
|
||||
'controller' => 'Sylius\Controller',
|
||||
'repository' => 'Sylius\Bundle\ResourceBundle\SyliusResourceBundle',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace spec\Sylius\Component\Resource\Exception\Driver;
|
||||
namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ class InvalidDriverExceptionSpec extends ObjectBehavior
|
|||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Component\Resource\Exception\Driver\InvalidDriverException');
|
||||
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception\InvalidDriverException');
|
||||
}
|
||||
|
||||
function it_extends_exception()
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace spec\Sylius\Component\Resource\Exception\Driver;
|
||||
namespace spec\Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ class UnknownDriverExceptionSpec extends ObjectBehavior
|
|||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Component\Resource\Exception\Driver\UnknownDriverException');
|
||||
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Exception\UnknownDriverException');
|
||||
}
|
||||
|
||||
function it_extends_exception()
|
||||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\SearchBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* @author Argyrios Gounaris <agounaris@gmail.com>
|
||||
|
|
@ -24,13 +26,19 @@ class SyliusSearchExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setParameter('sylius_search.config', $config);
|
||||
|
||||
$container->setAlias('sylius_search.command.indexer', sprintf('sylius.search.%s.indexer', ucfirst($config['engine'])));
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\SequenceBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Sequence extension.
|
||||
|
|
@ -26,13 +28,20 @@ class SyliusSequenceExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
sprintf('driver/%s.xml', $config['driver'])
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.sequence.generators', $config['generators']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,63 +12,33 @@
|
|||
namespace Sylius\Bundle\SettingsBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
|
||||
*/
|
||||
class SyliusSettingsExtension extends AbstractResourceExtension implements PrependExtensionInterface
|
||||
class SyliusSettingsExtension extends AbstractResourceExtension
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $configFiles = array(
|
||||
'services.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
'templating.xml',
|
||||
'twig.xml',
|
||||
);
|
||||
|
||||
foreach ($config['resources'] as $resource => $classesGroups) {
|
||||
if (isset($classesGroups['classes']['model'])) {
|
||||
$container->setParameter('sylius.model.parameter.class', $classesGroups['classes']['model']);
|
||||
}
|
||||
|
||||
if (isset($classesGroups['classes']['repository'])) {
|
||||
$container->setParameter('sylius.repository.parameter.class', $classesGroups['classes']['repository']);
|
||||
}
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepend(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasExtension('doctrine_cache')) {
|
||||
throw new \RuntimeException('DoctrineCacheBundle must be registered!');
|
||||
}
|
||||
|
||||
if (!$container->hasParameter('sylius.cache')) {
|
||||
$container->setParameter('sylius.cache', array('type' => 'file_system'));
|
||||
}
|
||||
|
||||
$container->prependExtensionConfig('doctrine_cache', array(
|
||||
'providers' => array(
|
||||
'sylius_settings' => '%sylius.cache%'
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,6 +179,7 @@ class Configuration implements ConfigurationInterface
|
|||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('default')->defaultValue(ShippingMethodType::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('choice')->defaultValue(ResourceChoiceType::class)->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\ShippingBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
|
|
@ -27,13 +29,20 @@ class SyliusShippingExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_TRANSLATIONS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
$this->mapFormValidationGroupsParameters($config, $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$shippingMethod = $container->getDefinition('sylius.form.type.shipping_method');
|
||||
$shippingMethod->addArgument(new Reference('sylius.registry.shipping_calculator'));
|
||||
$shippingMethod->addArgument(new Reference('sylius.registry.shipping_rule_checker'));
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
<parameter key="sylius.form.type.shipping_rule_item_count_configuration.class">Sylius\Bundle\ShippingBundle\Form\Type\Rule\ItemCountConfigurationType</parameter>
|
||||
|
||||
<parameter key="sylius.form.type.shipping_method_choice.class">Sylius\Bundle\ShippingBundle\Form\Type\ShippingMethodChoiceType</parameter>
|
||||
<parameter key="sylius.shipping_methods_resolver.class">Sylius\Component\Shipping\Resolver\MethodsResolver</parameter>
|
||||
|
||||
<parameter key="sylius.registry.shipping_calculator.class">Sylius\Component\Registry\ServiceRegistry</parameter>
|
||||
|
|
@ -54,15 +53,9 @@
|
|||
|
||||
<services>
|
||||
<service id="sylius.form.type.shipping_rule_item_count_configuration" class="%sylius.form.type.shipping_rule_item_count_configuration.class%">
|
||||
<argument>%sylius.validation_group.shipping_rule_item_count_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.shipping_rule_item_count_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_shipping_rule_item_count_configuration" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.form.type.shipping_category_choice" class="%sylius.form.type.shipping_category_choice.class%">
|
||||
<argument>%sylius.model.shipping_category.class%</argument>
|
||||
<tag name="form.type" alias="sylius_shipping_category_choice" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.shipping_eligibility_checker" class="%sylius.shipping_eligibility_checker.class%">
|
||||
<argument type="service" id="sylius.registry.shipping_rule_checker" />
|
||||
</service>
|
||||
|
|
@ -101,7 +94,7 @@
|
|||
<tag name="sylius.shipping_calculator" calculator="flat_rate" label="sylius.form.shipping_calculator.flat_rate_configuration.label" />
|
||||
</service>
|
||||
<service id="sylius.form.type.shipping_calculator.flat_rate" class="%sylius.form.type.shipping_calculator.flat_rate.class%">
|
||||
<argument>%sylius.validation_group.shipping_calculator_flat_rate_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.shipping_calculator_flat_rate_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_shipping_calculator_flat_rate" />
|
||||
</service>
|
||||
|
||||
|
|
@ -109,7 +102,7 @@
|
|||
<tag name="sylius.shipping_calculator" calculator="per_item_rate" label="sylius.form.shipping_calculator.per_item_rate_configuration.label" />
|
||||
</service>
|
||||
<service id="sylius.form.type.shipping_calculator.per_item_rate" class="%sylius.form.type.shipping_calculator.per_item_rate.class%">
|
||||
<argument>%sylius.validation_group.shipping_calculator_per_item_rate_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.shipping_calculator_per_item_rate_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_shipping_calculator_per_item_rate" />
|
||||
</service>
|
||||
|
||||
|
|
@ -117,7 +110,7 @@
|
|||
<tag name="sylius.shipping_calculator" calculator="flexible_rate" label="sylius.form.shipping_calculator.flexible_rate_configuration.label" />
|
||||
</service>
|
||||
<service id="sylius.form.type.shipping_calculator.flexible_rate" class="%sylius.form.type.shipping_calculator.flexible_rate.class%">
|
||||
<argument>%sylius.validation_group.shipping_calculator_flexible_rate_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.shipping_calculator_flexible_rate_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_shipping_calculator_flexible_rate" />
|
||||
</service>
|
||||
|
||||
|
|
@ -125,7 +118,7 @@
|
|||
<tag name="sylius.shipping_calculator" calculator="weight_rate" label="sylius.form.shipping_calculator.weight_rate_configuration.label" />
|
||||
</service>
|
||||
<service id="sylius.form.type.shipping_calculator.weight_rate" class="%sylius.form.type.shipping_calculator.weight_rate.class%">
|
||||
<argument>%sylius.validation_group.shipping_calculator_weight_rate_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.shipping_calculator_weight_rate_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_shipping_calculator_weight_rate" />
|
||||
</service>
|
||||
|
||||
|
|
@ -133,7 +126,7 @@
|
|||
<tag name="sylius.shipping_calculator" calculator="volume_rate" label="sylius.form.shipping_calculator.volume_rate_configuration.label" />
|
||||
</service>
|
||||
<service id="sylius.form.type.shipping_calculator.volume_rate" class="%sylius.form.type.shipping_calculator.volume_rate.class%">
|
||||
<argument>%sylius.validation_group.shipping_calculator_volume_rate_configuration%</argument>
|
||||
<argument>%sylius.validation_groups.shipping_calculator_volume_rate_configuration%</argument>
|
||||
<tag name="form.type" alias="sylius_shipping_calculator_volume_rate" />
|
||||
</service>
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\TaxationBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Taxation extension.
|
||||
|
|
@ -26,11 +28,17 @@ class SyliusTaxationExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\TaxonomyBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Taxonomy extension.
|
||||
|
|
@ -26,11 +28,19 @@ class SyliusTaxonomyExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_TRANSLATIONS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$loader->load(sprintf('driver/%s.xml', $config['driver']));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@
|
|||
namespace Sylius\Bundle\TranslationBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
|
||||
|
|
@ -24,13 +27,18 @@ class SyliusTranslationExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_PARAMETERS | self::CONFIGURE_DATABASE
|
||||
$processor = new Processor();
|
||||
$config = $processor->processConfiguration(new Configuration(), $config);
|
||||
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.translation.default_locale', $config['default_locale']);
|
||||
$container->setAlias('sylius.translation.locale_provider', $config['locale_provider']);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ use Sylius\Component\Translation\Provider\LocaleProviderInterface;
|
|||
use Sylius\Component\Translation\Repository\TranslatableResourceRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Doctrine ORM driver translatable entity repository.
|
||||
*
|
||||
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
|
||||
*/
|
||||
class TranslatableResourceRepository extends EntityRepository implements TranslatableResourceRepositoryInterface
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Sylius\Bundle\TranslationBundle\EventListener;
|
||||
|
||||
use Sylius\Component\Resource\Metadata\RegistryInterface;
|
||||
use Sylius\Component\Translation\Provider\LocaleProviderInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -18,21 +19,23 @@ use Sylius\Component\Translation\Provider\LocaleProviderInterface;
|
|||
*/
|
||||
abstract class AbstractTranslatableListener
|
||||
{
|
||||
/**
|
||||
* @var RegistryInterface
|
||||
*/
|
||||
protected $registry;
|
||||
|
||||
/**
|
||||
* @var LocaleProviderInterface
|
||||
*/
|
||||
protected $localeProvider;
|
||||
|
||||
/**
|
||||
* Mapping.
|
||||
*
|
||||
* @var array
|
||||
* @param RegistryInterface $registry
|
||||
* @param LocaleProviderInterface $localeProvider
|
||||
*/
|
||||
protected $configs;
|
||||
|
||||
public function __construct(LocaleProviderInterface $localeProvider, array $configs)
|
||||
public function __construct(RegistryInterface $registry, LocaleProviderInterface $localeProvider)
|
||||
{
|
||||
$this->registry = $registry;
|
||||
$this->localeProvider = $localeProvider;
|
||||
$this->configs = $configs;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,15 +67,23 @@ class ORMTranslatableListener extends AbstractTranslatableListener implements Ev
|
|||
*/
|
||||
private function mapTranslatable(ClassMetadata $metadata)
|
||||
{
|
||||
// In the case A -> B -> TranslatableInterface, B might not have mapping defined as it
|
||||
// is probably defined in A, so in that case, we just return.
|
||||
if (!isset($this->configs[$metadata->name])) {
|
||||
$className = $metadata->name;
|
||||
|
||||
try {
|
||||
$resourceMetadata = $this->registry->getByClass($className);
|
||||
} catch (\InvalidArgumentException $exception) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$resourceMetadata->hasParameter('translation')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$translationResourceMetadata = $this->registry->get($resourceMetadata->getAlias().'_translation');
|
||||
|
||||
$metadata->mapOneToMany(array(
|
||||
'fieldName' => 'translations',
|
||||
'targetEntity' => $this->configs[$metadata->name]['translation']['classes']['model'],
|
||||
'targetEntity' => $translationResourceMetadata->getClass('model'),
|
||||
'mappedBy' => 'translatable',
|
||||
'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY,
|
||||
'indexBy' => 'locale',
|
||||
|
|
@ -91,15 +99,19 @@ class ORMTranslatableListener extends AbstractTranslatableListener implements Ev
|
|||
*/
|
||||
private function mapTranslation(ClassMetadata $metadata)
|
||||
{
|
||||
// In the case A -> B -> TranslationInterface, B might not have mapping defined as it
|
||||
// is probably defined in A, so in that case, we just return.
|
||||
if (!isset($this->configs[$metadata->name])) {
|
||||
$className = $metadata->name;
|
||||
|
||||
try {
|
||||
$resourceMetadata = $this->registry->getByClass($className);
|
||||
} catch (\InvalidArgumentException $exception) {
|
||||
return;
|
||||
}
|
||||
|
||||
$translatableResourceMetadata = $this->registry->get(str_replace('_translation', '', $resourceMetadata->getAlias()));
|
||||
|
||||
$metadata->mapManyToOne(array(
|
||||
'fieldName' => 'translatable' ,
|
||||
'targetEntity' => $this->configs[$metadata->name]['classes']['model'],
|
||||
'targetEntity' => $translatableResourceMetadata->getClass('model'),
|
||||
'inversedBy' => 'translations' ,
|
||||
'joinColumns' => array(array(
|
||||
'name' => 'translatable_id',
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@
|
|||
|
||||
<services>
|
||||
<service id="sylius.translation.translatable_listener.doctrine.orm" class="%sylius.translation.translatable_listener.doctrine.orm.class%">
|
||||
<argument type="service" id="sylius.resource_registry" />
|
||||
<argument type="service" id="sylius.translation.locale_provider" />
|
||||
<argument>%sylius.translation.mapping%</argument>
|
||||
<tag name="doctrine.event_subscriber" connection="default" priority="99" />
|
||||
</service>
|
||||
<service id="sylius.translation.translatable_listener.doctrine.mongodb_odm" class="%sylius.translation.translatable_listener.doctrine.mongodb_odm.class%">
|
||||
<argument type="service" id="sylius.resource_registry" />
|
||||
<argument type="service" id="sylius.translation.locale_provider" />
|
||||
<argument>%sylius.translation.mapping%</argument>
|
||||
<tag name="doctrine_mongodb.odm.event_subscriber" connection="default" priority="99" />
|
||||
</service>
|
||||
|
||||
|
|
|
|||
|
|
@ -60,13 +60,6 @@ class Configuration implements ConfigurationInterface
|
|||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
|
||||
->arrayNode('templates')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('user')->defaultValue('SyliusUserBundle:User')->end()
|
||||
->scalarNode('customer')->defaultValue('SyliusUserBundle:Customer')->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('resetting')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
|
|
@ -149,6 +142,7 @@ class Configuration implements ConfigurationInterface
|
|||
->arrayNode('customer')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('templates')->defaultValue('SyliusUserBundle:Customer')->end()
|
||||
->arrayNode('classes')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
|
|
@ -175,7 +169,23 @@ class Configuration implements ConfigurationInterface
|
|||
->children()
|
||||
->arrayNode('default')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius'))
|
||||
->defaultValue(array('sylius', 'sylius_customer_profile'))
|
||||
->end()
|
||||
->arrayNode('profile')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius', 'sylius_customer_profile'))
|
||||
->end()
|
||||
->arrayNode('registration')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius', 'sylius_customer_profile', 'sylius_user_registration'))
|
||||
->end()
|
||||
->arrayNode('simple_registration')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius', 'sylius_user_registration'))
|
||||
->end()
|
||||
->arrayNode('guest')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius_customer_guest'))
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
|
@ -184,6 +194,7 @@ class Configuration implements ConfigurationInterface
|
|||
->arrayNode('user')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('templates')->defaultValue('SyliusUserBundle:User')->end()
|
||||
->arrayNode('classes')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
|
|
@ -208,6 +219,10 @@ class Configuration implements ConfigurationInterface
|
|||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius'))
|
||||
->end()
|
||||
->arrayNode('registration')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius'))
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
namespace Sylius\Bundle\UserBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
|
|
@ -20,22 +22,26 @@ use Symfony\Component\DependencyInjection\Reference;
|
|||
*/
|
||||
class SyliusUserExtension extends AbstractResourceExtension
|
||||
{
|
||||
protected $configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$loader->load(sprintf('driver/%s.xml', $config['driver']));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml'
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.user.resetting.token_ttl', $config['resetting']['token']['ttl']);
|
||||
$container->setParameter('sylius.user.resetting.token_length', $config['resetting']['token']['length']);
|
||||
$container->setParameter('sylius.user.resetting.pin_length', $config['resetting']['pin']['length']);
|
||||
|
|
|
|||
|
|
@ -12,11 +12,13 @@
|
|||
namespace Sylius\Bundle\VariationBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Product catalog extension.
|
||||
* Archetype extension.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
|
|
@ -27,55 +29,69 @@ class SyliusVariationExtension extends AbstractResourceExtension
|
|||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->configure(
|
||||
$config,
|
||||
new Configuration(),
|
||||
$container,
|
||||
self::CONFIGURE_LOADER | self::CONFIGURE_DATABASE | self::CONFIGURE_PARAMETERS | self::CONFIGURE_VALIDATORS | self::CONFIGURE_TRANSLATIONS | self::CONFIGURE_FORMS
|
||||
$config = $this->processConfiguration(new Configuration(), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $this->resolveResources($config['resources'], $container), $container);
|
||||
|
||||
foreach ($config['resources'] as $variable => $parameters) {
|
||||
$this->createvariableServices($container, $variable);
|
||||
}
|
||||
|
||||
foreach ($config['resources'] as $variableName => $variableConfig) {
|
||||
foreach ($variableConfig as $resourceName => $resourceConfig) {
|
||||
if (!is_array($resourceConfig)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$formDefinition = $container->getDefinition('sylius.form.type.'.$variableName.'_'.$resourceName);
|
||||
$formDefinition->addArgument($variableName);
|
||||
|
||||
if (isset($resourceConfig['translation'])) {
|
||||
$formTranslationDefinition = $container->getDefinition('sylius.form.type.'.$variableName.'_'.$resourceName.'_translation');
|
||||
$formTranslationDefinition->addArgument($variableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$configFiles = array(
|
||||
'services.xml',
|
||||
);
|
||||
|
||||
foreach ($config['resources'] as $resource => $parameters) {
|
||||
$formDefinition = $container->getDefinition('sylius.form.type.'.$resource);
|
||||
$formDefinition->addArgument($parameters['variable']);
|
||||
|
||||
if (isset($parameters['translation'])) {
|
||||
$formTranslationDefinition = $container->getDefinition('sylius.form.type.'.$resource.'_translation');
|
||||
$formTranslationDefinition->addArgument($parameters['variable']);
|
||||
}
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Resolve resources for every subject.
|
||||
*
|
||||
* @param array $resources
|
||||
* @param ContainerBuilder $container
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function process(array $config, ContainerBuilder $container)
|
||||
private function resolveResources(array $resources, ContainerBuilder $container)
|
||||
{
|
||||
$convertedConfig = array();
|
||||
$variables = array();
|
||||
|
||||
foreach ($config['resources'] as $resource => $parameters) {
|
||||
$variables[$resource] = $parameters;
|
||||
unset($parameters['variable']);
|
||||
|
||||
foreach ($parameters as $parameter => $classes) {
|
||||
$convertedConfig[$resource.'_'.$parameter] = $classes;
|
||||
$convertedConfig[$resource.'_'.$parameter]['variable'] = $resource;
|
||||
|
||||
if (!isset($classes['validation_groups'])) {
|
||||
$classes['validation_groups']['default'] = array('sylius');
|
||||
}
|
||||
}
|
||||
|
||||
$this->createvariableServices($container, $resource);
|
||||
|
||||
|
||||
foreach ($resources as $variable => $parameters) {
|
||||
$variables[$variable] = $parameters;
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.variation.variables', $variables);
|
||||
|
||||
$config['resources'] = $convertedConfig;
|
||||
$resolvedResources = array();
|
||||
|
||||
return parent::process($config, $container);
|
||||
foreach ($resources as $variableName => $variableConfig) {
|
||||
foreach ($variableConfig as $resourceName => $resourceConfig) {
|
||||
if (is_array($resourceConfig)) {
|
||||
$resolvedResources[$variableName.'_'.$resourceName] = $resourceConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $resolvedResources;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -89,7 +105,6 @@ class SyliusVariationExtension extends AbstractResourceExtension
|
|||
$variantAlias = $variable.'_variant';
|
||||
$optionValueAlias = $variable.'_option_value';
|
||||
|
||||
|
||||
$variantChoiceFormType = new Definition('Sylius\Bundle\VariationBundle\Form\Type\VariantChoiceType');
|
||||
$variantChoiceFormType
|
||||
->setArguments(array($variable))
|
||||
|
|
@ -106,7 +121,6 @@ class SyliusVariationExtension extends AbstractResourceExtension
|
|||
|
||||
$container->setDefinition('sylius.form.type.'.$variantAlias.'_match', $variantMatchFormType);
|
||||
|
||||
|
||||
$optionValueChoiceFormType = new Definition('Sylius\Bundle\VariationBundle\Form\Type\OptionValueChoiceType');
|
||||
$optionValueChoiceFormType
|
||||
->setArguments(array($variable))
|
||||
|
|
|
|||
|
|
@ -7,4 +7,6 @@ CHANGELOG
|
|||
* ``createNew`` method removed from RepositoryInterface.
|
||||
* Introduce InMemoryRepository for object storage using the memory.
|
||||
* Extracted ``getId`` method into ResourceInterface.
|
||||
* Extended RepositoryInterface by ``add`` and ``remove`` methods
|
||||
* Extended RepositoryInterface by ``add`` and ``remove`` methods.
|
||||
* Introduce Metadata class for easier handling of resource configurations.
|
||||
* Add Registry to hold all resources in the system.
|
||||
|
|
|
|||
184
src/Sylius/Component/Resource/Metadata/Metadata.php
Normal file
184
src/Sylius/Component/Resource/Metadata/Metadata.php
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Resource\Metadata;
|
||||
|
||||
use Doctrine\Common\Inflector\Inflector;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class Metadata implements MetadataInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $applicationName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $driver;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $templatesNamespace;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $parameters;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $applicationName
|
||||
* @param array $parameters
|
||||
*/
|
||||
private function __construct($name, $applicationName, array $parameters)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->applicationName = $applicationName;
|
||||
|
||||
$this->driver = $parameters['driver'];
|
||||
$this->templatesNamespace = array_key_exists('templates', $parameters) ? $parameters['templates'] : null;
|
||||
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function fromAliasAndConfiguration($alias, array $parameters)
|
||||
{
|
||||
list($applicationName, $name) = self::parseAlias($alias);
|
||||
|
||||
return new self($name, $applicationName, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAlias()
|
||||
{
|
||||
return $this->applicationName.'.'.$this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getApplicationName()
|
||||
{
|
||||
return $this->applicationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPluralName()
|
||||
{
|
||||
return Inflector::pluralize($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDriver()
|
||||
{
|
||||
return $this->driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTemplatesNamespace()
|
||||
{
|
||||
return $this->templatesNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParameter($name)
|
||||
{
|
||||
if (!$this->hasParameter($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('Parameter "%s" is not configured for resource "%s".', $name, $this->getAlias()));
|
||||
}
|
||||
|
||||
return $this->parameters[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasParameter($name)
|
||||
{
|
||||
return array_key_exists($name, $this->parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getClass($name)
|
||||
{
|
||||
if (!$this->hasClass($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('Class "%s" is not configured for resource "%s".', $name, $this->getAlias()));
|
||||
}
|
||||
|
||||
return $this->parameters['classes'][$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasClass($name)
|
||||
{
|
||||
return isset($this->parameters['classes'][$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getServiceId($serviceName)
|
||||
{
|
||||
return sprintf('%s.%s.%s', $this->applicationName, $serviceName, $this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function parseAlias($alias)
|
||||
{
|
||||
if (false === strpos($alias, '.')) {
|
||||
throw new \InvalidArgumentException('Invalid alias supplied, it should conform to the following format "<applicationName>.<name>".');
|
||||
}
|
||||
|
||||
return explode('.', $alias);
|
||||
}
|
||||
}
|
||||
87
src/Sylius/Component/Resource/Metadata/MetadataInterface.php
Normal file
87
src/Sylius/Component/Resource/Metadata/MetadataInterface.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Resource\Metadata;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
interface MetadataInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAlias();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getApplicationName();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPluralName();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDriver();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplatesNamespace();
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function getParameter($name);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasParameter($name);
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function getClass($name);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasClass($name);
|
||||
|
||||
/**
|
||||
* @param string $serviceName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceId($serviceName);
|
||||
}
|
||||
73
src/Sylius/Component/Resource/Metadata/Registry.php
Normal file
73
src/Sylius/Component/Resource/Metadata/Registry.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Resource\Metadata;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class Registry implements RegistryInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $metadata = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($alias)
|
||||
{
|
||||
if (!array_key_exists($alias, $this->metadata)) {
|
||||
throw new \InvalidArgumentException(sprintf('Resource "%s" does not exist.', $alias));
|
||||
}
|
||||
|
||||
return $this->metadata[$alias];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getByClass($className)
|
||||
{
|
||||
foreach ($this->metadata as $metadata) {
|
||||
if ($className === $metadata->getClass('model')) {
|
||||
return $metadata;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('Resource with model class "%s" does not exist.', $className));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add(MetadataInterface $metadata)
|
||||
{
|
||||
$this->metadata[$metadata->getAlias()] = $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFromAliasAndConfiguration($alias, array $configuration)
|
||||
{
|
||||
$this->add(Metadata::fromAliasAndConfiguration($alias, $configuration));
|
||||
}
|
||||
}
|
||||
50
src/Sylius/Component/Resource/Metadata/RegistryInterface.php
Normal file
50
src/Sylius/Component/Resource/Metadata/RegistryInterface.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Resource\Metadata;
|
||||
|
||||
/**
|
||||
* Interface for the registry of all resources.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
interface RegistryInterface
|
||||
{
|
||||
/**
|
||||
* @return MetadataInterface[]
|
||||
*/
|
||||
public function getAll();
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
*
|
||||
* @return MetadataInterface
|
||||
*/
|
||||
public function get($alias);
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
*
|
||||
* @return MetadataInterface
|
||||
*/
|
||||
public function getByClass($className);
|
||||
|
||||
/**
|
||||
* @param MetadataInterface $metadata
|
||||
*/
|
||||
public function add(MetadataInterface $metadata);
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
* @param array $configuration
|
||||
*/
|
||||
public function addFromAliasAndConfiguration($alias, array $configuration);
|
||||
}
|
||||
125
src/Sylius/Component/Resource/spec/Metadata/MetadataSpec.php
Normal file
125
src/Sylius/Component/Resource/spec/Metadata/MetadataSpec.php
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace spec\Sylius\Component\Resource\Metadata;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class MetadataSpec extends ObjectBehavior
|
||||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedThrough('fromAliasAndConfiguration', array(
|
||||
'app.product',
|
||||
array(
|
||||
'driver' => 'doctrine/orm',
|
||||
'templates' => 'SyliusProductBundle:Product',
|
||||
'classes' => array(
|
||||
'model' => 'Sylius\Component\Product\Model\Product',
|
||||
'form' => array(
|
||||
'default' => 'Sylius\Bundle\ProductBundle\Form\Type\ProductType',
|
||||
'choice' => 'Sylius\Bundle\ResourceBundle\Form\Type\ResourceChoiceType',
|
||||
'autocomplete' => 'Sylius\Bundle\ResourceBundle\Type\ResourceAutocompleteType'
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Component\Resource\Metadata\Metadata');
|
||||
}
|
||||
|
||||
function it_implements_metadata_interface()
|
||||
{
|
||||
$this->shouldImplement('Sylius\Component\Resource\Metadata\MetadataInterface');
|
||||
}
|
||||
|
||||
function it_has_alias()
|
||||
{
|
||||
$this->getAlias()->shouldReturn('app.product');
|
||||
}
|
||||
|
||||
function it_has_application_name()
|
||||
{
|
||||
$this->getApplicationName()->shouldReturn('app');
|
||||
}
|
||||
|
||||
function it_has_resource_name()
|
||||
{
|
||||
$this->getName()->shouldReturn('product');
|
||||
}
|
||||
|
||||
function it_has_plural_resource_name()
|
||||
{
|
||||
$this->getPluralName()->shouldReturn('products');
|
||||
}
|
||||
|
||||
function it_has_driver()
|
||||
{
|
||||
$this->getDriver()->shouldReturn('doctrine/orm');
|
||||
}
|
||||
|
||||
function it_has_templates_namespace()
|
||||
{
|
||||
$this->getTemplatesNamespace()->shouldReturn('SyliusProductBundle:Product');
|
||||
}
|
||||
|
||||
function it_has_access_to_specific_config_parameter()
|
||||
{
|
||||
$this->getParameter('driver')->shouldReturn('doctrine/orm');
|
||||
}
|
||||
|
||||
function it_checks_if_specific_parameter_exists()
|
||||
{
|
||||
$this->hasParameter('foo')->shouldReturn(false);
|
||||
$this->hasParameter('driver')->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_throws_an_exception_when_parameter_does_not_exist()
|
||||
{
|
||||
$this
|
||||
->shouldThrow(\InvalidArgumentException::class)
|
||||
->during('getParameter', array('foo'))
|
||||
;
|
||||
}
|
||||
|
||||
function it_has_access_to_specific_classes()
|
||||
{
|
||||
$this->getClass('model')->shouldReturn('Sylius\Component\Product\Model\Product');
|
||||
}
|
||||
|
||||
function it_throws_an_exception_when_class_does_not_exist()
|
||||
{
|
||||
$this
|
||||
->shouldThrow(\InvalidArgumentException::class)
|
||||
->during('getClass', array('foo'))
|
||||
;
|
||||
}
|
||||
|
||||
function it_checks_if_specific_class_exists()
|
||||
{
|
||||
$this->hasClass('bar')->shouldReturn(false);
|
||||
$this->hasClass('model')->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_generates_service_id()
|
||||
{
|
||||
$this->getServiceId('factory')->shouldReturn('app.factory.product');
|
||||
$this->getServiceId('repository')->shouldReturn('app.repository.product');
|
||||
$this->getServiceId('form.type')->shouldReturn('app.form.type.product');
|
||||
}
|
||||
}
|
||||
95
src/Sylius/Component/Resource/spec/Metadata/RegistrySpec.php
Normal file
95
src/Sylius/Component/Resource/spec/Metadata/RegistrySpec.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace spec\Sylius\Component\Resource\Metadata;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Component\Resource\Metadata\MetadataInterface;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class RegistrySpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Component\Resource\Metadata\Registry');
|
||||
}
|
||||
|
||||
function it_implements_registry_interface()
|
||||
{
|
||||
$this->shouldImplement('Sylius\Component\Resource\Metadata\RegistryInterface');
|
||||
}
|
||||
|
||||
function it_returns_all_resources_metadata(MetadataInterface $metadata1, MetadataInterface $metadata2)
|
||||
{
|
||||
$metadata1->getAlias()->willReturn('app.product');
|
||||
$metadata2->getAlias()->willReturn('app.order');
|
||||
|
||||
$this->add($metadata1);
|
||||
$this->add($metadata2);
|
||||
|
||||
$this->getAll()->shouldReturn(array('app.product' => $metadata1, 'app.order' => $metadata2));
|
||||
}
|
||||
|
||||
function it_throws_an_exception_if_resource_is_not_registered()
|
||||
{
|
||||
$this
|
||||
->shouldThrow(\InvalidArgumentException::class)
|
||||
->during('get', array('foo.bar'))
|
||||
;
|
||||
}
|
||||
|
||||
function it_returns_specific_metadata(MetadataInterface $metadata)
|
||||
{
|
||||
$metadata->getAlias()->willReturn('app.shipping_method');
|
||||
|
||||
$this->add($metadata);
|
||||
|
||||
$this->get('app.shipping_method')->shouldReturn($metadata);
|
||||
}
|
||||
|
||||
function it_throws_an_exception_if_resource_is_not_registered_with_class()
|
||||
{
|
||||
$this
|
||||
->shouldThrow(\InvalidArgumentException::class)
|
||||
->during('getByClass', array('App\Model\OrderItem'))
|
||||
;
|
||||
}
|
||||
|
||||
function it_returns_specific_metadata_by_model_class(MetadataInterface $metadata1, MetadataInterface $metadata2)
|
||||
{
|
||||
$metadata1->getAlias()->willReturn('app.product');
|
||||
$metadata1->getClass('model')->willReturn('App\Model\Product');
|
||||
|
||||
$metadata2->getAlias()->willReturn('app.order');
|
||||
$metadata2->getClass('model')->willReturn('App\Model\Order');
|
||||
|
||||
$this->add($metadata1);
|
||||
$this->add($metadata2);
|
||||
|
||||
$this->getByClass('App\Model\Order')->shouldReturn($metadata2);
|
||||
}
|
||||
|
||||
function it_adds_metadata_from_configuration_array()
|
||||
{
|
||||
$this->addFromAliasAndConfiguration('app.product', array(
|
||||
'driver' => 'doctrine/orm',
|
||||
'classes' => array(
|
||||
'model' => 'App\Model\Product'
|
||||
)
|
||||
));
|
||||
|
||||
$this->get('app.product')->shouldHaveType(MetadataInterface::class);
|
||||
$this->getByClass('App\Model\Product')->shouldHaveType(MetadataInterface::class);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue