|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Schema\Concerns; |
|
6
|
|
|
|
|
7
|
|
|
use LaravelFreelancerNL\Aranguent\Schema\Blueprint; |
|
8
|
|
|
|
|
9
|
|
|
trait UsesBlueprints |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Create a new command set with a Closure. |
|
13
|
|
|
* |
|
14
|
|
|
* @param string $collection |
|
15
|
|
|
* @param \Closure|null $callback |
|
16
|
|
|
* |
|
17
|
|
|
* @return Blueprint |
|
18
|
|
|
*/ |
|
19
|
122 |
|
protected function createBlueprint($collection, \Closure $callback = null) |
|
20
|
|
|
{ |
|
21
|
|
|
//Prefixes are unnamed in ArangoDB |
|
22
|
122 |
|
$prefix = null; |
|
23
|
|
|
|
|
24
|
122 |
|
if (isset($this->resolver)) { |
|
25
|
1 |
|
return call_user_func($this->resolver, $collection, $this->schemaManager, $callback, $prefix); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
122 |
|
return new Blueprint($collection, $this->schemaManager, $callback, $prefix); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Set the Schema Blueprint resolver callback. |
|
33
|
|
|
* |
|
34
|
|
|
* @param Closure $resolver |
|
|
|
|
|
|
35
|
|
|
* |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function blueprintResolver(\Closure $resolver) |
|
39
|
|
|
{ |
|
40
|
1 |
|
$this->resolver = $resolver; |
|
|
|
|
|
|
41
|
1 |
|
} |
|
42
|
|
|
|
|
43
|
122 |
|
protected function build($blueprint) |
|
44
|
|
|
{ |
|
45
|
122 |
|
$blueprint->build($this->connection, $this->grammar); |
|
46
|
122 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Create a new collection on the schema. |
|
50
|
|
|
* |
|
51
|
|
|
* @param array<mixed> $config |
|
52
|
|
|
*/ |
|
53
|
122 |
|
public function create($table, \Closure $callback, array $config = []): void |
|
54
|
|
|
{ |
|
55
|
122 |
|
$this->build(tap($this->createBlueprint($table), function ($blueprint) use ($callback, $config) { |
|
56
|
122 |
|
$blueprint->create($config); |
|
57
|
|
|
|
|
58
|
122 |
|
$callback($blueprint); |
|
59
|
122 |
|
})); |
|
60
|
122 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Modify a table's schema. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $table |
|
66
|
|
|
* @param \Closure $callback |
|
67
|
|
|
* |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
9 |
|
public function table($table, \Closure $callback) |
|
71
|
|
|
{ |
|
72
|
9 |
|
$this->build($this->createBlueprint($table, $callback)); |
|
73
|
9 |
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|