Add config and controller to use the config
This commit is contained in:
parent
a2c17d4be3
commit
db970b4c69
@ -40,6 +40,7 @@ abstract class BaseController extends AbstractController
|
|||||||
|
|
||||||
foreach ($configuration as $config) {
|
foreach ($configuration as $config) {
|
||||||
$name = $config['name'];
|
$name = $config['name'];
|
||||||
|
// Excluding the checkbox type from checking, because it will be null if not checked
|
||||||
if (null !== $result[$name] || CheckboxType::class == $config['type']) {
|
if (null !== $result[$name] || CheckboxType::class == $config['type']) {
|
||||||
$param->set($name, $result[$name]);
|
$param->set($name, $result[$name]);
|
||||||
}
|
}
|
||||||
|
64
Controller/ParameterController.php
Normal file
64
Controller/ParameterController.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Ardent\ParameterBundle\Controller;
|
||||||
|
|
||||||
|
|
||||||
|
use Ardent\ParameterBundle\Service\ParameterService;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
|
class ParameterController extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Route("/{name}", name="parameter_bundle_parameters")
|
||||||
|
*/
|
||||||
|
public function parameters($name,
|
||||||
|
ParameterService $param,
|
||||||
|
Request $request)
|
||||||
|
{
|
||||||
|
$config = $param->getConfig();
|
||||||
|
dump($config);
|
||||||
|
|
||||||
|
$configs = [
|
||||||
|
'transmission' => [
|
||||||
|
['name' => 'transmission_url', 'type' => TextType::class],
|
||||||
|
['name' => 'transmission_port', 'type' => NumberType::class],
|
||||||
|
['name' => 'transmission_username', 'type' => TextType::class],
|
||||||
|
['name' => 'transmission_password', 'type' => TextType::class],
|
||||||
|
['name' => 'transmission_path_local', 'type' => TextType::class],
|
||||||
|
['name' => 'transmission_path_remote', 'type' => TextType::class],
|
||||||
|
],
|
||||||
|
'animerss' => [
|
||||||
|
['name' => 'animerss_apikey', 'type' => TextType::class],
|
||||||
|
['name' => 'animerss_baseurl', 'type' => TextType::class],
|
||||||
|
],
|
||||||
|
'misc' => [
|
||||||
|
['name' => 'rss_url', 'type' => TextType::class],
|
||||||
|
['name' => 'torrent_quality', 'type' => TextType::class],
|
||||||
|
],
|
||||||
|
'all' => [], // Placeholder, lists all above values, it is captured a bit later
|
||||||
|
];
|
||||||
|
|
||||||
|
// Handle all special cases for the name
|
||||||
|
/*if ('list' === $name) { // List all the categories
|
||||||
|
$routes = [];
|
||||||
|
foreach ($configs as $key => $config) {
|
||||||
|
$routes[] = ['route' => 'parameters', 'params' => ['name' => $key], 'title' => $key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('list.routes.twig', ['routes' => $routes]);
|
||||||
|
} else*/if ('all' === $name) { // Show all parameters from all categories
|
||||||
|
$allConfigs = [];
|
||||||
|
foreach ($configs as $config) {
|
||||||
|
$allConfigs = array_merge($allConfigs, $config);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::baseIndex($param, $request, $allConfigs);
|
||||||
|
} else { // Show the parameters from one category
|
||||||
|
return parent::baseIndex($param, $request, $configs[$name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Ardent\ParameterBundle\DependencyInjection;
|
namespace Ardent\ParameterBundle\DependencyInjection;
|
||||||
|
|
||||||
use Ardent\ParameterBundle\Entity\Parameter;
|
|
||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||||
@ -14,8 +13,14 @@ class ArdentParameterExtension extends Extension
|
|||||||
{
|
{
|
||||||
$loader = new YamlFileLoader(
|
$loader = new YamlFileLoader(
|
||||||
$container,
|
$container,
|
||||||
new FileLocator(__DIR__.'/../Resources/config')
|
new FileLocator(dirname(__DIR__).'/Resources/config')
|
||||||
);
|
);
|
||||||
$loader->load('services.yaml');
|
$loader->load('services.yaml');
|
||||||
|
|
||||||
|
$configuration = new Configuration();
|
||||||
|
$config = $this->processConfiguration($configuration, $configs);
|
||||||
|
|
||||||
|
$def = $container->findDefinition('ardent.parameter');
|
||||||
|
$def->setArgument('$config', $config['parameters']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,35 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
|
|||||||
|
|
||||||
class Configuration implements ConfigurationInterface
|
class Configuration implements ConfigurationInterface
|
||||||
{
|
{
|
||||||
|
public const TYPE_TEXT = 'text';
|
||||||
|
public const TYPE_NUMBER = 'number';
|
||||||
|
|
||||||
public function getConfigTreeBuilder()
|
public function getConfigTreeBuilder()
|
||||||
{
|
{
|
||||||
$treeBuilder = new TreeBuilder('parameter_bundle');
|
$treeBuilder = new TreeBuilder('ardent_parameter');
|
||||||
|
|
||||||
$treeBuilder->getRootNode()
|
$treeBuilder->getRootNode()
|
||||||
->children()
|
->children()
|
||||||
|
->arrayNode('parameters')
|
||||||
|
->arrayPrototype()
|
||||||
|
->children()
|
||||||
|
->scalarNode('group')->defaultValue('misc')->end()
|
||||||
|
->arrayNode('values')
|
||||||
|
->arrayPrototype()
|
||||||
|
->children()
|
||||||
|
->scalarNode('name')->end()
|
||||||
|
->enumNode('type')
|
||||||
|
->values([self::TYPE_TEXT, self::TYPE_NUMBER])
|
||||||
|
->defaultValue(self::TYPE_TEXT)
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
->end();
|
->end();
|
||||||
|
|
||||||
|
return $treeBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,3 +5,8 @@ services:
|
|||||||
Ardent\ParameterBundle\Service\ParameterService:
|
Ardent\ParameterBundle\Service\ParameterService:
|
||||||
public: true
|
public: true
|
||||||
autowire: true
|
autowire: true
|
||||||
|
|
||||||
|
Ardent\ParameterBundle\Controller\:
|
||||||
|
resource: '../../Controller'
|
||||||
|
tags: ['controller.service_arguments']
|
||||||
|
autowire: true
|
@ -13,16 +13,20 @@ class ParameterService
|
|||||||
|
|
||||||
/** @var ParameterBagInterface */
|
/** @var ParameterBagInterface */
|
||||||
private $parameter;
|
private $parameter;
|
||||||
|
private $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ParameterService constructor.
|
* ParameterService constructor.
|
||||||
*
|
*
|
||||||
* @param EntityManagerInterface $em
|
* @param EntityManagerInterface $em
|
||||||
|
* @param ParameterBagInterface $parameter
|
||||||
|
* @param $config
|
||||||
*/
|
*/
|
||||||
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameter)
|
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameter, $config)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->parameter = $parameter;
|
$this->parameter = $parameter;
|
||||||
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,4 +79,12 @@ class ParameterService
|
|||||||
$this->em->persist($parameter);
|
$this->em->persist($parameter);
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getConfig()
|
||||||
|
{
|
||||||
|
return $this->config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user