Skip to content
Browse files

Continued refactoring

  • Loading branch information...
1 parent 35c2072 commit aaef6f3ecbd6c9cd2d4deba53a3b0a1d7aef4bfd @willdurand willdurand committed May 9, 2012
Showing with 41 additions and 34 deletions.
  1. +41 −34 src/Propel/Silex/PropelServiceProvider.php
View
75 src/Propel/Silex/PropelServiceProvider.php
@@ -22,16 +22,8 @@ class PropelServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
- if (isset($app['propel.path'])) {
- $propel = $app['propel.path'] . '/Propel.php';
- } else {
- if (!is_file($propel = realpath('./vendor/propel/propel1/runtime/lib/Propel.php'))) {
- $propel = realpath('./../vendor/propel/propel1/runtime/lib/Propel.php');
- }
- }
-
- if (!is_file($propel)) {
- throw new \InvalidArgumentException('Unable to find Propel, did you set the "propel.path" parameter?');
+ if (!class_exists('Propel')) {
+ require_once $this->guessPropel($app);
}
$modelPath = null;
@@ -49,36 +41,34 @@ public function register(Application $app)
$config = $this->guessConfigFile();
}
- if (isset($app['propel.internal_autoload']) && true === $app['propel.internal_autoload'] && null !== $modelPath) {
- set_include_path($modelPath . PATH_SEPARATOR . get_include_path());
- } elseif (null !== $modelPath) {
- //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()) {
- if (!$fileInfo->isDot()) {
- $built = true;
- $app['autoloader']->registerNamespace($fileInfo->getFilename(), $modelPath);
+ if (null !== $modelPath) {
+ if (isset($app['propel.internal_autoload']) && true === $app['propel.internal_autoload']) {
+ set_include_path($modelPath . PATH_SEPARATOR . get_include_path());
+ } 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()) {
+ if (!$fileInfo->isDot()) {
+ $built = true;
+ $app['autoloader']->registerNamespace($fileInfo->getFilename(), $modelPath);
+ }
}
}
- }
- if (!$built) {
- throw new \InvalidArgumentException(
- 'The '.$modelPath.' has no subdir. May be "propel.model_path" value is wrong or you didn\'t yet generate your model.'
- );
+ if (!$built) {
+ throw new \InvalidArgumentException(
+ 'The '.$modelPath.' has no subdir. May be "propel.model_path" value is wrong or you didn\'t yet generate your model.'
+ );
+ }
}
}
- if (!class_exists('Propel')) {
- require_once $propel;
- }
-
\Propel::init($config);
}
@@ -104,4 +94,21 @@ protected function guessConfigFile()
return $config;
}
+
+ public function guessPropel(Application $app)
+ {
+ if (isset($app['propel.path'])) {
+ $propel = $app['propel.path'] . '/Propel.php';
+ } else {
+ if (!is_file($propel = realpath('./vendor/propel/propel1/runtime/lib/Propel.php'))) {
+ $propel = realpath('./../vendor/propel/propel1/runtime/lib/Propel.php');
+ }
+ }
+
+ if (!is_file($propel)) {
+ throw new \InvalidArgumentException('Unable to find Propel, did you set the "propel.path" parameter?');
+ }
+
+ return $propel;
+ }
}

0 comments on commit aaef6f3

Please sign in to comment.
Something went wrong with that request. Please try again.