Skip to content

Instantly share code, notes, and snippets.

@jaytaph
Last active December 11, 2015 22:49
Show Gist options
  • Save jaytaph/4672123 to your computer and use it in GitHub Desktop.
Save jaytaph/4672123 to your computer and use it in GitHub Desktop.
class AppKernel extends Kernel
{
...
/**
* Add loader to load settings from /etc/bigproject/settings.conf
*/
protected function getContainerLoader(ContainerInterface $container)
{
$cl = parent::getContainerLoader($container);
// Add additional loader to the resolver
$resolver = $cl->getResolver();
$resolver->addLoader(new BigProject\MainBundle\ConfFileLoader($container, new FileLocator(array())));
return $cl;
}
}
<?php
namespace BigProject\MainBundle;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Loader\FileLoader;
class ConfFileLoader extends FileLoader
{
/**
* Loads a resource.
*
* @param mixed $file The resource
* @param string $type The resource type
*
* @throws InvalidArgumentException When ini file is not valid
*/
public function load($file, $type = null)
{
$path = $this->locator->locate($file);
$this->container->addResource(new FileResource($path));
$result = parse_ini_file($path, true);
if (false === $result || array() === $result) {
throw new InvalidArgumentException(sprintf('The "%s" file is not valid.', $file));
}
foreach ($result as $key => $section) {
foreach ($section as $name => $value) {
$this->container->setParameter($key.".".$name, $value);
}
}
}
/**
* Returns true if this class supports the given resource.
*
* @param mixed $resource A resource
* @param string $type The resource type
*
* @return Boolean true if this class supports the given resource, false otherwise
*/
public function supports($resource, $type = null)
{
return is_string($resource) && 'conf' === pathinfo($resource, PATHINFO_EXTENSION);
}
}
imports:
- { resource: parameters.yml }
....
markup_solarium:
clients:
default:
host: %solr.host%
port: %solr.port%
path: %solr.path%
core: %solr.core%
timeout: 5
[solr]
host = 10.10.1.10
port = 8080
path = /solr
core = mycore
parameters:
solr.host: 10.10.1.10
solr.port: 8080
solr.path: /solr
solr.core: mycore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment