[PropelBundle] fixed Propel and Phing autoloading

This commit is contained in:
Fabien Potencier 2010-05-27 16:47:39 +02:00
parent 13839f23ce
commit c9e8934ee0
4 changed files with 19 additions and 38 deletions

View File

@ -17,6 +17,12 @@ class Bundle extends BaseBundle
public function boot(ContainerInterface $container) public function boot(ContainerInterface $container)
{ {
require_once $container->getParameter('propel.path').'/runtime/lib/Propel.php';
if (0 === strncasecmp(PHP_SAPI, 'cli', 3)) {
set_include_path($container->getParameter('propel.phing_path').'/classes'.PATH_SEPARATOR.get_include_path());
}
$kernel = $container->getKernelService(); $kernel = $container->getKernelService();
if (!file_exists($autoload = $kernel->getCacheDir().'/propel_autoload.php')) { if (!file_exists($autoload = $kernel->getCacheDir().'/propel_autoload.php')) {
$map = array(); $map = array();

View File

@ -135,7 +135,7 @@ class BuildCommand extends Command
// Build file // Build file
$args[] = '-f'; $args[] = '-f';
$args[] = realpath($kernel->getContainer()->getParameter('propel.generator.path').DIRECTORY_SEPARATOR.'build.xml'); $args[] = realpath($kernel->getContainer()->getParameter('propel.path').'/generator/build.xml');
/* /*
// Logger // Logger

View File

@ -15,20 +15,25 @@ class PropelExtension extends LoaderExtension
); );
/** /**
* Loads the DBAL configuration. * Loads the Propel configuration.
* *
* @param array $config A configuration array * @param array $config A configuration array
* *
* @return BuilderConfiguration A BuilderConfiguration instance * @return BuilderConfiguration A BuilderConfiguration instance
*/ */
public function generatorLoad($config) public function configLoad($config)
{ {
if (!isset($config['path'])) { if (!isset($config['path'])) {
throw new \InvalidArgumentException('The "path" parameter is mandatory.'); throw new \InvalidArgumentException('The "path" parameter is mandatory.');
} }
$configuration = new BuilderConfiguration(); $configuration = new BuilderConfiguration();
$configuration->setParameter('propel.generator.path', $config['path']); $configuration->setParameter('propel.path', $config['path']);
if (isset($config['phing_path']))
{
$configuration->setParameter('propel.phing_path', $config['phing_path']);
}
return $configuration; return $configuration;
} }

View File

@ -23,8 +23,9 @@ Sample Configuration
### Project configuration ### Project configuration
# in sandbox/hello/config/config.yml # in sandbox/hello/config/config.yml
propel.generator: propel.config:
path: %kernel.root_dir%/../src/vendor/propel/generator path: %kernel.root_dir%/../src/vendor/propel
phing_path: %kernel.root_dir%/../src/vendor/phing
propel.dbal: propel.dbal:
driver: mysql driver: mysql
@ -41,38 +42,7 @@ Sample Configuration
# dsn: mysql:host=localhost;dbname=test # dsn: mysql:host=localhost;dbname=test
# options: {} # options: {}
### Autoloading
// in src/autoload.php
<?php
require_once __DIR__.'/vendor/symfony/src/Symfony/Foundation/UniversalClassLoader.php';
use Symfony\Foundation\UniversalClassLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => __DIR__.'/vendor/symfony/src',
'Application' => __DIR__,
'Bundle' => __DIR__,
'Doctrine' => __DIR__.'/vendor/doctrine/lib',
));
$loader->registerPrefixes(array(
'Swift_' => __DIR__.'/vendor/swiftmailer/lib/classes',
'Zend_' => __DIR__.'/vendor/zend/library',
));
$loader->register();
require_once __DIR__.'/vendor/propel/runtime/lib/Propel.php';
set_include_path(
__DIR__.'/vendor/phing/classes'.PATH_SEPARATOR.
__DIR__.'/vendor/zend/library'.PATH_SEPARATOR.
__DIR__.'/vendor/swiftmailer/lib'.PATH_SEPARATOR.
get_include_path()
);
Known Problems Known Problems
-------------- --------------
Your application must not be un a path inclufing dots in directory names (i.e. '/Users/me/symfony/2.0/sandbox/' fails). Your application must not be in a path including dots in directory names (i.e. '/Users/me/symfony/2.0/sandbox/' fails).