Repository navigation
Expand file tree
/
Copy pathSchema.php
More file actions
77 lines (71 loc) · 2.97 KB
/
Copy pathSchema.php
File metadata and controls
77 lines (71 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Database\Schema;
use Hyperf\Context\ApplicationContext;
use Hyperf\Database\ConnectionInterface;
use Hyperf\Database\ConnectionResolverInterface;
/**
* @method static bool hasTable(string $table)
* @method static bool createDatabase(string $name)
* @method static bool hasView(string $name)
* @method static array getViews()
* @method static bool dropDatabaseIfExists(string $name)
* @method static array getColumnListing(string $table)
* @method static array getColumnTypeListing(string $table)
* @method static void dropAllTables()
* @method static void dropAllViews()
* @method static array getAllTables()
* @method static array getTables()
* @method static array getAllViews()
* @method static array getIndexes(string $table)
* @method static array getIndexListing(string $table)
* @method static bool hasIndex(string $table, array|string $index, ?string $type = null)
* @method static bool hasColumn(string $table, string $column)
* @method static bool hasColumns(string $table, array $columns)
* @method static void whenTableHasColumn(string $table, string $column, \Closure $callback)
* @method static void whenTableDoesntHaveColumn(string $table, string $column, \Closure $callback)
* @method static string getColumnType(string $table, string $column)
* @method static void table(string $table, \Closure $callback)
* @method static void create(string $table, \Closure $callback))
* @method static void drop(string $table)
* @method static void dropIfExists(string $table)
* @method static void rename(string $from, string $to)
* @method static bool enableForeignKeyConstraints()
* @method static bool disableForeignKeyConstraints()
* @method static mixed withoutForeignKeyConstraints(\Closure $callback)
* @method static \Hyperf\Database\Connection getConnection()
* @method static Builder setConnection(\Hyperf\Database\Connection $connection)
* @method static void blueprintResolver(\Closure $resolver)
* @method static array getForeignKeys(string $table)
*/
class Schema
{
public static function __callStatic($name, $arguments)
{
$container = ApplicationContext::getContainer();
$resolver = $container->get(ConnectionResolverInterface::class);
$connection = $resolver->connection();
return $connection->getSchemaBuilder()->{$name}(...$arguments);
}
public function __call($name, $arguments)
{
return self::__callStatic($name, $arguments);
}
/**
* Create a connection by ConnectionResolver.
*/
public function connection(string $name = 'default'): ConnectionInterface
{
$container = ApplicationContext::getContainer();
$resolver = $container->get(ConnectionResolverInterface::class);
return $resolver->connection($name);
}
}