LazyRecord\SeedBuilder::buildScriptSeed PHP Метод

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

public buildScriptSeed ( $script )
    public function buildScriptSeed($script)
    {
        if (file_exists($seed)) {
            return require $seed;
        } else {
            $seed = str_replace('::', '\\', $seed);
            if (class_exists($seed, true)) {
                return $seed::seed();
            }
        }
        throw new InvalidArgumentException('Invalid seed script name');
    }

Usage Example

Пример #1
0
 public function setUp()
 {
     $annnotations = $this->getAnnotations();
     $configLoader = ConfigLoader::getInstance();
     $configLoader->loadFromSymbol(true);
     $configLoader->setDefaultDataSourceId($this->getDriverType());
     $connManager = ConnectionManager::getInstance();
     $connManager->init($configLoader);
     try {
         $dbh = $connManager->getConnection($this->getDriverType());
     } catch (PDOException $e) {
         if ($this->allowConnectionFailure) {
             $this->markTestSkipped(sprintf("Can not connect to database by data source '%s' message:'%s' config:'%s'", $this->getDriverType(), $e->getMessage(), var_export($configLoader->getDataSource($this->getDriverType()), true)));
             return;
         } else {
             echo sprintf("Can not connect to database by data source '%s' message:'%s' config:'%s'", $this->getDriverType(), $e->getMessage(), var_export($configLoader->getDataSource($this->getDriverType()), true));
             throw $e;
         }
     }
     $driver = $connManager->getQueryDriver($this->getDriverType());
     $this->assertInstanceOf('SQLBuilder\\Driver\\BaseDriver', $driver, 'QueryDriver object OK');
     // Rebuild means rebuild the database for new tests
     $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;
     }
     if ($rebuild) {
         $builder = SqlBuilder::create($driver, array('rebuild' => true));
         $this->assertNotNull($builder);
         // $schemas = ClassUtils::schema_classes_to_objects($this->getModels());
         $schemas = ClassUtils::schema_classes_to_objects($this->getModels());
         foreach ($schemas as $schema) {
             $sqls = $builder->build($schema);
             $this->assertNotEmpty($sqls);
             foreach ($sqls as $sql) {
                 $dbh->query($sql);
             }
         }
         if ($basedata) {
             $runner = new SeedBuilder($this->config, $this->logger);
             foreach ($schemas as $schema) {
                 $runner->buildSchemaSeeds($schema);
             }
             if ($scripts = $this->config->getSeedScripts()) {
                 foreach ($scripts as $script) {
                     $runner->buildScriptSeed($script);
                 }
             }
         }
     }
 }
All Usage Examples Of LazyRecord\SeedBuilder::buildScriptSeed