-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from w-vision/child-definitions
Child definitions
- Loading branch information
Showing
24 changed files
with
926 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* CoreShop. | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2015-2017 Dominik Pfaffenbauer (https://www.pfaffenbauer.at) | ||
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
namespace ImportDefinitionsBundle\Event; | ||
|
||
use CoreShop\Bundle\ResourceBundle\Event\ResourceControllerEvent; | ||
use CoreShop\Component\Resource\Metadata\MetadataInterface; | ||
use CoreShop\Component\Resource\Model\ResourceInterface; | ||
use ImportDefinitionsBundle\Model\DefinitionInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class EventDispatcher implements EventDispatcherInterface | ||
{ | ||
/** | ||
* @var SymfonyEventDispatcherInterface | ||
*/ | ||
private $eventDispatcher; | ||
|
||
/** | ||
* @param SymfonyEventDispatcherInterface $eventDispatcher | ||
*/ | ||
public function __construct(SymfonyEventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function dispatch(DefinitionInterface $definition, $eventName, $subject = '', $params = []) | ||
{ | ||
$event = $this->getEvent($definition, $subject, $params); | ||
|
||
$this->eventDispatcher->dispatch( | ||
sprintf('%s%s', $eventName, isset($params['child']) && $params['child'] ? '.child' : ''), | ||
$event | ||
); | ||
} | ||
|
||
/** | ||
* @param DefinitionInterface $definition | ||
* @param string $subject | ||
* @param array $params | ||
* @return ImportDefinitionEvent | ||
*/ | ||
private function getEvent(DefinitionInterface $definition, $subject = '', $params = []) | ||
{ | ||
return new ImportDefinitionEvent($definition, $subject, $params); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/ImportDefinitionsBundle/Event/EventDispatcherInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* CoreShop. | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2015-2017 Dominik Pfaffenbauer (https://www.pfaffenbauer.at) | ||
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
namespace ImportDefinitionsBundle\Event; | ||
|
||
use CoreShop\Bundle\ResourceBundle\Event\ResourceControllerEvent; | ||
use CoreShop\Component\Resource\Metadata\MetadataInterface; | ||
use CoreShop\Component\Resource\Model\ResourceInterface; | ||
use ImportDefinitionsBundle\Model\DefinitionInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
interface EventDispatcherInterface | ||
{ | ||
/** | ||
* @param DefinitionInterface $definition | ||
* @param $eventName | ||
* @param string $subject | ||
* @param array $params | ||
* @return mixed | ||
*/ | ||
public function dispatch(DefinitionInterface $definition, $eventName, $subject = '', $params = []); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/ImportDefinitionsBundle/Form/Type/DefinitionChoiceType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Import Definitions. | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch) | ||
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
namespace ImportDefinitionsBundle\Form\Type; | ||
|
||
use CoreShop\Component\Resource\Repository\RepositoryInterface; | ||
use ImportDefinitionsBundle\Model\DefinitionInterface; | ||
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\Options; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
final class DefinitionChoiceType extends AbstractType | ||
{ | ||
/** | ||
* @var RepositoryInterface | ||
*/ | ||
private $definitionRepository; | ||
|
||
/** | ||
* @param RepositoryInterface $definitionRepository | ||
*/ | ||
public function __construct(RepositoryInterface $definitionRepository) | ||
{ | ||
$this->definitionRepository = $definitionRepository; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
if ($options['multiple']) { | ||
$builder->addModelTransformer(new CollectionToArrayTransformer()); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver | ||
->setDefaults( | ||
[ | ||
'choices' => function (Options $options) { | ||
return array_map(function(DefinitionInterface $def) { | ||
return $def->getId(); | ||
}, $this->definitionRepository->findAll()); | ||
}, | ||
'choice_label' => function($val) { | ||
$def = $this->definitionRepository->find($val); | ||
|
||
return $def->getName(); | ||
}, | ||
'choice_translation_domain' => false, | ||
'active' => true, | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getParent() | ||
{ | ||
return ChoiceType::class; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBlockPrefix() | ||
{ | ||
return 'import_definitions_definition_choice'; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/ImportDefinitionsBundle/Form/Type/Interpreter/ConditionalInterpreterType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Import Definitions. | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch) | ||
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
namespace ImportDefinitionsBundle\Form\Type\Interpreter; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
final class ConditionalInterpreterType extends AbstractType | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder | ||
->add('condition', TextType::class) | ||
->add('true_interpreter', InterpreterType::class) | ||
->add('false_interpreter', InterpreterType::class) | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBlockPrefix() | ||
{ | ||
return 'import_definitions_interpreter_conditional'; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/ImportDefinitionsBundle/Form/Type/Interpreter/DefinitionType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Import Definitions. | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch) | ||
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
namespace ImportDefinitionsBundle\Form\Type\Interpreter; | ||
|
||
use ImportDefinitionsBundle\Form\Type\ClassChoiceType; | ||
use ImportDefinitionsBundle\Form\Type\DefinitionChoiceType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
class DefinitionType extends AbstractType | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder | ||
->add('definition', DefinitionChoiceType::class) | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBlockPrefix() | ||
{ | ||
return 'import_definitions_interpreter_definition'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.