5 Commits

Author SHA1 Message Date
tim
dacf3d6687 Allow symfony 6 2022-01-30 01:15:39 +01:00
tim
cd3c5a0a52 Allow for bool type as config type 2022-01-30 01:11:39 +01:00
da8a1e37ca Fix line endings? 2021-07-21 00:25:37 +02:00
d20f7401c1 Add categories overview 2020-10-23 23:39:45 +02:00
69abbcaf4b Improve phpdocs of service 2020-07-27 01:23:13 +02:00
9 changed files with 775 additions and 761 deletions

View File

@ -60,10 +60,8 @@ abstract class BaseController extends AbstractController
switch ($type) {
case CheckboxType::class:
return boolval($value);
break;
default:
return $value;
break;
}
}

View File

@ -1,41 +1,41 @@
<?php
namespace Ardent\ParameterBundle\Controller;
use Ardent\ParameterBundle\Service\ParameterService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class ParameterController extends BaseController
{
/**
* @Route("/{category}", name="parameter_bundle_parameters")
*/
public function parameters($category,
ParameterService $param,
Request $request)
{
$configs = $param->getConfig();
// 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' === $category) { // 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[$category]);
}
}
<?php
namespace Ardent\ParameterBundle\Controller;
use Ardent\ParameterBundle\Service\ParameterService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class ParameterController extends BaseController
{
/**
* @Route("/{category}", name="parameter_bundle_parameters")
*/
public function parameters($category = 'categories',
ParameterService $param,
Request $request)
{
$configs = $param->getConfig();
// Handle all special cases for the name
if ('categories' === $category) { // List all the categories
$categories = [];
foreach ($configs as $key => $config) {
$categories[] = $key;
}
$categories[] = 'all';
return $this->render('@ArdentParameter/categories.html.twig', ['categories' => $categories]);
} elseif ('all' === $category) { // 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[$category]);
}
}
}

View File

@ -1,38 +1,39 @@
<?php
namespace Ardent\ParameterBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public const TYPE_TEXT = 'text';
public const TYPE_NUMBER = 'number';
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('ardent_parameter');
$treeBuilder->getRootNode()
->children()
->arrayNode('parameters')
->arrayPrototype()
->arrayPrototype()
->children()
->scalarNode('name')->end()
->enumNode('type')
->values([self::TYPE_TEXT, self::TYPE_NUMBER])
->defaultValue(self::TYPE_TEXT)
->end()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
}
<?php
namespace Ardent\ParameterBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public const TYPE_TEXT = 'text';
public const TYPE_NUMBER = 'number';
public const TYPE_BOOL = 'bool';
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('ardent_parameter');
$treeBuilder->getRootNode()
->children()
->arrayNode('parameters')
->arrayPrototype()
->arrayPrototype()
->children()
->scalarNode('name')->end()
->enumNode('type')
->values([self::TYPE_TEXT, self::TYPE_NUMBER, self::TYPE_BOOL])
->defaultValue(self::TYPE_TEXT)
->end()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
}
}

1346
LICENSE

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
{% extends '@ArdentParameter/layout.html.twig' %}
{% block par_user_content %}
<h2>Parameter categories</h2><br>
{% for category in categories %}
<a class="btn-primary btn" href="{{ path('parameter_bundle_parameters', {category:category}) }}">{{ category }}</a><br><br>
{% endfor %}
{% endblock %}

View File

@ -0,0 +1 @@
{# Add extra content on the bottom of the form #}

View File

@ -1,8 +1,8 @@
{% extends '@ArdentParameter/layout.html.twig' %}
{% block par_user_content %}
<a class="btn-primary btn" href="{{ path('parameter_bundle_parameters', {category:'categories'}) }}">Back</a> <br><br>
{{ form(parameter_form) }}
{% include '@ArdentParameter/form.extra.html.twig' %}
{% endblock %}

View File

@ -6,6 +6,7 @@ use Ardent\ParameterBundle\DependencyInjection\Configuration;
use Ardent\ParameterBundle\Entity\Parameter;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
@ -33,10 +34,10 @@ class ParameterService
}
/**
* @param string $name
* @param bool $parse
* @param string $name The name of the parameter in the format <group>_<parameter>
* @param bool $parse Whether to parse embedded %parameter%'s
*
* @return string
* @return mixed
*/
public function get($name, $parse = true)
{
@ -67,8 +68,8 @@ class ParameterService
}
/**
* @param $name
* @param $value
* @param string $name The name of the parameter in the format <group>_<parameter>
* @param mixed $value
*/
public function set($name, $value)
{
@ -101,8 +102,12 @@ class ParameterService
case Configuration::TYPE_NUMBER:
$class = NumberType::class;
break;
case Configuration::TYPE_BOOL:
$class = CheckboxType::class;
break;
}
// Add the group name in front of the parameter name
$value['name'] = sprintf('%s_%s', $groupName, $value['name']);
$value['type'] = $class;
unset($value);

View File

@ -3,9 +3,9 @@
"description": "Simple bundle for storing parameters in a database",
"type": "symfony-bundle",
"require": {
"doctrine/orm": "^2.7",
"symfony/form": "^5.0",
"symfony/twig-bundle": "^5.0"
"doctrine/orm": "^2.0",
"symfony/form": "^5.0|^6.0",
"symfony/twig-bundle": "^5.0|^6.0"
},
"autoload": {
"psr-4": {