sfDoctrineSchemasConfigHandler.class.php 1.53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
<?php
/*
 * This file is part of the sfDoctrine package.
 * (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 *
 * sfDoctrineSchemasConfigHandler parses the config/schemas.yml config file
 *
 * @package    symfony.plugins
 * @subpackage sfDoctrine
 * @author     Stephen Leavitt <stephen.leavitt@gmail.com>
 * @version    SVN: $Id$
 */
class sfDoctrineSchemasConfigHandler extends sfYamlConfigHandler
{
    public function execute( $configFiles )
    {
        $this->initialize();

        $mappings = $this->parseYamls( $configFiles );

        $data = array();

        $data[] = '$manager = Doctrine_Manager::getInstance();'."\n";

        foreach ( $mappings as $mapping => $schemas )
        {
            foreach ( $schemas as $schema )
            {
                $path = sfConfig::get( 'sf_config_dir' ) . '/doctrine/' . $schema . '.yml';
                $components = array_keys( sfYaml::load( $path ) );

                foreach ( $components as $component )
                {
                    $data[] = "\$manager->bindComponent('{$component}', '{$mapping}');";
                }
            }
        }

        // compile data
        $retval = sprintf("<?php\n".
                          "// auto-generated by sfDoctrineSchemasConfigHandler\n".
                          "// date: %s\n%s\n",
                          date('Y-m-d H:i:s'), implode("\n", $data));
 
        return $retval;
    }
}