-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #35: Removendo contantes de configuração. #37
base: master
Are you sure you want to change the base?
Changes from all commits
c6b06c2
ffc48f9
f319875
859d7a5
17c9a30
483a99c
949e131
5ab5ae5
0c83bb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
namespace PseudoORM\DAO; | ||
|
||
use PseudoORM\Services\IDataBaseCreator; | ||
use PseudoORM\Services\IDatabaseCreator; | ||
use PseudoORM\Entity\EntidadeBase; | ||
use PseudoORM\Exception; | ||
use \PDO; | ||
|
@@ -224,20 +224,21 @@ private function bindArrayValue(\PDOStatement $query, $array, $typeArray = false | |
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function generate(IDataBaseCreator $creator, $create = false) | ||
public function geraScriptDeCriacaoDoBancoDeDados(IDatabaseCreator $creator) | ||
{ | ||
$script = $creator->scriptCreation($this->type, true); | ||
|
||
if ($create == false) { | ||
return $script; | ||
} else { | ||
// TODO extract to method | ||
try { | ||
$dbh = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION )); | ||
$dbh->exec($script);// or die(print_r($dbh->errorInfo(), true)); | ||
} catch (PDOException $e) { | ||
echo ("DB ERROR: ". $e->getMessage()); | ||
} | ||
return $script; | ||
} | ||
|
||
public function criaBancoDeDados(IDatabaseCreator $creator) | ||
{ | ||
$script = $this->geraScriptDeCriacaoDoBancoDeDados($creator); | ||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the |
||
$dbh = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION )); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Que tal passar essa instancia do |
||
$dbh->exec($script); | ||
} catch (PDOException $e) { | ||
echo ("DB ERROR: ". $e->getMessage()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,8 +44,12 @@ public function insert(EntidadeBase $entidade); | |
public function update(EntidadeBase $entidade); | ||
|
||
/** | ||
* Gera script de criação do banco de dados e permite a criação automatica. | ||
* @param bolean $create True to create database automatically | False To print script in screen | ||
* Retorna script de criação do banco de dados. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
public function generate(IDataBaseCreator $creator, $create = false); | ||
public function geraScriptDeCriacaoDoBancoDeDados(IDataBaseCreator $creator); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. English or Portuguese? let's avoid mix languages in here. |
||
|
||
/** | ||
* Cria banco de dados | ||
*/ | ||
public function criaBancoDeDados(IDataBaseCreator $creator); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,16 @@ final public static function createFromForm($params) | |
} | ||
} | ||
} | ||
|
||
public function getClassShortName() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doc? |
||
{ | ||
return (new \ReflectionClass($this))->getShortName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about proxy this |
||
} | ||
|
||
public function getClass() | ||
{ | ||
return (new \ReflectionClass($this))->getName(); | ||
} | ||
|
||
|
||
public function setUID($uid) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,17 +33,11 @@ public static function getFactory() | |
|
||
public static function getRepository(EntidadeBase $objeto) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it static? |
||
{ | ||
try { | ||
$class = get_class($objeto); | ||
$respositoryPath = DAOS . $class . 'DAO.php'; | ||
if (!file_exists($respositoryPath)) { | ||
return new GenericDAO($class); | ||
} | ||
require_once $respositoryPath; | ||
$repository = $class . 'DAO'; | ||
return new $repository; | ||
} catch (Exception $e) { | ||
throw new Exception($e->getMessage()); | ||
} | ||
$repository = '\\PseudoORM\\DAO\\' . $objeto->getClassShortName() . 'DAO'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be in a config/map instead? |
||
if(class_exists($repository)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PSR-2 |
||
return new $repository($objeto->getClass()); | ||
|
||
return new GenericDAO($objeto->getClass()); | ||
} | ||
} | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EOL EOF |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
namespace PseudoORM\Services; | ||
|
||
interface IDataBaseCreator | ||
interface IDatabaseCreator | ||
{ | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
|
||
namespace PseudoORM\Services; | ||
|
||
use PseudoORM\Services\IDataBaseCreator; | ||
use PseudoORM\Services\IDatabaseCreator; | ||
|
||
use Addendum\ReflectionAnnotatedClass; | ||
|
||
class PostgreSQLDataBaseCreator implements IDataBaseCreator | ||
class PostgreSQLDatabaseCreator implements IDatabaseCreator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, shouldn't it be |
||
{ | ||
|
||
protected $tableName; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,16 +11,16 @@ define("DB_PORT", 5432); | |
define("DB_NAME", 'pseudoorm'); | ||
define("SCHEMA", ''); | ||
define('ENCODING', "SET NAMES 'utf8';"); | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This demarks a |
||
* @todo Remover constantes | ||
*/ | ||
define("DB_DSN", "pgsql:host=".DB_HOST.";port=".DB_PORT.";dbname=".DB_NAME.";"); | ||
define("SHOW_SQL_ERROR", PDO::ERRMODE_EXCEPTION); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe mark this constants to be removed in the future as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. marquei como |
||
|
||
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; | ||
use PseudoORM\Services\PostgreSQLDatabaseCreator; | ||
|
||
require_once 'src/Annotations/Column.php'; | ||
require_once 'src/Annotations/Id.php'; | ||
|
@@ -36,7 +36,7 @@ require_once 'src/Annotations/Persistent.php'; | |
$dao = AppFactory::getRepository(new Usuario()); | ||
|
||
// USe para gerar o script de criação do banco | ||
$dao->generate(new PostgreSQLDataBaseCreator(), true); | ||
$dao->criaBancoDeDados(new PostgreSQLDatabaseCreator()); | ||
|
||
// Realizar operações básicas | ||
$usuario = $dao->create(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this method be removed? it doesn't do too much now...