schema.php 905 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. use Cake\Utility\Inflector;
  3. $tables = [];
  4. /**
  5. * @var \DirectoryIterator<\DirectoryIterator> $iterator
  6. */
  7. $iterator = new DirectoryIterator(__DIR__ . DS . 'Fixture');
  8. foreach ($iterator as $file) {
  9. if (!preg_match('/(\w+)Fixture.php$/', (string)$file, $matches)) {
  10. continue;
  11. }
  12. $name = $matches[1];
  13. $tableName = Inflector::underscore($name);
  14. $class = 'Tools\\Test\\Fixture\\' . $name . 'Fixture';
  15. try {
  16. $object = (new ReflectionClass($class))->getProperty('fields');
  17. } catch (ReflectionException $e) {
  18. continue;
  19. }
  20. $array = $object->getDefaultValue();
  21. $constraints = $array['_constraints'] ?? [];
  22. $indexes = $array['_indexes'] ?? [];
  23. unset($array['_constraints'], $array['_indexes'], $array['_options']);
  24. $table = [
  25. 'table' => $tableName,
  26. 'columns' => $array,
  27. 'constraints' => $constraints,
  28. 'indexes' => $indexes,
  29. ];
  30. $tables[$tableName] = $table;
  31. }
  32. return $tables;