示例#1
0
文件: Index.php 项目: rzajac/schema
 /**
  * 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;
 }
示例#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);
 }
示例#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;
 }
示例#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;
 }
示例#5
0
文件: Table.php 项目: rzajac/schema
 /**
  * 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;
 }