Permalink
Browse files

Added some checks to fix problems found on testing

  • Loading branch information...
1 parent fae6e1e commit 447ef74dbb4c4f91c235bc8e5620a8380f619b7c @cristianoc72 cristianoc72 committed Mar 21, 2012
Showing with 18 additions and 2 deletions.
  1. +18 −2 src/Propel/Silex/PropelServiceProvider.php
@@ -33,12 +33,16 @@ public function register(Application $app)
} else {
$modelPath = realpath('./build/classes');
}
+
+ if (!is_dir($modelPath)) {
+ throw new \InvalidArgumentException(__CLASS__.': please, initialize the "propel.model_path" parameter (did you already generate your model?)');
+ }
if (isset($app['propel.config_file'])) {
$config = $app['propel.config_file'];
} else {
$currentDir = getcwd();
- if (!chdir(realpath('./build/conf'))) {
+ if (!@chdir(realpath('./build/conf'))) {
throw new \InvalidArgumentException(__CLASS__.': please, initialize the "propel.config_file" parameter.');
}
@@ -56,11 +60,23 @@ public function register(Application $app)
} else {
//model namespaces are subdir of $modelPath directory
$dir = new \DirectoryIterator($modelPath);
+
+ //Unfortunately DirectoryIterator count() method is not always implemented, so we need a boolean
+ //to check if $modelPath dir has at least one subdir, otherwise te model has not yet been generated or
+ //$modelPath contains a wrong value.
+ $built = false;
foreach ($dir as $fileInfo) {
if ($fileInfo->isDir()) {
- $app['autoloader']->registerNamespace($fileInfo->getFilename(), $modelPath);
+ if (!$fileInfo->isDot()) {
+ $built = true;
+ $app['autoloader']->registerNamespace($fileInfo->getFilename(), $modelPath);
+ }
}
}
+
+ if (!$built) {
+ throw new \InvalidArgumentException(__CLASS__.': '.$modelPath.' has no subdir. May be "propel.model_path" value is wrong or you didn\'t yet generate your model.');
+ }
}
if (!class_exists('Propel')) {

0 comments on commit 447ef74

Please sign in to comment.