generate() публичный Метод

Given a schema class list, generate schema files.
public generate ( array $schemas ) : array
$schemas array
Результат array class map array of schema class and file path.
Пример #1
0
 public function execute()
 {
     $logger = $this->getLogger();
     $config = $this->getConfigLoader();
     $this->logger->debug('Finding schemas...');
     $classes = $this->findSchemasByArguments(func_get_args());
     SchemaUtils::printSchemaClasses($classes, $this->logger);
     $this->logger->debug("Initializing schema generator...");
     $generator = new SchemaGenerator($config, $this->logger);
     if ($this->options->force) {
         $generator->setForceUpdate(true);
     }
     $classMap = $generator->generate($classes, $this->options->force);
     /*
     foreach( $classMap as $class => $file ) {
         $path = $file;
         if ( strpos( $path , getcwd() ) === 0 ) {
             $path = substr( $path , strlen(getcwd()) + 1 );
         }
         $logger->info($path);
         // $logger->info(sprintf("%-32s",ltrim($class,'\\')) . " => $path",1);
     }
     */
     $logger->info('Done');
 }
Пример #2
0
 public function testSchemaGenerator()
 {
     $g = new SchemaGenerator($this->config, $this->logger);
     $g->setForceUpdate(true);
     $schemas = $this->getModels();
     foreach ($schemas as $schema) {
         if ($result = $g->generateCollectionClass($schema)) {
             list($class, $file) = $result;
             ok($class);
             ok($file);
             path_ok($file);
             $this->syntaxTest($file);
         }
         if ($classMap = $g->generate(array($schema))) {
             foreach ($classMap as $class => $file) {
                 ok($class);
                 ok($file);
                 path_ok($file, $file);
                 // $this->syntaxTest($file);
                 require_once $file;
             }
         }
         $pk = $schema->findPrimaryKey();
         $this->assertNotNull($pk, "Find primary key from " . get_class($schema));
         $model = $schema->newModel();
         $this->assertNotNull($model);
         $collection = $schema->newCollection();
         $this->assertNotNull($collection);
     }
 }
Пример #3
0
 public function setUp()
 {
     if ($this->onlyDriver !== null && $this->getDataSource() != $this->onlyDriver) {
         return $this->markTestSkipped("{$this->onlyDriver} only");
     }
     $this->prepareConnection();
     // Ensure that we use the correct default data source ID
     $this->assertEquals($this->getDataSource(), $this->config->getDefaultDataSourceId());
     $this->assertInstanceOf('SQLBuilder\\Driver\\BaseDriver', $this->queryDriver, 'QueryDriver object OK');
     // Rebuild means rebuild the database for new tests
     $annnotations = $this->getAnnotations();
     $rebuild = true;
     $basedata = true;
     if (isset($annnotations['method']['rebuild'][0]) && $annnotations['method']['rebuild'][0] == 'false') {
         $rebuild = false;
     }
     if (isset($annnotations['method']['basedata'][0]) && $annnotations['method']['basedata'][0] == 'false') {
         $basedata = false;
     }
     $schemas = ClassUtils::schema_classes_to_objects($this->getModels());
     if (false === $this->schemaHasBeenBuilt) {
         $g = new SchemaGenerator($this->config);
         $g->setForceUpdate(true);
         $g->generate($schemas);
         $this->schemaHasBeenBuilt = true;
     }
     if ($rebuild === false) {
         $tableParser = TableParser::create($this->conn, $this->queryDriver, $this->config);
         $tables = $tableParser->getTables();
         $schemas = array_filter($schemas, function ($schema) use($tables) {
             return !in_array($schema->getTable(), $tables);
         });
     }
     $this->sqlBuilder = SqlBuilder::create($this->queryDriver, array('rebuild' => $rebuild));
     $this->bootstrap = new Bootstrap($this->conn, $this->sqlBuilder, $this->logger);
     $this->bootstrap->build($schemas);
     if ($rebuild && $basedata) {
         $seeder = new SeedBuilder($this->logger);
         $seeder->build(new SchemaCollection($schemas));
         $seeder->buildConfigSeeds($this->config);
     }
 }
Пример #4
0
<?php

$loader = (require "vendor/autoload.php");
require "tests/model_helpers.php";
mb_internal_encoding('UTF-8');
error_reporting(E_ALL);
$loader->add(null, 'tests');
$loader->add(null, 'tests/src');
use LazyRecord\Schema\SchemaGenerator;
use LazyRecord\ConfigLoader;
use CLIFramework\Logger;
$config = ConfigLoader::getInstance();
$config->loadFromSymbol(true);
$config->initForBuild();
$logger = new Logger();
$logger->quiet();
$logger->info("Building schema class files...");
// build schema class files
$schemas = array(new \AuthorBooks\Model\AddressSchema(), new \AuthorBooks\Model\AuthorBookSchema(), new \AuthorBooks\Model\AuthorSchema(), new \AuthorBooks\Model\BookSchema(), new \AuthorBooks\Model\PublisherSchema(), new \AuthorBooks\Model\TagSchema(), new \MetricApp\Model\MetricValueSchema(), new \PageApp\Model\PageSchema(), new \StoreApp\Model\StoreSchema(), new \TestApp\Model\EdmSchema(), new \TestApp\Model\IDNumberSchema(), new \TestApp\Model\NameSchema(), new \TestApp\Model\PostSchema(), new \TestApp\Model\TableSchema(), new \TestApp\Model\UserSchema(), new \TestApp\Model\WineCategorySchema(), new \TestApp\Model\WineSchema());
$g = new \LazyRecord\Schema\SchemaGenerator($config, $logger);
$g->setForceUpdate(true);
$g->generate($schemas, true);
// $logger->info("Starting tests...");
Пример #5
0
 /**
  * @return array[] class map
  */
 public function updateSchemaFiles(DeclareSchema $schema)
 {
     $generator = new SchemaGenerator($this->config, $this->logger);
     return $generator->generate([$schema]);
 }
Пример #6
0
<?php

$loader = (require "vendor/autoload.php");
require "tests/model_helpers.php";
mb_internal_encoding('UTF-8');
error_reporting(E_ALL);
if (extension_loaded('xhprof')) {
    ini_set('xhprof.output_dir', '/tmp');
}
$loader->add(null, 'tests');
$loader->add(null, 'tests/src');
use LazyRecord\Schema\SchemaGenerator;
use LazyRecord\ConfigLoader;
use CLIFramework\Logger;
$config = ConfigLoader::getInstance();
$config->loadFromArray(array('bootstrap' => array('tests/bootstrap.php'), 'schema' => array('auto_id' => 1, 'paths' => array('tests/TestApp')), 'data_sources' => array('default' => array('dsn' => 'sqlite::memory:', 'user' => NULL, 'pass' => NULL), 'pgsql' => array('dsn' => 'pgsql:host=localhost;dbname=testing', 'user' => 'postgres'))));
$logger = new Logger();
$logger->info("Building schema class files...");
// build schema class files
$schemas = array(new \TestApp\Model\UserSchema(), new \TestApp\Model\IDNumberSchema(), new \TestApp\Model\NameSchema(), new \AuthorBooks\Model\AddressSchema(), new \AuthorBooks\Model\BookSchema(), new \AuthorBooks\Model\AuthorSchema(), new \AuthorBooks\Model\AuthorBookSchema(), new \AuthorBooks\Model\PublisherSchema(), new \MetricApp\Model\MetricValueSchema(), new \PageApp\Model\PageSchema());
$g = new \LazyRecord\Schema\SchemaGenerator($config, $logger);
$g->setForceUpdate(true);
$g->generate($schemas);
// $logger->info("Starting tests...");