-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyAccess] Allow custom methods on property accesses #18016
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
Changes from 1 commit
af3a824
5b82237
00a26eb
e4aaac9
e46df98
5f206e6
94e6157
09707ad
d02d93a
748b894
688cbda
003efdb
dc5cacb
1a35d45
1e29523
7c6a79c
d0bd777
6b7eeff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -987,11 +987,6 @@ private function registerPropertyAccessConfiguration(array $config, ContainerBui | |
$chainLoader->replaceArgument(0, $serializerLoaders); | ||
|
||
if (isset($config['cache']) && $config['cache']) { | ||
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. It should be delayed until #17868 is merged. 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. Sure, it makes sense 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. I'm not sure #17868 will be merged before the 3.1 feature freeze. Could we skip this and work on it after the new Cache component is ready? 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. It should use the new |
||
$container->setParameter( | ||
'property_access.mapping.cache.prefix', | ||
'property_access_'.$this->getKernelRootHash($container) | ||
); | ||
|
||
$container->getDefinition('property_access.mapping.class_metadata_factory')->replaceArgument( | ||
1, new Reference($config['cache']) | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
CHANGELOG | ||
========= | ||
|
||
3.1.0 | ||
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. should be 3.2 now |
||
------ | ||
* added custom method calling for properties. | ||
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. This is unclear. 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. Ok, I'll add a more thoughtful explanation |
||
|
||
2.7.0 | ||
------ | ||
|
||
|
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ | |
|
||
namespace Symfony\Component\PropertyAccess\Mapping\Factory; | ||
|
||
use Psr\Cache\CacheItemPoolInterface; | ||
use Symfony\Component\PropertyAccess\Exception\NoSuchMetadataException; | ||
use Symfony\Component\PropertyAccess\Mapping\Cache\CacheInterface; | ||
use Symfony\Component\PropertyAccess\Mapping\ClassMetadata; | ||
use Symfony\Component\PropertyAccess\Mapping\Loader\LoaderInterface; | ||
|
||
|
@@ -62,11 +62,11 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface | |
/** | ||
* Creates a new metadata factory. | ||
* | ||
* @param LoaderInterface|null $loader The loader for configuring new metadata | ||
* @param CacheInterface|null $cache The cache for persisting metadata | ||
* between multiple PHP requests | ||
* @param LoaderInterface|null $loader The loader for configuring new metadata | ||
* @param CacheItemPoolInterface|null $cache The PSR-6 cache for persisting metadata | ||
* between multiple PHP requests | ||
*/ | ||
public function __construct(LoaderInterface $loader = null, CacheInterface $cache = null) | ||
public function __construct(LoaderInterface $loader = null, CacheItemPoolInterface $cache = null) | ||
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. The cache would be better as a decorator. 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. I just replicated the @dunglas, Do you still want me to implement the cache as a decorator? 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. 👍 for a decorator, this would make this class easier to understand. |
||
{ | ||
$this->loader = $loader; | ||
$this->cache = $cache; | ||
|
@@ -99,8 +99,11 @@ public function getMetadataFor($value) | |
return $this->loadedClasses[$class]; | ||
} | ||
|
||
if (null !== $this->cache && false !== ($this->loadedClasses[$class] = $this->cache->read($class))) { | ||
return $this->loadedClasses[$class]; | ||
if (null !== $this->cache) { | ||
$item = $this->cache->getItem($this->escapeClassName($class)); | ||
if ($item->isHit()) { | ||
return $this->loadedClasses[$class] = $item->get(); | ||
} | ||
} | ||
|
||
if (!class_exists($class) && !interface_exists($class)) { | ||
|
@@ -124,7 +127,8 @@ public function getMetadataFor($value) | |
} | ||
|
||
if (null !== $this->cache) { | ||
$this->cache->write($metadata); | ||
$item->set($metadata); | ||
$this->cache->save($item); | ||
} | ||
|
||
return $this->loadedClasses[$class] = $metadata; | ||
|
@@ -147,4 +151,16 @@ public function hasMetadataFor($value) | |
|
||
return false; | ||
} | ||
|
||
/** | ||
* Replaces backslashes by dots in a class name. | ||
* | ||
* @param string $class | ||
* | ||
* @return string | ||
*/ | ||
private function escapeClassName($class) | ||
{ | ||
return str_replace('\\', '.', $class); | ||
} | ||
} |
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.
this file autogenerates on each release ;)
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.
I had no idea 😅 Thanks for the info! I'll take it out then