Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow use Propel before Silex boot

  • Loading branch information...
commit 41c06c4c3db2f27e674e6a3832f23df360ef84ff 1 parent b879eda
@oziks oziks authored
Showing with 17 additions and 5 deletions.
  1. +3 −5 README.md
  2. +14 −0 src/Propel/Silex/PropelServiceProvider.php
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
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.