# DTOGetter.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2007 by Ivan Y. Khvostishkov                            *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00012     final class DTOGetter extends PrototypedGetter
    00013     {
    00014         private $soapDto    = true;
    00015
    00016         public function __construct(EntityProto $proto, $object)
    00017         {
    00018             Assert::isInstance($object, 'DTOClass');
    00019
    00020             return parent::__construct($proto, $object);
    00021         }
    00022
    00026         public function setSoapDto($soapDto)
    00027         {
    00028             $this->soapDto = ($soapDto === true);
    00029
    00030             return $this;
    00031         }
    00032
    00033         // FIXME: isSoapDto()
    00034         public function getSoapDto()
    00035         {
    00036             return $this->soapDto;
    00037         }
    00038
    00039         public function get($name)
    00040         {
    00041             if (!isset($this->mapping[$name]))
    00042                 throw new WrongArgumentException(
    00043                     "knows nothing about property '{$name}'"
    00044                 );
    00045
    00046             $primitive = $this->mapping[$name];
    00047
    00048             $method = 'get'.ucfirst($primitive->getName());
    00049
    00050             $result = $this->object->$method();
    00051
    00052             // TODO: primitives refactoring
    00053             if (
    00054                 $result !== null
    00055                 && $this->soapDto
    00056                 && !is_array($result)
    00057                 && (
    00058                     ($primitive instanceof PrimitiveFormsList)
    00059                     || ($primitive instanceof PrimitiveEnumerationList)
    00060                     || ($primitive instanceof PrimitiveIdentifierList)
    00061                     || ($primitive instanceof PrimitiveArray)
    00062                 )
    00063             ) {
    00064                 $result = array($result);
    00065             }
    00066
    00067             return $result;
    00068         }
    00069     }
    00070 ?>