Catch errors, use default database driver

Catch errors from not working PDO connections etc.
Added the memory driver as option.
This commit is contained in:
Barry
2013-03-26 10:20:39 +01:00
parent 5ccb7ce9bc
commit 14813b77b1
2 changed files with 42 additions and 24 deletions
+4 -1
View File
@@ -31,7 +31,10 @@ You can also publish the config-file to add extra facades (ie. for bundles) or s
The generator tries to identify the real class, but if it cannot be found, you can define it in the config file.
You can choose to include helper files. This is not enabled by default, but you can override this with the --helpers (-H) or --nohelpers (-N) option.
Some classes need a working database connection. If you do not have a working default connection, some facades will not be included.
You can use a in-memory sqlite driver, using the -M option.
You can choose to include helper files. This is not enabled by default, but you can override this with the --helpers (-H) option.
The Illuminate/Support/helpers.php is already set-up, but you can add/remove your own files in the config file.
@@ -30,7 +30,9 @@ class GeneratorCommand extends Command {
{
$filename = $this->argument('filename');
$this->setupDefaults();
if($this->option('memory')){
$this->useMemoryDriver();
}
$aliases = \Config::get('laravel-ide-helper::aliases');
$aliases += \Config::get('app.aliases');
@@ -55,7 +57,7 @@ class GeneratorCommand extends Command {
}
protected function setupDefaults(){
protected function useMemoryDriver(){
//Use a sqlite database in memory, to avoid connection errors on Database facades
\Config::set('database.connections.sqlite',array(
'driver' => 'sqlite',
@@ -85,7 +87,7 @@ class GeneratorCommand extends Command {
{
return array(
array('helpers', "H", InputOption::VALUE_NONE, 'Include the helper files'),
array('nohelpers', "N", InputOption::VALUE_NONE, 'Do not include the helper files'),
array('memory', "M", InputOption::VALUE_NONE, 'Use sqlite memory driver'),
array('sublime', "S", InputOption::VALUE_NONE, 'Use different style for SublimeText CodeIntel'),
);
}
@@ -99,13 +101,21 @@ class GeneratorCommand extends Command {
foreach($aliases as $alias => $facade){
if(method_exists($facade, 'getFacadeRoot')){
$root = get_class($facade::getFacadeRoot());
}else{
$root = $facade;
}
if(!class_exists($root) && !interface_exists($root)){
$this->error("Class $root is not found.");
try{
if(method_exists($facade, 'getFacadeRoot')){
$root = get_class($facade::getFacadeRoot());
}else{
$root = $facade;
}
if(!class_exists($root) && !interface_exists($root)){
$this->error("Class $root is not found.");
continue;
}
}catch(\PDOException $e){
$this->error("PDOException: ".$e->getMessage()."\nPlease configure your database connection correctly, or use the sqlite memory driver (-M). Skipping $facade.");
continue;
}catch(\Exception $e){
$this->error("Exception: ".$e->getMessage()."\nSkipping $facade.");
continue;
}
@@ -117,22 +127,27 @@ class GeneratorCommand extends Command {
$namespace = '';
}
$d->analyze($root);
try{
$d->analyze($root);
$output .= "namespace $namespace {\n";
if($sublime){
$output .= " class $alias extends $root{\n";
}else{
$output .= " class $alias{\n";
$output .= "\t/**\n\t * @var $root \$root\n\t */\n\t static private \$root;\n\n";
}
$methods = $d->getMethods();
$output .= "namespace $namespace {\n";
if($sublime){
$output .= " class $alias extends $root{\n";
}else{
$output .= " class $alias{\n";
$output .= "\t/**\n\t * @var $root \$root\n\t */\n\t static private \$root;\n\n";
}
$methods = $d->getMethods();
foreach ($methods as $method)
{
$output .= $this->parseMethod($method, $sublime);
foreach ($methods as $method)
{
$output .= $this->parseMethod($method, $sublime);
}
$output .= " }\n}\n\n";
}catch(\Exception $e){
$this->error("Exception: ".$e->getMessage()."\nCould not analyze $root.");
}
$output .= " }\n}\n\n";
}