This repository has been archived on 2026-07-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
espocrm-base/application/Espo/Core/Utils/Resolver.php
T
2013-11-18 12:58:06 +02:00

71 lines
1.3 KiB
PHP

<?php
namespace Espo\Core\Utils;
class Resolver
{
protected $exceptions = array(
'Doctrine\DBAL\DBALException' => 'DBALException',
'ReflectionException' => 'ReflectionException',
);
private $metadata;
public function __construct(\Espo\Core\Utils\Metadata $metadata)
{
$this->metadata = $metadata;
}
protected function getMetadata()
{
return $this->metadata;
}
public function handle($Exception)
{
$handler= get_class($Exception);
$trace= $Exception->getTrace();
$args= array();
if (is_array($trace[0]['args'])) {
$args= $trace[0]['args'];
}
if (in_array($handler, array_keys($this->exceptions))) {
$method= $this->exceptions[$handler];
$GLOBALS['log']->add('INFO', 'Try to resolve the exception - '.$handler);
$result= false;
try {
$result= $this->$method($args);
} catch(\Exception $e) {
$GLOBALS['log']->add('INFO', 'Could not resolve the exception - '.$handler.'. Details below:');
$GLOBALS['log']->catchException($e, false);
}
return $result;
}
return false;
}
protected function DBALException($args)
{
return $this->getMetadata()->getDoctrineConverter()->rebuildDatabase();
}
protected function ReflectionException($args)
{
return $this->getMetadata()->getDoctrineConverter()->generateEntities($args);
}
}
?>