CacheNamingStrategy.php 659 B

1234567891011121314151617181920212223242526
  1. <?php
  2. namespace JMS\SerializerBundle\Serializer\Naming;
  3. use JMS\SerializerBundle\Metadata\PropertyMetadata;
  4. class CacheNamingStrategy implements PropertyNamingStrategyInterface
  5. {
  6. private $delegate;
  7. private $cache;
  8. public function __construct(PropertyNamingStrategyInterface $delegate)
  9. {
  10. $this->delegate = $delegate;
  11. $this->cache = new \SplObjectStorage();
  12. }
  13. public function translateName(PropertyMetadata $property)
  14. {
  15. if (isset($this->cache[$property])) {
  16. return $this->cache[$property];
  17. }
  18. return $this->cache[$property] = $this->delegate->translateName($property);
  19. }
  20. }