Fixed #DDC-597
Added a test on public properties in entities. I did not check whether these properties are actually mapped to a column because personally, I believe that within an entity, there should only be protected / private members. Signed-off-by: David Abdemoulaie <dave@hobodave.com>
This commit is contained in:
parent
aafb278aa2
commit
773f56bef2
@ -55,12 +55,13 @@ class SchemaValidator
|
|||||||
/**
|
/**
|
||||||
* Checks the internal consistency of mapping files.
|
* Checks the internal consistency of mapping files.
|
||||||
*
|
*
|
||||||
* There are several checks that can't be done at runtime or are to expensive, which can be verified
|
* There are several checks that can't be done at runtime or are too expensive, which can be verified
|
||||||
* with this command. For example:
|
* with this command. For example:
|
||||||
*
|
*
|
||||||
* 1. Check if a relation with "mappedBy" is actually connected to that specified field.
|
* 1. Check if a relation with "mappedBy" is actually connected to that specified field.
|
||||||
* 2. Check if "mappedBy" and "inversedBy" are consistent to each other.
|
* 2. Check if "mappedBy" and "inversedBy" are consistent to each other.
|
||||||
* 3. Check if "referencedColumnName" attributes are really pointing to primary key columns.
|
* 3. Check if "referencedColumnName" attributes are really pointing to primary key columns.
|
||||||
|
* 4. Check if there are public properties that might cause problems with lazy loading.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -71,9 +72,9 @@ class SchemaValidator
|
|||||||
$classes = $cmf->getAllMetadata();
|
$classes = $cmf->getAllMetadata();
|
||||||
|
|
||||||
foreach ($classes AS $class) {
|
foreach ($classes AS $class) {
|
||||||
|
$ce = array();
|
||||||
/* @var $class ClassMetadata */
|
/* @var $class ClassMetadata */
|
||||||
foreach ($class->associationMappings AS $fieldName => $assoc) {
|
foreach ($class->associationMappings AS $fieldName => $assoc) {
|
||||||
$ce = array();
|
|
||||||
if (!$cmf->hasMetadataFor($assoc->targetEntityName)) {
|
if (!$cmf->hasMetadataFor($assoc->targetEntityName)) {
|
||||||
$ce[] = "The target entity '" . $assoc->targetEntityName . "' specified on " . $class->name . '#' . $fieldName . ' is unknown.';
|
$ce[] = "The target entity '" . $assoc->targetEntityName . "' specified on " . $class->name . '#' . $fieldName . ' is unknown.';
|
||||||
}
|
}
|
||||||
@ -171,12 +172,18 @@ class SchemaValidator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($class->reflClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $publicAttr) {
|
||||||
|
$ce[] = "Attribute '".$publicAttr->getName()."' in class '".$class->name."' is marked as public. Make sure you initialize your entities manually"
|
||||||
|
." before accessing these properties or you will experience strange behaviour as using public properties will disallow Doctrine to use lazy loading. The Doctrine Team strongly"
|
||||||
|
." recommends using protected / private properties on entities only. See the manual for more detailed information.";
|
||||||
|
}
|
||||||
|
|
||||||
if ($ce) {
|
if ($ce) {
|
||||||
$errors[$class->name] = $ce;
|
$errors[$class->name] = $ce;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user