-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ServiceProviders and example propel config
- Loading branch information
Showing
7 changed files
with
267 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,42 @@ | ||
laravel-propel | ||
propel-laravel | ||
============== | ||
|
||
Propel integration for Laravel framework | ||
Propel2 integration for Laravel framework 4 | ||
|
||
Usage | ||
----- | ||
|
||
Require this package with composer using the following command: | ||
|
||
composer require allboo/propel-laravel | ||
|
||
After updating composer, add the ServiceProviders to the providers array in app/config/app.php | ||
|
||
'Allboo\PropelLaravel\GeneratorServiceProvider', | ||
'Allboo\PropelLaravel\RuntimeServiceProvider', | ||
|
||
Create Propel configuration file `app/config/propel.php` | ||
Note: See example config in `example/config/propel.php` | ||
Within provided config schemas files are located into `app/database/` folder, models are generated into `app/models`, migrations into `app/database/migrations` | ||
|
||
|
||
You can now use Propel commands via artisan, ex | ||
|
||
php artisan propel:build | ||
|
||
etc. | ||
|
||
|
||
Services | ||
-------- | ||
|
||
No service is provided. | ||
|
||
Propel configures and manages itself by using static methods and its own service container, so no service is registered into Application. | ||
Actually, the `GeneratorServiceProvider` class injects Propel tasks into artisan tasks list with prefix `propel:` | ||
`RuntimeServiceProvider` class initializes Propel runtime configuration | ||
|
||
|
||
See also | ||
-------- | ||
[Make Propel models work with Laravel Form::model() without making it an array](https://github.com/stephangroen/propel-laravel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "allboo/propel-laravel", | ||
"description": "Propel integration for Laravel framework.", | ||
"keywords": ["laravel", "propel", "orm", "Active Record"], | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Alex Kazinskiy", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"laravel/framework": "4.2.*", | ||
"propel/propel": "~2.0@dev" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Allboo\\PropelLaravel\\": "src" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
return [ | ||
'propel' => [ | ||
'general' => [ | ||
'project' => 'MyProject', | ||
'version' => '1.0', | ||
], | ||
|
||
'paths' => [ | ||
'projectDir' => app_path() . '/propel', | ||
'schemaDir' => app_path() . '/database', | ||
'outputDir' => app_path() . '/propel', | ||
'phpDir' => app_path() . '/models', | ||
'phpConfDir' => app_path() . '/propel', | ||
'sqlDir' => app_path() . '/database', | ||
'migrationDir' => app_path() . '/database/migrations', | ||
'composerDir' => base_path(), | ||
], | ||
|
||
'database' => [ | ||
'connections' => array_map(function($item) { | ||
return [ | ||
'adapter' => $item['driver'], | ||
'dsn' => $item['driver'] . ':host=' . $item['host'] . ';port=' . (empty($item['port']) ? '3306' : $item['port']) . ';dbname=' . $item['database'], | ||
'user' => $item['username'], | ||
'password' => $item['password'], | ||
'settings' => [ | ||
'charset' => $item['charset'], | ||
'queries' => [ | ||
'SET NAMES utf8 COLLATE utf8_unicode_ci, COLLATION_CONNECTION = utf8_unicode_ci, COLLATION_DATABASE = utf8_unicode_ci, COLLATION_SERVER = utf8_unicode_ci' | ||
], | ||
], | ||
]; | ||
}, app()['config']->get('database.connections')), | ||
'adapters' => [ | ||
'mysql' => [ | ||
'tableType' => 'InnoDB' | ||
], | ||
], | ||
], | ||
|
||
'runtime' => [ | ||
'defaultConnection' => app()['config']->get('database.default'), | ||
'connections' => array_keys(app()['config']->get('database.connections')), | ||
], | ||
|
||
'generator' => [ | ||
'defaultConnection' => app()['config']->get('database.default'), | ||
'connections' => array_keys(app()['config']->get('database.connections')), | ||
|
||
'targetPackage' => '', | ||
'namespaceAutoPackage' => false, | ||
], | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"providers": [ | ||
"Allboo\PropelLaravel\GeneratorServiceProvider", | ||
"Allboo\PropelLaravel\RuntimeServiceProvider", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* Laravel Propel integration | ||
* | ||
* @author Alex Kazinskiy <[email protected]> | ||
* @copyright 2014 Alex Kazinskiy | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT | ||
* @link https://github.com/alboo/laravel-propel | ||
*/ | ||
|
||
namespace Allboo\PropelLaravel; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
class GeneratorServiceProvider extends ServiceProvider | ||
{ | ||
|
||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = true; | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
if (!class_exists('Propel\\Runtime\\Propel', true)) { | ||
throw new \InvalidArgumentException('Unable to find Propel, did you install it?'); | ||
} | ||
|
||
$finder = new Finder(); | ||
$finder->files()->name('*.php')->in(base_path().'/vendor/propel/propel/src/Propel/Generator/Command')->depth(0); | ||
|
||
$commands = []; | ||
foreach ($finder as $file) { | ||
$ns = '\\Propel\\Generator\\Command'; | ||
$r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php')); | ||
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) { | ||
$c = $r->newInstance(); | ||
|
||
$command = 'command.propel.' . $c->getName(); | ||
$commands[] = $command; | ||
|
||
$c->setName('propel:' . $c->getName()); | ||
$c->setAliases(array_map(function($item) {return 'propel:' . $item;}, $c->getAliases())); | ||
|
||
$this->app[$command] = $this->app->share( | ||
function ($app) use ($c) { | ||
chdir(app_path() . '/config'); | ||
return $c; | ||
} | ||
); | ||
} | ||
} | ||
|
||
$this->commands($commands); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return array('command.propel'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/** | ||
* Laravel Propel integration | ||
* | ||
* @author Alex Kazinskiy <[email protected]> | ||
* @copyright 2014 Alex Kazinskiy | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT | ||
* @link https://github.com/alboo/laravel-propel | ||
*/ | ||
|
||
namespace Allboo\PropelLaravel; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use Propel\Runtime\Propel; | ||
|
||
class RuntimeServiceProvider extends ServiceProvider | ||
{ | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
if (!$this->app->config['propel.propel.runtime.connections']) { | ||
throw new \InvalidArgumentException('Unable to guess Propel runtime config file. Please, initialize the "propel.runtime" parameter.'); | ||
} | ||
|
||
/** @var \Propel\Runtime\ServiceContainer\StandardServiceContainer */ | ||
$serviceContainer = \Propel\Runtime\Propel::getServiceContainer(); | ||
$serviceContainer->closeConnections(); | ||
$serviceContainer->checkVersion('2.0.0-dev'); | ||
|
||
$propel_conf = $this->app->config['propel.propel']; | ||
foreach ($propel_conf['runtime']['connections'] as $connection_name) { | ||
$config = $propel_conf['database']['connections'][$connection_name]; | ||
if (!isset($config['classname'])) { | ||
$config['classname'] = '\\Propel\\Runtime\\Connection\\ConnectionWrapper'; | ||
} | ||
|
||
$serviceContainer->setAdapterClass($connection_name, $config['adapter']); | ||
$manager = new \Propel\Runtime\Connection\ConnectionManagerSingle(); | ||
$manager->setConfiguration($config); | ||
$manager->setName($connection_name); | ||
$serviceContainer->setConnectionManager($connection_name, $manager); | ||
} | ||
|
||
$serviceContainer->setDefaultDatasource($propel_conf['runtime']['defaultConnection']); | ||
|
||
Propel::setServiceContainer($serviceContainer); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
if (!class_exists('Propel\\Runtime\\Propel', true)) { | ||
throw new \InvalidArgumentException('Unable to find Propel, did you install it?'); | ||
} | ||
} | ||
} |