1<?php 2 3declare(strict_types=1); 4 5namespace JMS\Serializer\Expression; 6 7use Symfony\Component\ExpressionLanguage\ParsedExpression as BaseExpression; 8use Symfony\Component\ExpressionLanguage\SerializedParsedExpression; 9 10/** 11 * @author Asmir Mustafic <goetas@gmail.com> 12 */ 13class Expression implements \Serializable 14{ 15 /** 16 * @var BaseExpression 17 */ 18 private $expression; 19 20 public function __construct(BaseExpression $expression) 21 { 22 $this->expression = $expression; 23 } 24 25 public function getExpression(): BaseExpression 26 { 27 return $this->expression; 28 } 29 30 /** 31 * @return string 32 * 33 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint 34 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation 35 */ 36 public function __toString() 37 { 38 return (string) $this->expression; 39 } 40 41 /** 42 * @return string 43 * 44 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint 45 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint 46 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation 47 */ 48 public function serialize() 49 { 50 return serialize([(string) $this->expression, serialize($this->expression->getNodes())]); 51 } 52 53 /** 54 * @param string $str 55 * 56 * @return void 57 * 58 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint 59 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint 60 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation 61 */ 62 public function unserialize($str): void 63 { 64 $this->expression = new SerializedParsedExpression(...unserialize($str)); 65 } 66} 67