Merge pull request #76 from havvg/schema-bundle-inheritance
schema bundle inheritance
This commit is contained in:
commit
2e556b5640
|
@ -184,17 +184,41 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
|
|||
|
||||
$base = ltrim(realpath($kernel->getRootDir().'/..'), DIRECTORY_SEPARATOR);
|
||||
|
||||
$cacheFiles = array();
|
||||
$bundleSchemas = array();
|
||||
$ignoredBundles = array();
|
||||
|
||||
foreach ($kernel->getBundles() as $bundle) {
|
||||
if (in_array($bundle->getName(), $ignoredBundles)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($dir = $bundle->getPath().'/Resources/config')) {
|
||||
$finder = new Finder();
|
||||
$schemas = $finder->files()->name('*schema.xml')->followLinks()->in($dir);
|
||||
|
||||
if (empty($schemas)) {
|
||||
if (!iterator_count($schemas)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// In case this is a child bundle, we ignore the parent.
|
||||
if (null !== $bundle->getParent()) {
|
||||
$ignoredBundles[] = $bundle->getParent();
|
||||
|
||||
// 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)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$packagePrefix = self::getPackagePrefix($bundle, $base);
|
||||
|
||||
$bundleSchemas[$bundle->getName()] = array();
|
||||
foreach ($schemas as $schema) {
|
||||
$tempSchema = $bundle->getName().'-'.$schema->getBaseName();
|
||||
$this->tempSchemas[$tempSchema] = array(
|
||||
|
@ -206,6 +230,9 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
|
|||
$file = $cacheDir.DIRECTORY_SEPARATOR.$tempSchema;
|
||||
$filesystem->copy((string) $schema, $file, true);
|
||||
|
||||
$cacheFiles[$file] = $file;
|
||||
$bundleSchemas[$bundle->getName()][] = $file;
|
||||
|
||||
// the package needs to be set absolute
|
||||
// besides, the automated namespace to package conversion has
|
||||
// not taken place yet so it needs to be done manually
|
||||
|
|
|
@ -16,6 +16,7 @@ Currently supports:
|
|||
* Integration with the Form component.
|
||||
* Integration with the Security component.
|
||||
* Propel ParamConverter can be used with Sensio Framework Extra Bundle.
|
||||
* Schema Inheritance
|
||||
|
||||
## Installation ##
|
||||
|
||||
|
@ -385,3 +386,15 @@ BundleNamespace\Model\User:
|
|||
|
||||
As many validator of this type as you want can be used.
|
||||
|
||||
## Bundle Inheritance ##
|
||||
|
||||
The `PropelBundle` makes use of the bundle inheritance.
|
||||
Currently only schema inheritance is provided.
|
||||
|
||||
### Schema Inheritance ###
|
||||
|
||||
You can override the defined schema of a bundle from within its child bundle.
|
||||
The child's schema will *completely* override the parent's one.
|
||||
To make use of the inheritance you only need to drop a schema file in the `Resources/config` folder of the child bundle.
|
||||
|
||||
**IMPORTANT**: If there is *at least one* schema file in the child bundle, *none* of the parent's schema files will be used.
|
||||
|
|
Loading…
Reference in a new issue