-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for non-cacheable entities on metadata level, not at runtime #1433
Merged
Ocramius
merged 11 commits into
doctrine:master
from
goetas:slc-check-to-classmetadatainfo
Jul 16, 2015
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6a428c6
Allow to retreive association cache defaults
goetas c685255
Check for non-cacheable associations directly on the class metada info
goetas 11be4fa
Do not check at runtime for non-cacheable associations
goetas f4f32a5
Annotation driver uses getAssociationCacheDefaults for SLC mapping
goetas 7d64be9
XML driver uses getAssociationCacheDefaults for SLC mapping
goetas acbda4b
YAML driver uses getAssociationCacheDefaults for SLC mapping
goetas 012367a
Removed runtime check test for non-cacheable entities
goetas 5f2922b
Test annotation driver with failing SLC mapping
goetas 4da0ee9
Test PHP driver with failing SLC mapping
goetas 32f0fef
Test XML driver with failing SLC mapping
goetas 3a7b299
PSR-2 CS improvements
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
use ReflectionClass; | ||
use Doctrine\Common\Persistence\Mapping\ClassMetadata; | ||
use Doctrine\Common\ClassLoader; | ||
use Doctrine\ORM\Cache\CacheException; | ||
|
||
/** | ||
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata | ||
|
@@ -1078,18 +1079,29 @@ public function enableCache(array $cache) | |
* @return void | ||
*/ | ||
public function enableAssociationCache($fieldName, array $cache) | ||
{ | ||
$this->associationMappings[$fieldName]['cache'] = $this->getAssociationCacheDefaults ($fieldName, $cache); | ||
} | ||
|
||
/** | ||
* @param string $fieldName | ||
* @param array $cache | ||
* | ||
* @return array | ||
*/ | ||
public function getAssociationCacheDefaults ($fieldName, array $cache) | ||
{ | ||
if ( ! isset($cache['usage'])) { | ||
$cache['usage'] = isset($this->cache['usage']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing indentation level, it should be : $cache['usage'] = isset($this->cache['usage'])
? $this->cache['usage']
: self::CACHE_USAGE_READ_ONLY; |
||
? $this->cache['usage'] | ||
: self::CACHE_USAGE_READ_ONLY; | ||
? $this->cache['usage'] | ||
: self::CACHE_USAGE_READ_ONLY; | ||
} | ||
|
||
if ( ! isset($cache['region'])) { | ||
$cache['region'] = strtolower(str_replace('\\', '_', $this->rootEntityName)) . '__' . $fieldName; | ||
} | ||
|
||
$this->associationMappings[$fieldName]['cache'] = $cache; | ||
return $cache; | ||
} | ||
|
||
/** | ||
|
@@ -1475,6 +1487,10 @@ protected function _validateAndCompleteAssociationMapping(array $mapping) | |
if ( ! $this->isIdentifierComposite && count($this->identifier) > 1) { | ||
$this->isIdentifierComposite = true; | ||
} | ||
|
||
if ($this->cache && !isset($mapping['cache'])) { | ||
throw CacheException::nonCacheableEntityAssociation($this->name, $mapping['fieldName']); | ||
} | ||
} | ||
|
||
// Mandatory attributes for both sides | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.PHPSLC.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
use Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
|
||
$metadata->enableCache(array( | ||
'usage' => ClassMetadataInfo::CACHE_USAGE_READ_ONLY | ||
)); | ||
$metadata->mapManyToOne(array( | ||
'fieldName' => 'foo', | ||
'id' => true, | ||
'targetEntity' => 'PHPSLCFoo' | ||
)); |
13 changes: 13 additions & 0 deletions
13
tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.XMLSLC.dcm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping | ||
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | ||
<entity name="Doctrine\Tests\ORM\Mapping\XMLSLC"> | ||
<cache usage="NONSTRICT_READ_WRITE" /> | ||
<id name="foo" association-key="true"/> | ||
<many-to-one field="foo" target-entity="Doctrine\Tests\ORM\Mapping\XMLSLCFoo"> | ||
<join-column name="foo_id" referenced-column-name="id" /> | ||
</many-to-one> | ||
</entity> | ||
</doctrine-mapping> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space between the function name and open parenthesis