set_include_path(get_include_path() . PATH_SEPARATOR . CLASS_DIR); spl_autoload_register(function ($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strrpos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; }); $pdo = new \PDO("mysql:host=localhost;", "root", "123"); $criar_database_tabela = $pdo->exec("CREATE DATABASE IF NOT EXISTS `dbteste`;\n GRANT ALL ON `dbteste`.* TO 'root'@'localhost';\n FLUSH PRIVILEGES;\n CREATE TABLE IF NOT EXISTS `dbteste`.`Cliente` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `nome` varchar(45) NOT NULL,\n `endereco` varchar(100) NOT NULL,\n `telefone` varchar(30) NOT NULL,\n `tipo` int(11) NOT NULL,\n `grau_importancia` int(11) NOT NULL,\n `endereco_cobranca` varchar(200) NOT NULL,\n PRIMARY KEY (`id`)\n )"); $clientes = new SON\Cliente\BancoClientes(); // eu não entendi muito bem se tem que criar um metodo ou é aqui mesmo que coloca // as fixtures para povoar o banco de dados. $fisico = new SON\Cliente\Cliente(); $fisico->setNome('Paulo '); $fisico->setTipo(1); $fisico->setEndereco('Rua Cliente'); $fisico->setTelefone('6599545555'); $fisico->setEnderecoCobranca('endereco cobranca'); $fisico->setGrauImportancia(5); $clientes->persist($fisico); $juridico = new SON\Cliente\Cliente(); $juridico->setNome('Empresa'); $juridico->setTipo(2); $juridico->setEndereco('Rua Empresa'); $juridico->setTelefone('64444444445');
* a funcão spl_autoload_register() não queria funciona sem parametro, então eu coloquei o código do * php-fig e deu certo. **/ spl_autoload_register(function ($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strrpos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; }); $clientes = new SON\Cliente\BancoClientes(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <title>Curso POO SON - fase 1</title> <!-- Bootstrap --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->