Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
26 changes: 13 additions & 13 deletions src/Factory/AppFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace PseudoORM\Factory;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sth?


use PseudoORM\Entity\EntidadeBase;
use PseudoORM\DAO\GenericDAO;
use \Exception;

class AppFactory
Expand Down Expand Up @@ -33,17 +32,18 @@ public static function getFactory()

public static function getRepository(EntidadeBase $objeto)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type?

Choose a reason for hiding this comment

The 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());
}
$class = get_class($objeto);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya don't need to get the name of class, just use ReflectionObject instead.

$classShortName = (new \ReflectionClass($objeto))->getShortName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no caso dessas ReflectionClass a função vai pegar o nome da classe ao invés de precisar fazer um require_once ?


$classDAO = '\\PseudoORM\\DAO\\' . $classShortName . 'DAO';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should a DI be used instead?


$entityName = class_exists($classDAO)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if my repository is an anonymous class?

? $classShortName
: 'Generic'
;

$repository = '\\PseudoORM\\DAO\\' . $entityName . 'DAO';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repositories should be configured in some kind of mapping file — xml? —


return new $repository($class);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if $repository isn't a valid class?

}
}
4 changes: 0 additions & 4 deletions test/functional/check-environment.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ 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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mark this constants to be removed in the future as well? @todo ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marquei como @todo


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;
Expand Down