Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for Boolean values #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions Command/ContainerInvalidateCommand.php

This file was deleted.

93 changes: 24 additions & 69 deletions Controller/ConfiguratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,44 @@
use Unifik\DatabaseConfigBundle\Form\ConfiguratorType;

/**
* Locale Controller
* Configurator Controller
*
* @package Unifik.DatabaseConfigBundle.Controller
*
* @author Guillaume Petit <[email protected]>
*/
class ConfiguratorController extends Controller
{

/**
* @return Response
*/
public function indexAction()
{
return $this->render('UnifikDatabaseConfigBundle::index.html.twig', array(
'bundles' => $this->getConfiguratorEnabledBundles()
));
}

/**
* Display a form to edit the configuration of a bundle
*
* @param Request $request
* @param string $bundleName
* @param Request $request the request
* @param string $bundleName the bundle name to be configured
* @param string $namespace the namespace of the extension
*
* @return Response
*/
public function editAction(Request $request, $bundleName)
public function editAction(Request $request, $bundleName, $namespace)
{
$extensionRepository = $this->getDoctrine()->getRepository('UnifikDatabaseConfigBundle:Extension');
$configRepository = $this->getDoctrine()->getRepository('UnifikDatabaseConfigBundle:Config');

$manager = $this->getDoctrine()->getManager();
$bundles = $this->get('kernel')->getBundles();

$tree = $this->getConfigurationTree($bundles[$bundleName]);
$extension = $extensionRepository->findOneByName($tree->getName());
$tree = $this->get('unifik_database_config.services.configuration')->getContainerConfigurationTree($bundles[$bundleName]);
$extension = $extensionRepository->findOneBy(
array(
'name' => $tree->getName(),
'namespace' => $namespace,
)
);

if (false == $extension) {
$extension = new Extension();
$extension->setName($tree->getName());
$extension->setNamespace($namespace);
}

$form = $this->createForm(new ConfiguratorType(), $extension, array('tree' => $tree));
Expand All @@ -66,67 +67,21 @@ public function editAction(Request $request, $bundleName)

$manager->persist($extension);
$manager->flush($extension);

$this->get('unifik_database_config.container_invalidator')->invalidate();
}
}

return $this->render('UnifikDatabaseConfigBundle::edit.html.twig', array(
'form' => $form->createView(),
'bundles' => $this->getConfiguratorEnabledBundles()
));
}

/**
* Check each bundle currently loaded in the kernel and validate configurator support
*
* @return array
*/
protected function getConfiguratorEnabledBundles()
{
$enabledBundles = array();
$bundles = $this->get('kernel')->getBundles();

foreach ($bundles as $name => $bundle) {
try {
if ($tree = $this->getConfigurationTree($bundle)) {
if ($tree && $this->isConfiguratorEnabledNode($tree)) {
$enabledBundles[] = $name;
}
}
} catch (\Exception $e) {
// skip error'd bundle
}
}

return $enabledBundles;
}

/**
* Return the configuration tree of a bundle or false if not defined
*
* @param BundleInterface $bundle
*
* @return mixed
*/
protected function getConfigurationTree(BundleInterface $bundle)
{
$extension = $bundle->getContainerExtension();

if ($extension) {
$configuration = $extension->getConfiguration(array(), new ContainerBuilder());
if ($configuration) {
return $configuration->getConfigTreeBuilder()->buildTree();
}
}

return false;
return $this->render(
'UnifikDatabaseConfigBundle::edit.html.twig',
array(
'form' => $form->createView(),
)
);
}

/**
* Check if a tree node is configuration enabled
*
* @param NodeInterface $arrayNode
* @param NodeInterface $arrayNode a node
*
* @return bool
*/
Expand Down
Loading