use FileLocator to handle bundle's schema inheritance
This commit is contained in:
parent
2e556b5640
commit
f35a6833b5
|
@ -17,6 +17,7 @@ use Symfony\Component\Finder\Finder;
|
|||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\HttpKernel\Util\Filesystem;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
|
||||
/**
|
||||
* Wrapper for Propel commands.
|
||||
|
@ -184,14 +185,9 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
|
|||
|
||||
$base = ltrim(realpath($kernel->getRootDir().'/..'), DIRECTORY_SEPARATOR);
|
||||
|
||||
$cacheFiles = array();
|
||||
$bundleSchemas = array();
|
||||
$ignoredBundles = array();
|
||||
$finalSchemas = array();
|
||||
|
||||
foreach ($kernel->getBundles() as $bundle) {
|
||||
if (in_array($bundle->getName(), $ignoredBundles)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($dir = $bundle->getPath().'/Resources/config')) {
|
||||
$finder = new Finder();
|
||||
|
@ -200,38 +196,30 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
|
|||
if (!iterator_count($schemas)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($schemas as $schema) {
|
||||
|
||||
// In case this is a child bundle, we ignore the parent.
|
||||
if (null !== $bundle->getParent()) {
|
||||
$ignoredBundles[] = $bundle->getParent();
|
||||
$logicalName = $this->transformToLogicalName($schema, $bundle);
|
||||
$finalSchema = new \SplFileInfo($this->getFileLocator()->locate($logicalName));
|
||||
|
||||
// The parent schema has been added before.
|
||||
// Remove the deprecated schema files.
|
||||
if (!empty($bundleSchemas[$bundle->getParent()])) {
|
||||
foreach ($bundleSchemas[$bundle->getParent()] as $schemaFile) {
|
||||
$filesystem->remove($schemaFile);
|
||||
unset($cacheFiles[$schemaFile]);
|
||||
unset($this->tempSchemas[basename($schemaFile)]);
|
||||
$finalSchemas[(string)$finalSchema] = array($bundle, $finalSchema);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($finalSchemas as $schema) {
|
||||
list($bundle, $finalSchema) = $schema;
|
||||
$packagePrefix = self::getPackagePrefix($bundle, $base);
|
||||
|
||||
$bundleSchemas[$bundle->getName()] = array();
|
||||
foreach ($schemas as $schema) {
|
||||
$tempSchema = $bundle->getName().'-'.$schema->getBaseName();
|
||||
$tempSchema = $bundle->getName().'-'.$finalSchema->getBaseName();
|
||||
$this->tempSchemas[$tempSchema] = array(
|
||||
'bundle' => $bundle->getName(),
|
||||
'basename' => $schema->getBaseName(),
|
||||
'path' => $schema->getPathname(),
|
||||
'basename' => $finalSchema->getBaseName(),
|
||||
'path' => $finalSchema->getPathname(),
|
||||
);
|
||||
|
||||
$file = $cacheDir.DIRECTORY_SEPARATOR.$tempSchema;
|
||||
$filesystem->copy((string) $schema, $file, true);
|
||||
$filesystem->copy((string) $finalSchema, $file, true);
|
||||
|
||||
$cacheFiles[$file] = $file;
|
||||
$bundleSchemas[$bundle->getName()][] = $file;
|
||||
|
||||
// the package needs to be set absolute
|
||||
// besides, the automated namespace to package conversion has
|
||||
|
@ -247,7 +235,7 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
|
|||
} else {
|
||||
throw new \RuntimeException(
|
||||
sprintf('%s : Please define a `package` attribute or a `namespace` attribute for schema `%s`',
|
||||
$bundle->getName(), $schema->getBaseName())
|
||||
$bundle->getName(), $finalSchema->getBaseName())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -264,7 +252,17 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
|
|||
file_put_contents($file, $database->asXML());
|
||||
}
|
||||
}
|
||||
|
||||
private function transformToLogicalName(\SplFileInfo $schema, BundleInterface $bundle)
|
||||
{
|
||||
$schemaPath = str_replace($bundle->getPath().'/Resources/config/', '', $schema->getPathname());
|
||||
|
||||
return sprintf('@%s/Resources/config/%s', $bundle->getName(), $schemaPath);
|
||||
}
|
||||
|
||||
private function getFileLocator()
|
||||
{
|
||||
return $this->getContainer()->get('file_locator');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue