123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- /*
- * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- namespace JMS\SerializerBundle\Metadata;
- use JMS\SerializerBundle\Exception\InvalidArgumentException;
- use Metadata\MergeableInterface;
- use Metadata\MethodMetadata;
- use Metadata\MergeableClassMetadata;
- class ClassMetadata extends MergeableClassMetadata
- {
- public $preSerializeMethods = array();
- public $postSerializeMethods = array();
- public $postDeserializeMethods = array();
- public $xmlRootName;
- public function addPreSerializeMethod(MethodMetadata $method)
- {
- $this->preSerializeMethods[] = $method;
- }
- public function addPostSerializeMethod(MethodMetadata $method)
- {
- $this->postSerializeMethods[] = $method;
- }
- public function addPostDeserializeMethod(MethodMetadata $method)
- {
- $this->postDeserializeMethods[] = $method;
- }
- public function merge(MergeableInterface $object)
- {
- if (!$object instanceof ClassMetadata) {
- throw new InvalidArgumentException('$object must be an instance of ClassMetadata.');
- }
- parent::merge($object);
- $this->preSerializeMethods = array_merge($this->preSerializeMethods, $object->preSerializeMethods);
- $this->postSerializeMethods = array_merge($this->postSerializeMethods, $object->postSerializeMethods);
- $this->postDeserializeMethods = array_merge($this->postDeserializeMethods, $object->postDeserializeMethods);
- $this->xmlRootName = $object->xmlRootName;
- }
- public function serialize()
- {
- return serialize(array(
- $this->preSerializeMethods,
- $this->postSerializeMethods,
- $this->postDeserializeMethods,
- $this->xmlRootName,
- parent::serialize(),
- ));
- }
- public function unserialize($str)
- {
- list(
- $this->preSerializeMethods,
- $this->postSerializeMethods,
- $this->postDeserializeMethods,
- $this->xmlRootName,
- $parentStr
- ) = unserialize($str);
- parent::unserialize($parentStr);
- }
- }
|