1<?php 2 3declare(strict_types=1); 4 5namespace JMS\Serializer\Metadata; 6 7use JMS\Serializer\Expression\Expression; 8 9/** 10 * @Annotation 11 * @Target("METHOD") 12 * 13 * @author Asmir Mustafic <goetas@gmail.com> 14 */ 15class ExpressionPropertyMetadata extends PropertyMetadata 16{ 17 /** 18 * @var string|Expression 19 */ 20 public $expression; 21 22 /** 23 * @param string|Expression $expression 24 */ 25 public function __construct(string $class, string $fieldName, $expression) 26 { 27 $this->class = $class; 28 $this->name = $fieldName; 29 $this->expression = $expression; 30 $this->readOnly = true; 31 } 32 33 public function setAccessor(string $type, ?string $getter = null, ?string $setter = null): void 34 { 35 } 36 37 /** 38 * {@inheritdoc} 39 */ 40 public function serialize() 41 { 42 return serialize([ 43 $this->expression, 44 parent::serialize(), 45 ]); 46 } 47 48 /** 49 * {@inheritdoc} 50 */ 51 public function unserialize($str) 52 { 53 $parentStr = $this->unserializeProperties($str); 54 [$this->class, $this->name] = unserialize($parentStr); 55 } 56 57 protected function unserializeProperties(string $str): string 58 { 59 [ 60 $this->expression, 61 $parentStr, 62 ] = unserialize($str); 63 return parent::unserializeProperties($parentStr); 64 } 65} 66