sfRoutingConfigHandler.class.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * @package symfony
  11. * @subpackage config
  12. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  13. * @version SVN: $Id: sfRoutingConfigHandler.class.php 9085 2008-05-20 01:53:23Z Carl.Vondrick $
  14. */
  15. class sfRoutingConfigHandler extends sfYamlConfigHandler
  16. {
  17. /**
  18. * Executes this configuration handler.
  19. *
  20. * @param array $configFiles An array of absolute filesystem path to a configuration file
  21. *
  22. * @return string Data to be written to a cache file
  23. *
  24. * @throws sfConfigurationException If a requested configuration file does not exist or is not readable
  25. * @throws sfParseException If a requested configuration file is improperly formatted
  26. */
  27. public function execute($configFiles)
  28. {
  29. // parse the yaml
  30. $config = self::getConfiguration($configFiles);
  31. // connect routes
  32. $data = array();
  33. foreach ($config as $name => $params)
  34. {
  35. $data[] = sprintf('$this->connect(\'%s\', \'%s\', %s, %s);',
  36. $name,
  37. $params['url'] ? $params['url'] : '/',
  38. isset($params['param']) ? var_export($params['param'], true) : 'array()',
  39. isset($params['requirements']) ? var_export($params['requirements'], true) : 'array()'
  40. );
  41. }
  42. return sprintf("<?php\n".
  43. "// auto-generated by sfRoutingConfigHandler\n".
  44. "// date: %s\n%s\n", date('Y/m/d H:i:s'), implode("\n", $data)
  45. );
  46. }
  47. /**
  48. * @see sfConfigHandler
  49. */
  50. static public function getConfiguration(array $configFiles)
  51. {
  52. return self::parseYamls($configFiles);
  53. }
  54. }