Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Issue #7

  • Loading branch information...
commit e47eb590546ea7de5e838c23b92ecf74cc2a0193 1 parent aaef6f3
Cristiano Cinotti authored
1  .gitignore
View
@@ -1,2 +1,3 @@
vendor
composer.lock
+composer.phar
8 README.md
View
@@ -19,10 +19,6 @@ Parameters
* **propel.model_path** (optional): Path to where model classes are located.
Default is `/full/project/path/build/classes`
-* **propel.internal_autoload** (optional): Setting to true, forces Propel to use
- its own internal autoloader, instead of Silex one, to load model classes.
- Default is `false`
-
> It's strongly recommanded to use **absolute paths** for previous options.
@@ -46,10 +42,6 @@ For more informations consult the [Propel documentation](http://www.propelorm.or
``` php
<?php
-$app['autoloader']->registerNamespaces(array(
- 'Propel\Silex' => __DIR__ . '/../../vendor/propel/propel-service-provider/src',
-));
-
$app->register(new Propel\Silex\PropelServiceProvider(), array(
'propel.path' => __DIR__.'/path/to/Propel.php',
'propel.config_file' => __DIR__.'/path/to/myproject-conf.php',
62 src/Propel/Silex/PropelServiceProvider.php
View
@@ -26,14 +26,7 @@ public function register(Application $app)
require_once $this->guessPropel($app);
}
- $modelPath = null;
- if (isset($app['propel.model_path'])) {
- $modelPath = $app['propel.model_path'];
-
- if (!is_dir($modelPath)) {
- throw new \InvalidArgumentException('The given "propel.model_path" is not found.');
- }
- }
+ $modelPath = $this->guessModelPath($app);
if (isset($app['propel.config_file'])) {
$config = $app['propel.config_file'];
@@ -41,35 +34,8 @@ public function register(Application $app)
$config = $this->guessConfigFile();
}
- 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.'
- );
- }
- }
- }
-
\Propel::init($config);
+ set_include_path($modelPath . PATH_SEPARATOR . get_include_path());
}
protected function guessConfigFile()
@@ -95,7 +61,7 @@ protected function guessConfigFile()
return $config;
}
- public function guessPropel(Application $app)
+ protected function guessPropel(Application $app)
{
if (isset($app['propel.path'])) {
$propel = $app['propel.path'] . '/Propel.php';
@@ -111,4 +77,24 @@ public function guessPropel(Application $app)
return $propel;
}
-}
+
+ protected function guessModelPath(Application $app)
+ {
+ if (isset($app['propel.model_path'])) {
+ $modelPath = $app['propel.model_path'];
+ } else {
+ $modelPath = './build/classes';
+ }
+
+ if (!is_dir($modelPath)) {
+ throw new \InvalidArgumentException('The given "propel.model_path" is not found.');
+ }
+
+ return $modelPath;
+ }
+
+ public function boot(Application $a)
+ {
+
+ }
+}
32 tests/Propel/Tests/Silex/PropelServiceProviderTest.php
View
@@ -36,8 +36,8 @@ public function testRegisterWithProperties()
'propel.model_path' => __DIR__ . '/PropelFixtures/FixtFull/build/classes',
));
- $this->assertTrue(class_exists('Propel'));
-
+ $this->assertTrue(class_exists('Propel'), 'Propel class does not exist.');
+ $this->assertGreaterThan(strpos(get_include_path(), $app['propel.model_path']), 1);
}
public function testRegisterDefaults()
@@ -50,28 +50,15 @@ public function testRegisterDefaults()
'propel.path' => __DIR__ . '/../../../../vendor/propel/propel1/runtime/lib',
));
- $this->assertTrue(class_exists('Propel'));
+ $this->assertTrue(class_exists('Propel'), 'Propel class does not exist.');
+ $this->assertGreaterThan(strpos(get_include_path(), './build/classes'), 1);
chdir($current);
}
- public function testRegisterInternalAutoload()
- {
- $app = new Application();
- $app->register(new PropelServiceProvider(), array(
- 'propel.path' => __DIR__.'/../../../../vendor/propel/propel1/runtime/lib',
- 'propel.config_file' => __DIR__.'/PropelFixtures/FixtFull/build/conf/myproject-conf.php',
- 'propel.model_path' => __DIR__.'/PropelFixtures/FixtFull/build/classes',
- 'propel.internal_autoload' => true,
- ));
-
- $this->assertTrue(class_exists('Propel'), 'Propel class does not exist.');
- $this->assertGreaterThan(strpos(get_include_path(), $app['propel.model_path']), 1);
- }
-
/**
* @expectedException InvalidArgumentException
- * @expectedExceptionMessage Please, initialize the "propel.config_file" parameter.
+ * @expectedExceptionMessage Unable to guess the config file. Please, initialize the "propel.config_file" parameter.
*/
public function testConfigFilePropertyNotInitialized()
{
@@ -106,14 +93,15 @@ public function testWrongConfigFile()
/**
* @expectedException InvalidArgumentException
+ * @expectedExceptionMessage The given "propel.model_path" is not found.
*/
- public function testNoNamespace()
+ public function testWrongModelPath()
{
$app = new Application();
$app->register(new PropelServiceProvider(), array(
- 'propel.path' => __DIR__.'/../../../../vendor/propel/propel1/runtime/lib',
- 'propel.model_path' => __DIR__.'/PropelFixtures/FixtEmpty/build/classes',
- 'propel.config_file' => __DIR__.'/PropelFixtures/FixtFull/build/conf/myproject-conf.php',
+ 'propel.path' => __DIR__ . '/../../../../vendor/propel/propel1/runtime/lib',
+ 'propel.config_file' => __DIR__ . '/PropelFixtures/FixtFull/build/conf/myproject-conf.php',
+ 'propel.model_path' => __DIR__ . '/wrongDir/build/classes',
));
}
2  tests/bootstrap.php
View
@@ -1,6 +1,6 @@
<?php
-$loader = require_once __DIR__.'/../vendor/.composer/autoload.php';
+$loader = require_once __DIR__.'/../vendor/autoload.php';
$loader->register('Propel', __DIR__.'/../src');
require_once __DIR__.'/../vendor/propel/propel1/runtime/lib/Propel.php';
Please sign in to comment.
Something went wrong with that request. Please try again.