Создать класс где унаследовать класс FileLoader
<?php namespace Acme\DemoBundle\Loader; use Symfony\Component\Yaml\Yaml; use Symfony\Component\Config\Loader\FileLoader; /** * YamlFileLoader loads Yaml routing files. */ class YamlFileLoader extends FileLoader { /** * Loads a Yaml file. * * @param string $file A Yaml file path * * @return array * * @throws \InvalidArgumentException When config can't be parsed */ public function load($file, $type = null) { $path = $this->locator->locate($file); $config = Yaml::parse($path); // empty file if (null === $config) { $config = array(); } // not an array if (!is_array($config)) { throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $file)); } return $config; } /** * 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 * * @api */ public function supports($resource, $type = null) { return is_string($resource) && 'yml' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'yaml' === $type); } }
Чтобы он был везде доступен нужно добавить в файле
DependencyInjection/
namespace Acme\DemoBundle\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; use Acme\DemoBundle\Loader\YamlFileLoader; /** * This is the class that loads and manages your bundle configuration * * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} */ class AcmeDemoExtension extends Extension { /** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); // until here everything is default config (for your DIC services) $ymlLoader = new YamlFileLoader(new FileLocator(__DIR__.'/../Resources/config')); $container->setParameter('param_name', $ymlLoader->load('yaml_file_name'))); // load yml file contents as an array } }
теперь чтобы получить содержимое нужного yaml файла достаточно его вызвать
$yaml_product = $this->container->getParameter('param_name')