mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Refactor Appbox
This commit is contained in:
@@ -26,9 +26,9 @@ use Alchemy\Phrasea\Core;
|
||||
class module_console_fileConfigCheck extends Command
|
||||
{
|
||||
|
||||
const PROD = 'prod';
|
||||
const DEV = 'dev';
|
||||
const TEST = 'test';
|
||||
const PROD = 'prod';
|
||||
const DEV = 'dev';
|
||||
const TEST = 'test';
|
||||
const ALERT = 1;
|
||||
const ERROR = 0;
|
||||
|
||||
@@ -39,10 +39,10 @@ class module_console_fileConfigCheck extends Command
|
||||
protected $configuration;
|
||||
protected $env;
|
||||
protected $testSuite = array(
|
||||
'checkPhraseanetScope'
|
||||
, 'checkDatabaseScope'
|
||||
, 'checkTeamplateEngineService'
|
||||
, 'checkOrmService'
|
||||
'checkPhraseanetScope'
|
||||
, 'checkDatabaseScope'
|
||||
, 'checkTeamplateEngineService'
|
||||
, 'checkOrmService'
|
||||
);
|
||||
protected $connexionOk = false;
|
||||
|
||||
@@ -78,8 +78,8 @@ class module_console_fileConfigCheck extends Command
|
||||
|
||||
private function initTests(OutputInterface $output)
|
||||
{
|
||||
$spec = new Core\Configuration\Application();
|
||||
$parser = new Core\Configuration\Parser\Yaml();
|
||||
$spec = new Core\Configuration\Application();
|
||||
$parser = new Core\Configuration\Parser\Yaml();
|
||||
$handler = new Core\Configuration\Handler($spec, $parser);
|
||||
|
||||
$this->configuration = new Core\Configuration($handler, $this->env);
|
||||
@@ -105,11 +105,11 @@ class module_console_fileConfigCheck extends Command
|
||||
$previous = $e->getPrevious();
|
||||
|
||||
$output->writeln(sprintf(
|
||||
"<error>%s FATAL error : %s</error>"
|
||||
, $e->getMessage()
|
||||
, $previous instanceof \Exception ?
|
||||
$previous->getMessage() : 'Unknown.'
|
||||
)
|
||||
"<error>%s FATAL error : %s</error>"
|
||||
, $e->getMessage()
|
||||
, $previous instanceof \Exception ?
|
||||
$previous->getMessage() : 'Unknown.'
|
||||
)
|
||||
);
|
||||
$output->writeln(sprintf("\nConfig check test suite can not continue please correct FATAL error and relaunch.\n"));
|
||||
|
||||
@@ -132,11 +132,11 @@ class module_console_fileConfigCheck extends Command
|
||||
$previous = $e->getPrevious();
|
||||
|
||||
$output->writeln(sprintf(
|
||||
"<error>%s FAILED : %s</error>"
|
||||
, $e->getMessage()
|
||||
, $previous instanceof \Exception ?
|
||||
$previous->getMessage() : 'Unknow'
|
||||
)
|
||||
"<error>%s FAILED : %s</error>"
|
||||
, $e->getMessage()
|
||||
, $previous instanceof \Exception ?
|
||||
$previous->getMessage() : 'Unknow'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -146,25 +146,25 @@ class module_console_fileConfigCheck extends Command
|
||||
|
||||
private function checkParse(OutputInterface $output)
|
||||
{
|
||||
$parser = $this
|
||||
->configuration
|
||||
->getConfigurationHandler()
|
||||
->getParser();
|
||||
$fileConfig = $this
|
||||
->configuration
|
||||
->getConfigurationHandler()
|
||||
->getSpecification()
|
||||
->getConfigurationFile();
|
||||
$fileService = $this
|
||||
->configuration
|
||||
->getConfigurationHandler()
|
||||
->getSpecification()
|
||||
->getServiceFile();
|
||||
$parser = $this
|
||||
->configuration
|
||||
->getConfigurationHandler()
|
||||
->getParser();
|
||||
$fileConfig = $this
|
||||
->configuration
|
||||
->getConfigurationHandler()
|
||||
->getSpecification()
|
||||
->getConfigurationFile();
|
||||
$fileService = $this
|
||||
->configuration
|
||||
->getConfigurationHandler()
|
||||
->getSpecification()
|
||||
->getServiceFile();
|
||||
$fileConnexion = $this
|
||||
->configuration
|
||||
->getConfigurationHandler()
|
||||
->getSpecification()
|
||||
->getConnexionFile();
|
||||
->configuration
|
||||
->getConfigurationHandler()
|
||||
->getSpecification()
|
||||
->getConnexionFile();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -175,7 +175,7 @@ class module_console_fileConfigCheck extends Command
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$message = str_replace("\\", "", $e->getMessage());
|
||||
$e = new \Exception($message);
|
||||
$e = new \Exception($message);
|
||||
throw new \Exception(sprintf("Check parsing file\n"), null, $e);
|
||||
}
|
||||
$output->writeln("<info>Parsing File OK</info>");
|
||||
@@ -200,8 +200,8 @@ class module_console_fileConfigCheck extends Command
|
||||
|
||||
private function checkGetSelectedEnvironementFromFile(OutputInterface $output)
|
||||
{
|
||||
$spec = new Core\Configuration\Application();
|
||||
$parser = new Core\Configuration\Parser\Yaml();
|
||||
$spec = new Core\Configuration\Application();
|
||||
$parser = new Core\Configuration\Parser\Yaml();
|
||||
$handler = new Core\Configuration\Handler($spec, $parser);
|
||||
|
||||
$configuration = new Core\Configuration($handler);
|
||||
@@ -232,18 +232,18 @@ class module_console_fileConfigCheck extends Command
|
||||
if ($phraseanet->get("debug") !== true)
|
||||
{
|
||||
$output->writeln(sprintf(
|
||||
"<comment>%s:phraseanet:debug must be initialized to true<:comment>"
|
||||
, $this->env
|
||||
)
|
||||
"<comment>%s:phraseanet:debug must be initialized to true<:comment>"
|
||||
, $this->env
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($phraseanet->get("display_errors") !== true)
|
||||
{
|
||||
throw new \Exception(sprintf(
|
||||
"%s:phraseanet:debug must be initialized to true"
|
||||
, $this->env
|
||||
)
|
||||
"%s:phraseanet:debug must be initialized to true"
|
||||
, $this->env
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -253,18 +253,18 @@ class module_console_fileConfigCheck extends Command
|
||||
if ($phraseanet->get("debug") !== false)
|
||||
{
|
||||
throw new \Exception(sprintf(
|
||||
"%s:phraseanet:debug must be initialized to false"
|
||||
, $this->env
|
||||
)
|
||||
"%s:phraseanet:debug must be initialized to false"
|
||||
, $this->env
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($phraseanet->get("display_errors") !== false)
|
||||
{
|
||||
throw new \Exception(sprintf(
|
||||
"%s:phraseanet:debug must be initialized to false"
|
||||
, $this->env
|
||||
)
|
||||
"%s:phraseanet:debug must be initialized to false"
|
||||
, $this->env
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -284,14 +284,14 @@ class module_console_fileConfigCheck extends Command
|
||||
try
|
||||
{
|
||||
$connexionName = $this->configuration->getPhraseanet()->get('database');
|
||||
$connexion = $this->configuration->getConnexion($connexionName);
|
||||
$connexion = $this->configuration->getConnexion($connexionName);
|
||||
|
||||
try
|
||||
{
|
||||
$config = new \Doctrine\DBAL\Configuration();
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection(
|
||||
$connexion->all()
|
||||
, $config
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection(
|
||||
$connexion->all()
|
||||
, $config
|
||||
);
|
||||
unset($conn);
|
||||
$this->connexionOk = true;
|
||||
@@ -299,10 +299,10 @@ class module_console_fileConfigCheck extends Command
|
||||
catch (\Exception $e)
|
||||
{
|
||||
throw new \Exception(sprintf(
|
||||
"Unable to connect to database declared in connexion '%s' for the following reason %s"
|
||||
, $connexionName
|
||||
, $e->getMessage()
|
||||
)
|
||||
"Unable to connect to database declared in connexion '%s' for the following reason %s"
|
||||
, $connexionName
|
||||
, $e->getMessage()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -328,24 +328,23 @@ class module_console_fileConfigCheck extends Command
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$message = sprintf(
|
||||
"%s called from %s in %s:%s:template_engine scope"
|
||||
, $e->getMessage()
|
||||
, $this->configuration->getFile()->getFilename()
|
||||
, $this->env
|
||||
, $templateEngineName
|
||||
"%s called from %s in %s:%s:template_engine scope"
|
||||
, $e->getMessage()
|
||||
, $this->configuration->getFile()->getFilename()
|
||||
, $this->env
|
||||
, $templateEngineName
|
||||
);
|
||||
$e = new \Exception($message);
|
||||
$e = new \Exception($message);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
||||
$serviceBuilder = new Core\ServiceBuilder\TemplateEngine(
|
||||
$templateEngineName
|
||||
, $configuration
|
||||
$service = Core\Service\Builder::create(
|
||||
\bootstrap::getCore()
|
||||
, $templateEngineName
|
||||
, $configuration
|
||||
);
|
||||
|
||||
$service = $serviceBuilder->buildService();
|
||||
|
||||
if ($service->getType() === 'twig')
|
||||
{
|
||||
$twig = $service->getService();
|
||||
@@ -376,20 +375,20 @@ class module_console_fileConfigCheck extends Command
|
||||
if ($e->getKey() === 'template_engine')
|
||||
{
|
||||
$e = new \Exception(sprintf(
|
||||
"Missing parameter %s for %s environment scope"
|
||||
, $e->getKey()
|
||||
, $this->env
|
||||
)
|
||||
"Missing parameter %s for %s environment scope"
|
||||
, $e->getKey()
|
||||
, $this->env
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$e = new \Exception(sprintf(
|
||||
"Missing parameter %s for %s service declared in %s scope."
|
||||
, $e->getKey()
|
||||
, $templateEngineName
|
||||
, $this->env
|
||||
)
|
||||
"Missing parameter %s for %s service declared in %s scope."
|
||||
, $e->getKey()
|
||||
, $templateEngineName
|
||||
, $this->env
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -422,26 +421,22 @@ class module_console_fileConfigCheck extends Command
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$message = sprintf(
|
||||
"%s called from %s in %s:orm scope"
|
||||
, $e->getMessage()
|
||||
, $this->configuration->getFile()->getFilename()
|
||||
, $this->env
|
||||
, $ormName
|
||||
"%s called from %s in %s:orm scope"
|
||||
, $e->getMessage()
|
||||
, $this->configuration->getFile()->getFilename()
|
||||
, $this->env
|
||||
, $ormName
|
||||
);
|
||||
$e = new \Exception($message);
|
||||
$e = new \Exception($message);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$registry = \registry::get_instance();
|
||||
|
||||
$serviceBuilder = new Core\ServiceBuilder\Orm(
|
||||
$ormName
|
||||
, $configuration
|
||||
, array('registry' => $registry)
|
||||
$service = Core\Service\Builder::create(
|
||||
\bootstrap::getCore()
|
||||
, $ormName
|
||||
, $configuration
|
||||
);
|
||||
|
||||
$service = $serviceBuilder->buildService();
|
||||
|
||||
if ($service->getType() === 'doctrine')
|
||||
{
|
||||
$caches = $service->getCacheServices();
|
||||
@@ -449,17 +444,17 @@ class module_console_fileConfigCheck extends Command
|
||||
if ($service->isDebug() && self::PROD === $this->env)
|
||||
{
|
||||
$output->writeln(sprintf(
|
||||
"<comment>%s service should not be in debug mode </comment>"
|
||||
, $service->getName()
|
||||
)
|
||||
"<comment>%s service should not be in debug mode </comment>"
|
||||
, $service->getName()
|
||||
)
|
||||
);
|
||||
}
|
||||
elseif ((self::TEST === $this->env || self::DEV === $this->env) && !$service->isDebug())
|
||||
{
|
||||
$output->writeln(sprintf(
|
||||
"<comment>%s service should be in debug mode</comment>"
|
||||
, $service->getName()
|
||||
)
|
||||
"<comment>%s service should be in debug mode</comment>"
|
||||
, $service->getName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -468,23 +463,23 @@ class module_console_fileConfigCheck extends Command
|
||||
if ($cache->getType() === 'array' && self::PROD === $this->env)
|
||||
{
|
||||
$output->writeln(sprintf(
|
||||
"<comment>%s:doctrine:orm:%s %s service should not be an array cache type for %s environment</comment>"
|
||||
, $service->getName()
|
||||
, $key
|
||||
, $cache->getName()
|
||||
, $this->env
|
||||
)
|
||||
"<comment>%s:doctrine:orm:%s %s service should not be an array cache type for %s environment</comment>"
|
||||
, $service->getName()
|
||||
, $key
|
||||
, $cache->getName()
|
||||
, $this->env
|
||||
)
|
||||
);
|
||||
}
|
||||
elseif ($cache->getType() !== 'array' && (self::TEST === $this->env || self::DEV === $this->env))
|
||||
{
|
||||
$output->writeln(sprintf(
|
||||
"<comment>%s:doctrine:orm:%s %s service should be an array cache type for %s environment</comment>"
|
||||
, $service->getName()
|
||||
, $key
|
||||
, $cache->getName()
|
||||
, $this->env
|
||||
)
|
||||
"<comment>%s:doctrine:orm:%s %s service should be an array cache type for %s environment</comment>"
|
||||
, $service->getName()
|
||||
, $key
|
||||
, $cache->getName()
|
||||
, $this->env
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -497,20 +492,20 @@ class module_console_fileConfigCheck extends Command
|
||||
if ($e->getKey() === 'orm')
|
||||
{
|
||||
$e = new \Exception(sprintf(
|
||||
"Missing parameter %s for %s environment scope"
|
||||
, $e->getKey()
|
||||
, $this->env
|
||||
)
|
||||
"Missing parameter %s for %s environment scope"
|
||||
, $e->getKey()
|
||||
, $this->env
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$e = new \Exception(sprintf(
|
||||
"Missing parameter %s for %s service declared in %s scope."
|
||||
, $e->getKey()
|
||||
, $service->getName()
|
||||
, $this->env
|
||||
)
|
||||
"Missing parameter %s for %s service declared in %s scope."
|
||||
, $e->getKey()
|
||||
, $service->getName()
|
||||
, $this->env
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user