forked from PHPMT/PseudoORM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
62 lines (46 loc) · 1.52 KB
/
index.php
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
<?php
ini_set("display_errors",1);
define("DB_USERNAME", "postgres");
define("DB_PASSWORD", "postgres");
define("DB_HOST", 'localhost');
define("DB_PORT", 5432);
define("DB_NAME", 'meu_db');
define("SCHEMA", '');
define('ENCODING', "SET NAMES 'utf8';");
define("DB_DSN", "pgsql:host=".DB_HOST.";port=".DB_PORT.";dbname=".DB_NAME.";");
define("SHOW_SQL_ERROR", PDO::ERRMODE_EXCEPTION);
// PATHS
define('MODELS', '../app/models/');
define('DAOS', MODELS . 'DAO/impl/');
define('EXCEPTIONS', MODELS . 'exception/');
use PseudoORM\Entity\Usuario;
use PseudoORM\Factory\AppFactory;
use PseudoORM\Services\PostgreSQLDataBaseCreator;
$composer_autoload = 'vendor/autoload.php';
if (false === file_exists($composer_autoload)) {
throw new RuntimeException('Por favor instalar as dependências do composer.');
}
include $composer_autoload;
require_once 'src/Annotations/Column.php';
require_once 'src/Annotations/Id.php';
require_once 'src/Annotations/Table.php';
require_once 'src/Annotations/Join.php';
require_once 'src/Annotations/Persistent.php';
/**
* Exemplo de uso
*/
$dao = AppFactory::getRepository(new Usuario());
// USe para gerar o script de criação do banco
echo $dao->generate(new PostgreSQLDataBaseCreator());
// Realizar operações básicas
$usuario = $dao->create();
$usuario->nome = 'Zé da Silva';
$usuario->idade = 25;
$usuario->cpf = '000555111';
$usuario->senha = '123456';
$dao->insert($usuario);
$usuarios = $dao->getList();
echo "<Br><Br>";
foreach ($usuarios as $usuario) {
echo $usuario->nome.'<br>';
}