123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace JMS\SerializerBundle\Tests\Fixtures;
- use JMS\SerializerBundle\Annotation\Exclude;
- use JMS\SerializerBundle\Annotation\PreSerialize;
- use JMS\SerializerBundle\Annotation\PostDeserialize;
- use JMS\SerializerBundle\Annotation\Type;
- class ObjectWithLifecycleCallbacks
- {
- /**
- * @Exclude
- */
- private $firstname;
- /**
- * @Exclude
- */
- private $lastname;
- /**
- * @Type("string")
- */
- private $name;
- public function __construct($firstname = 'Foo', $lastname = 'Bar')
- {
- $this->firstname = $firstname;
- $this->lastname = $lastname;
- }
- /**
- * @PreSerialize
- */
- private function prepareForSerialization()
- {
- $this->name = $this->firstname.' '.$this->lastname;
- }
- /**
- * @PostDeserialize
- */
- private function afterDeserialization()
- {
- list($this->firstname, $this->lastname) = explode(' ', $this->name);
- }
- }
|