Ejemplo n.º 1
0
 /**
  * Returns true if line is definition of one of the indexes.
  *
  * @param string $line The line from CREATE STATEMENT.
  *
  * @return bool
  */
 public static function isIndexDef($line)
 {
     if (Str::startsWith($line, 'PRIMARY KEY')) {
         return true;
     }
     if (Str::startsWith($line, 'UNIQUE KEY')) {
         return true;
     }
     if (Str::startsWith($line, 'KEY')) {
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider containsProvider
  *
  * @covers ::contains
  *
  * @param string $haystack
  * @param string $needle
  * @param bool $ignoreCase
  * @param bool $expected
  */
 public function test_containsProvider($haystack, $needle, $ignoreCase, $expected)
 {
     // When
     $got = Str::contains($haystack, $needle, $ignoreCase);
     // Then
     $this->assertSame($expected, $got);
 }
Ejemplo n.º 3
0
 private function getGitVersion($fileOrDir)
 {
     $newestVersion = '0.0.0';
     $currentDir = getcwd();
     $gitCommand = 'git tag';
     if (!Interaction::commandExist('git')) {
         return $newestVersion;
     }
     if (Str::endsWith($fileOrDir, 'php')) {
         $dir = dirname($fileOrDir);
     } else {
         $dir = $fileOrDir;
     }
     $dir = realpath($dir);
     chdir($dir);
     exec($gitCommand, $output);
     foreach ($output as $version) {
         if (version_compare($newestVersion, $version) === -1) {
             $newestVersion = $version;
         }
     }
     chdir($currentDir);
     return $newestVersion;
 }
Ejemplo n.º 4
0
 /**
  * Returns true if line is definition of one of the index constraints.
  *
  * @param string $line The line from CREATE STATEMENT.
  *
  * @return bool
  */
 public static function isConstraintDef($line)
 {
     if (Str::startsWith($line, 'CONSTRAINT')) {
         return true;
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * Fix and rewrite table CREATE statement if needed.
  *
  * @param bool $addIfNotExists Set to true to add if not exists condition.
  *
  * @return string The table create statement.
  */
 protected function fixTableCreateStatement($addIfNotExists = false)
 {
     $tableCS = $this->tableCS;
     if (!Str::endsWith(trim($this->tableCS), ';')) {
         $tableCS = trim($this->tableCS) . ";";
     }
     $tableCS = preg_replace('/(AUTO_INCREMENT=)([0-9]+)/', '${1}1', $tableCS);
     if (!$addIfNotExists) {
         return $tableCS;
     }
     /* @noinspection SqlNoDataSourceInspection */
     $tableCS = preg_replace('/CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $tableCS);
     return $tableCS;
 }