Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #9 from oziks/master

Allow the use of Propel before Silex boots
  • Loading branch information...
commit b670cc039243c09bb2ebc7f094d33dabb216c664 2 parents b879eda + e143ec3
@willdurand willdurand authored
View
8 README.md
@@ -42,11 +42,9 @@ For more informations consult the [Propel documentation](http://www.propelorm.or
``` php
<?php
-$app->register(new Propel\Silex\PropelServiceProvider(), array(
- 'propel.path' => __DIR__.'/path/to/Propel.php',
- 'propel.config_file' => __DIR__.'/path/to/myproject-conf.php',
- 'propel.model_path' => __DIR__.'/path/to/model/classes',
-));
+$app['propel.config_file'] = __DIR__.'/path/to/myproject-conf.php';
+$app['propel.model_path'] = __DIR__.'/path/to/model/classes';
+$app->register(new Propel\Silex\PropelServiceProvider());
```
Alternatively, if you 've installed Propel by Git in `vendor/propel` and
View
1  composer.json
@@ -18,6 +18,7 @@
"silex/silex": "1.0.*",
"propel/propel1": "1.6.*"
},
+ "minimum-stability": "dev",
"autoload": {
"psr-0": { "Propel\\Silex": "src" }
}
View
14 src/Propel/Silex/PropelServiceProvider.php
@@ -20,12 +20,24 @@
*/
class PropelServiceProvider implements ServiceProviderInterface
{
+ protected $alreadyInit = false;
+
public function register(Application $app)
{
+ if (isset($app['propel.model_path']) && isset($app['propel.config_file'])) {
+ $this->initPropel($app);
+ }
}
public function boot(Application $app)
{
+ if (!$this->alreadyInit) {
+ $this->initPropel($app);
+ }
+ }
+
+ protected function initPropel(Application $app)
+ {
if (!class_exists('Propel')) {
require_once $this->guessPropel($app);
}
@@ -35,6 +47,8 @@ public function boot(Application $app)
\Propel::init($config);
set_include_path($modelPath . PATH_SEPARATOR . get_include_path());
+
+ $this->alreadyInit = true;
}
protected function guessPropel(Application $app)
Please sign in to comment.
Something went wrong with that request. Please try again.