Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit f1e67ab1057d241b73ead6937d5eb6f20161b6b3 @willdurand willdurand committed Feb 17, 2012
@@ -0,0 +1 @@
+vendor
128 README.md
@@ -0,0 +1,128 @@
+PropelServiceProvider
+=====================
+
+The *PropelServiceProvider* provides integration with [Propel](http://www.propelorm.org).
+
+Parameters
+----------
+
+* **propel.path** (optional): The path in wich Propel.php will be found. Usually, for
+ PEAR installation, it is `propel` while for Git installation it is
+ `vendor/propel/runtime/lib`.
+ Default is `/full/project/path/vendor/propel/runtime/lib`.
+
+* **propel.config_file** (optional): The name of Propel configuration file with full path.
+ Default is `/full/project/path/build/conf/projectname-conf.php`
+
+* **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.
+
+
+Services
+--------
+
+No service is provided.
+
+Propel configures and manages itself by **using** static methods, so no service is registered into Application.
+Actually, the PropelServiceProvider class initializes Propel in a more "Silex-ian" way.
+
+
+Registering
+-----------
+
+Make sure you place a copy of *Propel* in `vendor/propel` or install it through PEAR, or Composer.
+
+For more informations consult the [Propel documentation](http://www.propelorm.org/documentation/01-installation.html):
+
+``` 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,
+ 'propel.model_path' => __DIR__.'/path/to/model/classes',
+));
+```
+
+Alternatively, if you 've installed Propel by Git in `vendor/propel` and
+you built your model with default Propel generator options:
+
+``` php
+<?php
+
+$app->register(new Propel\Silex\PropelServiceProvider());
+```
+
+
+We can consider "default" Propel generator options:
+
+* Put `build.properties` and `schema.xml` files into the main directory project,
+usually where file `index.php` is located.
+
+* In `build.properties` file, define only `propel.database`, `propel.project`
+and `propel.namespace.autopackage` properties.
+
+
+Usage
+-----
+
+You'll have to build the model by yourself. According to Propel documentation, you'll need three files:
+
+* `schema.xml` which contains your database schema;
+
+* `build.properties` more information below;
+
+* `runtime-conf.xml` which contains the database configuration.
+
+
+Use the `propel-gen` script to create all files (SQL, configuration, Model classes).
+
+By default, the *PropelServiceProvider* relies on the Silex autoloader you have to configure to load
+model classes. Of course, the Silex autoloader needs the model to be built with namespaces,
+so be sure to set this property into the `build.properties` file:
+
+``` yaml
+propel.namespace.autopackage = true
+
+The recommended configuration for your `build.properties` file is:
+
+propel.project = <project_name>
+
+propel.namespace.autoPackage = true
+propel.packageObjectModel = true
+
+# Enable full use of the DateTime class.
+# Setting this to true means that getter methods for date/time/timestamp
+# columns will return a DateTime object when the default format is empty.
+propel.useDateTimeClass = true
+
+# Specify a custom DateTime subclass that you wish to have Propel use
+# for temporal values.
+propel.dateTimeClass = DateTime
+
+# These are the default formats that will be used when fetching values from
+# temporal columns in Propel. You can always specify these when calling the
+# methods directly, but for methods like getByName() it is nice to change
+# the defaults.
+# To have these methods return DateTime objects instead, you should set these
+# to empty values
+propel.defaultTimeStampFormat =
+propel.defaultTimeFormat =
+propel.defaultDateFormat =
+```
+
+If you plan to build your model without using namespaces, you need to force Propel to use
+its internal autoloader. Do this by setting the option `propel.internal_autoload` to `true`.
+
+For more information, consult the [Propel documentation](http://www.propelorm.org/documentation/).
@@ -0,0 +1,24 @@
+{
+ "name": "propel/propel-service-provider",
+ "type": "library",
+ "description": "Propel integrationfor Silex.",
+ "keywords": ["silex", "propel"],
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "William Durand",
+ "email": "william.durand1@gmail.com"
+ },
+ {
+ "name": "Cristiano Cinotti",
+ "email": "cristianocinotti@gmail.com"
+ }
+ ],
+ "require": {
+ "silex/silex": ">=1.0.0-dev",
+ "propel/propel1": "master-dev"
+ },
+ "autoload": {
+ "psr-0": { "Propel\\Silex": "src" }
+ }
+}
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="tests/bootstrap.php"
+>
+ <testsuites>
+ <testsuite name="PropelServiceProvider Test Suite">
+ <directory>./tests/Propel/</directory>
+ </testsuite>
+ </testsuites>
+</phpunit>
@@ -0,0 +1,67 @@
+<?php
+
+/*
+ * This file is part of the Silex framework.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Propel\Silex;
+
+use Silex\Application;
+use Silex\ServiceProviderInterface;
+
+/**
+ * Propel service provider.
+ *
+ * @author Cristiano Cinotti <cristianocinotti@gmail.com>
+ */
+class PropelServiceProvider implements ServiceProviderInterface
+{
+ public function register(Application $app)
+ {
+ if (isset($app['propel.path'])) {
+ $propel = $app['propel.path'].'/Propel.php';
+ } else {
+ $propel = realpath('./vendor/propel/runtime/lib/Propel.php');
+ }
+
+ if (isset($app['propel.model_path'])) {
+ $modelPath = $app['propel.model_path'];
+ } else {
+ $modelPath = realpath('./build/classes');
+ }
+
+ if (isset($app['propel.config_file'])) {
+ $config = $app['propel.config_file'];
+ } else {
+ $currentDir = getcwd();
+ if (!chdir(realpath('./build/conf'))) {
+ throw new \InvalidArgumentException(__CLASS__.': please, initialize the "propel.config_file" parameter.');
+ }
+
+ $files = glob('classmap*.php');
+ if (!$files || empty($files)) {
+ throw new \InvalidArgumentException(__CLASS__.': please, initialize the "propel.config_file" parameter.');
+ }
+
+ $config = '/build/conf/'.substr(strstr($files[0], '-'), 1);
+ chdir($currentDir);
+ }
+
+ if (isset($app['propel.internal_autoload']) && true === $app['propel.internal_autoload']) {
+ set_include_path($modelPath.PATH_SEPARATOR.get_include_path());
+ } else {
+ $app['autoloader']->registerNamespace('model', $modelPath);
+ }
+
+ if (!class_exists('Propel')) {
+ require_once $propel;
+ }
+
+ \Propel::init($config);
+ }
+}
@@ -0,0 +1,7 @@
+<?php
+// This file generated by Propel 1.6.4-dev convert-conf target
+return array (
+ 'model\\Class1' => 'model/Class1.php',
+ 'model\\Class2' => 'model/Class2.php',
+ 'model\\Class3' => 'model/Class3.php',
+);
@@ -0,0 +1,19 @@
+<?php
+// This file generated by Propel 1.6.4-dev convert-conf target
+$conf = array (
+ 'datasources' =>
+ array (
+ 'myproject' =>
+ array (
+ 'adapter' => 'sqlite',
+ 'connection' =>
+ array (
+ 'dsn' => 'sqlite:',
+ ),
+ ),
+ 'default' => 'myproject',
+ ),
+ 'generator_version' => '1.6.4-dev',
+);
+$conf['classmap'] = include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classmap-myproject-conf.php');
+return $conf;
@@ -0,0 +1,70 @@
+<?php
+
+/*
+ * This file is part of the Silex framework.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Propel\Tests\Silex;
+
+use Propel\Silex\PropelServiceProvider;
+use Silex\Application;
+
+/**
+ * PropelProvider test cases.
+ *
+ * Cristiano Cinotti <cristianocinotti@gmail.com>
+ */
+class PropelServiceProviderTest extends \PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ if (!class_exists('\Propel')) {
+ $this->markTestSkipped('The Propel submodule is not installed.');
+ }
+ }
+
+ public function testRegisterWithProperties()
+ {
+ $app = new Application();
+ $app->register(new PropelServiceProvider(), array(
+ 'propel.path' =>__DIR__ . '/../../../../vendor/propel/runtime/lib',
+ 'propel.config_file' =>__DIR__ . '/PropelFixtures/build/conf/myproject-conf.php',
+ 'propel.model_path' =>__DIR__ . '/PropelFixtures/build/classes',
+ ));
+
+ $this->assertTrue(class_exists('Propel'));
+
+ }
+
+ public function testRegisterDefaults()
+ {
+ $current = getcwd();
+ chdir(__DIR__.'/PropelFixtures');
+
+ $app = new Application();
+ $app->register(new PropelServiceProvider());
+
+ $this->assertTrue(class_exists('Propel'));
+
+ chdir($current);
+ }
+
+ public function testRegisterInternalAutoload()
+ {
+ $app = new Application();
+ $app->register(new PropelServiceProvider(), array(
+ 'propel.path' => __DIR__.'/../../../../vendor/propel/runtime/lib',
+ 'propel.config_file' => __DIR__.'/PropelFixtures/build/conf/myproject-conf.php',
+ 'propel.model_path' => __DIR__.'/PropelFixtures/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);
+ }
+}
@@ -0,0 +1,6 @@
+<?php
+
+$loader = require_once __DIR__.'/../vendor/.composer/autoload.php';
+$loader->register('Propel', __DIR__.'/../src');
+
+require_once __DIR__.'/../vendor/propel/propel1/runtime/lib/Propel.php';

0 comments on commit f1e67ab

Please sign in to comment.