wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.Formatter.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.Formatter.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/util/class.ObjectFactory.php");
20 
21 /**
22  * @class Formatter
23  * @ingroup Format
24  * @brief Formatter is is the single entry point for request/response formatting.
25  * It chooses the configured formatter based on the format property of the message
26  * by getting the value XXXFormat from the configuration section 'implementation'.
27  *
28  * @author ingo herwig <ingo@wemove.com>
29  */
30 class Formatter
31 {
32  /**
33  * Deserialize Request data into objects.
34  * @note UTF-8 encoded request data is decoded automatically
35  * @param request A reference to the Request instance
36  */
37  function deserialize(&$request)
38  {
39  // get the formatter that should be used for this request format
40  $format = $request->getFormat();
41  if ($format == null || strlen($format) == 0)
42  {
43  // default to html (POST/GET variables) format
44  $format = MSG_FORMAT_HTML;
45  }
46  $objectFactory = &ObjectFactory::getInstance();
47  $formatter = &$objectFactory->createInstanceFromConfig('implementation', $format.'Format');
48  if ($formatter === null)
49  WCMFException::throwEx($objectFactory->getErrorMsg()."\nRequest: ".$request->toString(), __FILE__, __LINE__);
50 
51  $formatter->deserialize($request);
52  }
53  /**
54  * Serialize Response according to the output format.
55  * @param response A reference to the Response instance
56  */
57  function serialize(&$response)
58  {
59  // get the formatter that should be used for this response format
60  $format = $response->getFormat();
61  if ($format == null)
62  {
63  // the response format must be given!
64  WCMFException::throwEx("No response format defined for ".$response->toString(), __FILE__, __LINE__);
65  }
66  $objectFactory = &ObjectFactory::getInstance();
67  $formatter = &$objectFactory->createInstanceFromConfig('implementation', $format.'Format');
68  if ($formatter === null)
69  WCMFException::throwEx($objectFactory->getErrorMsg()."\nResponse: ".$response->toString(), __FILE__, __LINE__);
70  $formatter->serialize($response);
71  }
72 }
73 ?>
Formatter is is the single entry point for request/response formatting. It chooses the configured for...
throwEx($message, $file='', $line='')
serialize(&$response)
const MSG_FORMAT_HTML
deserialize(&$request)