ClassMetadataExporter.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information, see
  19. * <http://www.doctrine-project.org>.
  20. */
  21. namespace Doctrine\ORM\Tools\Export;
  22. use Doctrine\ORM\Tools\Export\ExportException,
  23. Doctrine\ORM\EntityManager;
  24. /**
  25. * Class used for converting your mapping information between the
  26. * supported formats: yaml, xml, and php/annotation.
  27. *
  28. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  29. * @link www.doctrine-project.org
  30. * @since 2.0
  31. * @version $Revision$
  32. * @author Jonathan Wage <jonwage@gmail.com>
  33. */
  34. class ClassMetadataExporter
  35. {
  36. private static $_exporterDrivers = array(
  37. 'xml' => 'Doctrine\ORM\Tools\Export\Driver\XmlExporter',
  38. 'yaml' => 'Doctrine\ORM\Tools\Export\Driver\YamlExporter',
  39. 'yml' => 'Doctrine\ORM\Tools\Export\Driver\YamlExporter',
  40. 'php' => 'Doctrine\ORM\Tools\Export\Driver\PhpExporter',
  41. 'annotation' => 'Doctrine\ORM\Tools\Export\Driver\AnnotationExporter'
  42. );
  43. /**
  44. * Register a new exporter driver class under a specified name
  45. *
  46. * @param string $name
  47. * @param string $class
  48. */
  49. public static function registerExportDriver($name, $class)
  50. {
  51. self::$_exporterDrivers[$name] = $class;
  52. }
  53. /**
  54. * Get a exporter driver instance
  55. *
  56. * @param string $type The type to get (yml, xml, etc.)
  57. * @param string $source The directory where the exporter will export to
  58. * @return AbstractExporter $exporter
  59. */
  60. public function getExporter($type, $dest = null)
  61. {
  62. if ( ! isset(self::$_exporterDrivers[$type])) {
  63. throw ExportException::invalidExporterDriverType($type);
  64. }
  65. $class = self::$_exporterDrivers[$type];
  66. return new $class($dest);
  67. }
  68. }