generateSql.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. require_once __DIR__.'/../../../../ClassLoader/ClassLoader.php';
  11. use Symfony\Component\ClassLoader\ClassLoader;
  12. use Symfony\Component\Finder\Finder;
  13. use Symfony\Component\Security\Acl\Dbal\Schema;
  14. $loader = new ClassLoader();
  15. $loader->addPrefixes(array(
  16. 'Symfony' => __DIR__.'/../../../../../..',
  17. 'Doctrine\\Common' => __DIR__.'/../../../../../../../vendor/doctrine-common/lib',
  18. 'Doctrine\\DBAL\\Migrations' => __DIR__.'/../../../../../../../vendor/doctrine-migrations/lib',
  19. 'Doctrine\\DBAL' => __DIR__.'/../../../../../../../vendor/doctrine/dbal/lib',
  20. 'Doctrine' => __DIR__.'/../../../../../../../vendor/doctrine/lib',
  21. ));
  22. $loader->register();
  23. $schema = new Schema(array(
  24. 'class_table_name' => 'acl_classes',
  25. 'entry_table_name' => 'acl_entries',
  26. 'oid_table_name' => 'acl_object_identities',
  27. 'oid_ancestors_table_name' => 'acl_object_identity_ancestors',
  28. 'sid_table_name' => 'acl_security_identities',
  29. ));
  30. $reflection = new ReflectionClass('Doctrine\\DBAL\\Platforms\\AbstractPlatform');
  31. $finder = new Finder();
  32. $finder->name('*Platform.php')->in(dirname($reflection->getFileName()));
  33. foreach ($finder as $file) {
  34. require_once $file->getPathName();
  35. $className = 'Doctrine\\DBAL\\Platforms\\'.$file->getBasename('.php');
  36. $reflection = new ReflectionClass($className);
  37. if ($reflection->isAbstract()) {
  38. continue;
  39. }
  40. $platform = $reflection->newInstance();
  41. $targetFile = sprintf(__DIR__.'/../schema/%s.sql', $platform->getName());
  42. file_put_contents($targetFile, implode("\n\n", $schema->toSql($platform)));
  43. }