-
Notifications
You must be signed in to change notification settings - Fork 5
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 #4 from sherlockode/feature/field_types
Handle field types with strategy
- Loading branch information
Showing
9 changed files
with
145 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Sherlockode\ConfigurationBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class FieldTypePass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$definition = $container->findDefinition('sherlockode_configuration.field_manager'); | ||
$taggedServices = $container->findTaggedServiceIds('sherlockode_configuration.field'); | ||
|
||
foreach ($taggedServices as $id => $tags) { | ||
$definition->addMethodCall('addFieldType', [new Reference($id)]); | ||
} | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Sherlockode\ConfigurationBundle\FieldType; | ||
|
||
interface FieldTypeInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getFormType(); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getFormOptions(); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(); | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Sherlockode\ConfigurationBundle\FieldType; | ||
|
||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
|
||
class TextField implements FieldTypeInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getFormType() | ||
{ | ||
return TextType::class; | ||
} | ||
|
||
public function getFormOptions() | ||
{ | ||
return []; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'text'; | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
namespace Sherlockode\ConfigurationBundle\Manager; | ||
|
||
use Sherlockode\ConfigurationBundle\FieldType\FieldTypeInterface; | ||
|
||
class FieldTypeManager | ||
{ | ||
/** | ||
* @var FieldTypeInterface[] | ||
*/ | ||
private $fieldTypes; | ||
|
||
public function __construct() | ||
{ | ||
$this->fieldTypes = []; | ||
} | ||
|
||
/** | ||
* @param FieldTypeInterface $fieldType | ||
* | ||
* @return $this | ||
*/ | ||
public function addFieldType(FieldTypeInterface $fieldType) | ||
{ | ||
$this->fieldTypes[$fieldType->getName()] = $fieldType; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* | ||
* @return FieldTypeInterface | ||
* @throws \Exception | ||
*/ | ||
public function getField($type) | ||
{ | ||
if (!isset($this->fieldTypes[$type])) { | ||
throw new \Exception(sprintf('Unknown parameter type "%s"', $type)); | ||
} | ||
|
||
return $this->fieldTypes[$type]; | ||
} | ||
} |
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,5 @@ | ||
services: | ||
sherlockode_configuration.field.text: | ||
class: Sherlockode\ConfigurationBundle\FieldType\TextField | ||
tags: | ||
- {name: sherlockode_configuration.field } |
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