stacktemplate.class.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * Copyright 2010-2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. /*%******************************************************************************************%*/
  17. // CLASS
  18. /**
  19. * Simplifies the process of preparing JSON stack templates.
  20. *
  21. * @version 2011.02.03
  22. * @license See the included NOTICE.md file for more information.
  23. * @copyright See the included NOTICE.md file for more information.
  24. * @link http://aws.amazon.com/php/ PHP Developer Center
  25. */
  26. class CFStackTemplate
  27. {
  28. /**
  29. * Removes whitespace from a JSON template.
  30. *
  31. * @param string $template (Required) A JSON representation of the stack template. Must have <a href="http://docs.php.net/manual/en/function.json-decode.php#refsect1-function.json-decode-examples">strict JSON-specific formatting</a>.
  32. * @return string A JSON representation of the template.
  33. */
  34. public static function json($template)
  35. {
  36. return json_encode(json_decode($template, true));
  37. }
  38. /**
  39. * Converts an associative array (map) of the template into a JSON string.
  40. *
  41. * @param array $template (Required) An associative array that maps directly to its JSON counterpart.
  42. * @return string A JSON representation of the template.
  43. */
  44. public static function map($template)
  45. {
  46. return json_encode($template);
  47. }
  48. }