1 | <?php |
2 | |
3 | require_once __DIR__ . "/../modelo/Venta.php"; |
4 | require_once __DIR__ . "/../modelo/Producto.php"; |
5 | require_once __DIR__ . "/bdCrea.php"; |
6 | require_once __DIR__ . "/productoCuenta.php"; |
7 | require_once __DIR__ . "/productoAgrega.php"; |
8 | require_once __DIR__ . "/ventaCuenta.php"; |
9 | require_once __DIR__ . "/ventaAgrega.php"; |
10 | |
11 | class Bd |
12 | { |
13 | |
14 | private static ?PDO $conexion = null; |
15 | |
16 | public static function getConexion(): PDO |
17 | { |
18 | if (self::$conexion === null) { |
19 | self::$conexion = new PDO( |
20 | |
21 | "sqlite:srvcompras.db", |
22 | |
23 | null, |
24 | |
25 | null, |
26 | |
27 | [PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION] |
28 | ); |
29 | |
30 | bdCrea(self::$conexion); |
31 | if (productoCuenta() === 0) { |
32 | productoAgrega( |
33 | new Producto(nombre: "Sandwich", existencias: 50, precio: 15) |
34 | ); |
35 | productoAgrega( |
36 | new Producto(nombre: "Hot dog", existencias: 40, precio: 30) |
37 | ); |
38 | productoAgrega( |
39 | new Producto(nombre: "Hamburguesa", existencias: 30, precio: 40) |
40 | ); |
41 | } |
42 | |
43 | if (ventaCuenta() === 0) { |
44 | ventaAgrega(new Venta(enCaptura: true)); |
45 | } |
46 | } |
47 | |
48 | return self::$conexion; |
49 | } |
50 | } |
51 | |