|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rentgen; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
6
|
|
|
|
|
7
|
|
|
use Rentgen\DependencyInjection\RentgenExtension; |
|
8
|
|
|
use Rentgen\Schema\Info; |
|
9
|
|
|
use Rentgen\Schema\Manipulation; |
|
10
|
|
|
|
|
11
|
|
|
class Rentgen |
|
12
|
|
|
{ |
|
13
|
|
|
private $container; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Constructor. |
|
17
|
|
|
*/ |
|
18
|
|
|
public function __construct() |
|
19
|
|
|
{ |
|
20
|
|
|
$container = new ContainerBuilder(); |
|
21
|
|
|
|
|
22
|
|
|
$extension = new RentgenExtension(); |
|
23
|
|
|
$container->registerExtension($extension); |
|
24
|
|
|
$container->loadFromExtension($extension->getAlias()); |
|
25
|
|
|
$container->compile(); |
|
26
|
|
|
|
|
27
|
|
|
$this->container = $container; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get a service. |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $service A service name. |
|
34
|
|
|
* |
|
35
|
|
|
* @return mixed |
|
36
|
|
|
*/ |
|
37
|
|
|
public function get($service) |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->container->get($service); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Create the manipulation instance. |
|
44
|
|
|
* |
|
45
|
|
|
* @return Rentgen\Schema\Manipulation |
|
46
|
|
|
*/ |
|
47
|
|
|
public function createManipulationInstance() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->container->get('rentgen.schema.manipulation'); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Create the info instance. |
|
54
|
|
|
* |
|
55
|
|
|
* @return Rentgen\Schema\Info |
|
56
|
|
|
*/ |
|
57
|
|
|
public function createInfoInstance() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->container->get('rentgen.schema.info'); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Execute sql query. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $sql A sql query. |
|
66
|
|
|
* |
|
67
|
|
|
* @return integer |
|
68
|
|
|
*/ |
|
69
|
|
|
public function execute($sql) |
|
70
|
|
|
{ |
|
71
|
|
|
$connection = $this->get('connection'); |
|
72
|
|
|
|
|
73
|
|
|
return $connection->execute($sql); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Execute sql query with select intention. |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $sql A sql query. |
|
80
|
|
|
* |
|
81
|
|
|
* @return array |
|
82
|
|
|
*/ |
|
83
|
|
|
public function query($sql) |
|
84
|
|
|
{ |
|
85
|
|
|
$connection = $this->get('connection'); |
|
86
|
|
|
|
|
87
|
|
|
return $connection->query($sql); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|