Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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