Skip to content

Commit e01b56d

Browse files
committed
Merge pull request #8 from cristianoc72/master
Update according to new Silex version (see issue #7)
2 parents aaef6f3 + e47eb59 commit e01b56d

File tree

5 files changed

+36
-69
lines changed

5 files changed

+36
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor
22
composer.lock
3+
composer.phar

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ Parameters
1919
* **propel.model_path** (optional): Path to where model classes are located.
2020
Default is `/full/project/path/build/classes`
2121

22-
* **propel.internal_autoload** (optional): Setting to true, forces Propel to use
23-
its own internal autoloader, instead of Silex one, to load model classes.
24-
Default is `false`
25-
2622

2723
> It's strongly recommanded to use **absolute paths** for previous options.
2824
@@ -46,10 +42,6 @@ For more informations consult the [Propel documentation](http://www.propelorm.or
4642
``` php
4743
<?php
4844

49-
$app['autoloader']->registerNamespaces(array(
50-
'Propel\Silex' => __DIR__ . '/../../vendor/propel/propel-service-provider/src',
51-
));
52-
5345
$app->register(new Propel\Silex\PropelServiceProvider(), array(
5446
'propel.path' => __DIR__.'/path/to/Propel.php',
5547
'propel.config_file' => __DIR__.'/path/to/myproject-conf.php',

src/Propel/Silex/PropelServiceProvider.php

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,16 @@ public function register(Application $app)
2626
require_once $this->guessPropel($app);
2727
}
2828

29-
$modelPath = null;
30-
if (isset($app['propel.model_path'])) {
31-
$modelPath = $app['propel.model_path'];
32-
33-
if (!is_dir($modelPath)) {
34-
throw new \InvalidArgumentException('The given "propel.model_path" is not found.');
35-
}
36-
}
29+
$modelPath = $this->guessModelPath($app);
3730

3831
if (isset($app['propel.config_file'])) {
3932
$config = $app['propel.config_file'];
4033
} else {
4134
$config = $this->guessConfigFile();
4235
}
4336

44-
if (null !== $modelPath) {
45-
if (isset($app['propel.internal_autoload']) && true === $app['propel.internal_autoload']) {
46-
set_include_path($modelPath . PATH_SEPARATOR . get_include_path());
47-
} else {
48-
//model namespaces are subdir of $modelPath directory
49-
$dir = new \DirectoryIterator($modelPath);
50-
51-
//Unfortunately DirectoryIterator count() method is not always implemented, so we need a boolean
52-
//to check if $modelPath dir has at least one subdir, otherwise te model has not yet been generated or
53-
//$modelPath contains a wrong value.
54-
$built = false;
55-
foreach ($dir as $fileInfo) {
56-
if ($fileInfo->isDir()) {
57-
if (!$fileInfo->isDot()) {
58-
$built = true;
59-
$app['autoloader']->registerNamespace($fileInfo->getFilename(), $modelPath);
60-
}
61-
}
62-
}
63-
64-
if (!$built) {
65-
throw new \InvalidArgumentException(
66-
'The '.$modelPath.' has no subdir. May be "propel.model_path" value is wrong or you didn\'t yet generate your model.'
67-
);
68-
}
69-
}
70-
}
71-
7237
\Propel::init($config);
38+
set_include_path($modelPath . PATH_SEPARATOR . get_include_path());
7339
}
7440

7541
protected function guessConfigFile()
@@ -95,7 +61,7 @@ protected function guessConfigFile()
9561
return $config;
9662
}
9763

98-
public function guessPropel(Application $app)
64+
protected function guessPropel(Application $app)
9965
{
10066
if (isset($app['propel.path'])) {
10167
$propel = $app['propel.path'] . '/Propel.php';
@@ -111,4 +77,24 @@ public function guessPropel(Application $app)
11177

11278
return $propel;
11379
}
114-
}
80+
81+
protected function guessModelPath(Application $app)
82+
{
83+
if (isset($app['propel.model_path'])) {
84+
$modelPath = $app['propel.model_path'];
85+
} else {
86+
$modelPath = './build/classes';
87+
}
88+
89+
if (!is_dir($modelPath)) {
90+
throw new \InvalidArgumentException('The given "propel.model_path" is not found.');
91+
}
92+
93+
return $modelPath;
94+
}
95+
96+
public function boot(Application $a)
97+
{
98+
99+
}
100+
}

tests/Propel/Tests/Silex/PropelServiceProviderTest.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function testRegisterWithProperties()
3636
'propel.model_path' => __DIR__ . '/PropelFixtures/FixtFull/build/classes',
3737
));
3838

39-
$this->assertTrue(class_exists('Propel'));
40-
39+
$this->assertTrue(class_exists('Propel'), 'Propel class does not exist.');
40+
$this->assertGreaterThan(strpos(get_include_path(), $app['propel.model_path']), 1);
4141
}
4242

4343
public function testRegisterDefaults()
@@ -50,28 +50,15 @@ public function testRegisterDefaults()
5050
'propel.path' => __DIR__ . '/../../../../vendor/propel/propel1/runtime/lib',
5151
));
5252

53-
$this->assertTrue(class_exists('Propel'));
53+
$this->assertTrue(class_exists('Propel'), 'Propel class does not exist.');
54+
$this->assertGreaterThan(strpos(get_include_path(), './build/classes'), 1);
5455

5556
chdir($current);
5657
}
5758

58-
public function testRegisterInternalAutoload()
59-
{
60-
$app = new Application();
61-
$app->register(new PropelServiceProvider(), array(
62-
'propel.path' => __DIR__.'/../../../../vendor/propel/propel1/runtime/lib',
63-
'propel.config_file' => __DIR__.'/PropelFixtures/FixtFull/build/conf/myproject-conf.php',
64-
'propel.model_path' => __DIR__.'/PropelFixtures/FixtFull/build/classes',
65-
'propel.internal_autoload' => true,
66-
));
67-
68-
$this->assertTrue(class_exists('Propel'), 'Propel class does not exist.');
69-
$this->assertGreaterThan(strpos(get_include_path(), $app['propel.model_path']), 1);
70-
}
71-
7259
/**
7360
* @expectedException InvalidArgumentException
74-
* @expectedExceptionMessage Please, initialize the "propel.config_file" parameter.
61+
* @expectedExceptionMessage Unable to guess the config file. Please, initialize the "propel.config_file" parameter.
7562
*/
7663
public function testConfigFilePropertyNotInitialized()
7764
{
@@ -106,14 +93,15 @@ public function testWrongConfigFile()
10693

10794
/**
10895
* @expectedException InvalidArgumentException
96+
* @expectedExceptionMessage The given "propel.model_path" is not found.
10997
*/
110-
public function testNoNamespace()
98+
public function testWrongModelPath()
11199
{
112100
$app = new Application();
113101
$app->register(new PropelServiceProvider(), array(
114-
'propel.path' => __DIR__.'/../../../../vendor/propel/propel1/runtime/lib',
115-
'propel.model_path' => __DIR__.'/PropelFixtures/FixtEmpty/build/classes',
116-
'propel.config_file' => __DIR__.'/PropelFixtures/FixtFull/build/conf/myproject-conf.php',
102+
'propel.path' => __DIR__ . '/../../../../vendor/propel/propel1/runtime/lib',
103+
'propel.config_file' => __DIR__ . '/PropelFixtures/FixtFull/build/conf/myproject-conf.php',
104+
'propel.model_path' => __DIR__ . '/wrongDir/build/classes',
117105
));
118106
}
119107

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
$loader = require_once __DIR__.'/../vendor/.composer/autoload.php';
3+
$loader = require_once __DIR__.'/../vendor/autoload.php';
44
$loader->register('Propel', __DIR__.'/../src');
55

66
require_once __DIR__.'/../vendor/propel/propel1/runtime/lib/Propel.php';

0 commit comments

Comments
 (0)