stepconfig.class.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * Contains functionality for simplifying Amazon EMR Hadoop steps.
  20. *
  21. * @version 2010.11.16
  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 CFStepConfig
  27. {
  28. /**
  29. * Stores the configuration map.
  30. */
  31. public $config;
  32. /**
  33. * Constructs a new instance of this class.
  34. *
  35. * @param array $config (Required) An associative array representing the Hadoop step configuration.
  36. * @return $this A reference to the current instance.
  37. */
  38. public function __construct($config)
  39. {
  40. // Handle Hadoop jar arguments
  41. if (isset($config['HadoopJarStep']['Args']) && $args = $config['HadoopJarStep']['Args'])
  42. {
  43. $config['HadoopJarStep']['Args'] = is_array($args) ? $args : array($args);
  44. }
  45. $this->config = $config;
  46. }
  47. /**
  48. * Constructs a new instance of this class, and allows chaining.
  49. *
  50. * @param array $config (Required) An associative array representing the Hadoop step configuration.
  51. * @return $this A reference to the current instance.
  52. */
  53. public static function init($config)
  54. {
  55. if (version_compare(PHP_VERSION, '5.3.0', '<'))
  56. {
  57. throw new Exception('PHP 5.3 or newer is required to instantiate a new class with CLASS::init().');
  58. }
  59. $self = get_called_class();
  60. return new $self($config);
  61. }
  62. /**
  63. * Returns a JSON representation of the object when typecast as a string.
  64. *
  65. * @return string A JSON representation of the object.
  66. * @link http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring PHP Magic Methods
  67. */
  68. public function __toString()
  69. {
  70. return json_encode($this->config);
  71. }
  72. /**
  73. * Returns the configuration data.
  74. *
  75. * @return array The configuration data.
  76. */
  77. public function get_config()
  78. {
  79. return $this->config;
  80. }
  81. }