1<?php
2
3/*
4	Phoronix Test Suite
5	URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
6	Copyright (C) 2009 - 2018, Phoronix Media
7	Copyright (C) 2009 - 2018, Michael Larabel
8
9	This program is free software; you can redistribute it and/or modify
10	it under the terms of the GNU General Public License as published by
11	the Free Software Foundation; either version 3 of the License, or
12	(at your option) any later version.
13
14	This program is distributed in the hope that it will be useful,
15	but WITHOUT ANY WARRANTY; without even the implied warranty of
16	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17	GNU General Public License for more details.
18
19	You should have received a copy of the GNU General Public License
20	along with this program. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23class pts_argument_check
24{
25	private $argument_index;
26	private $function_check;
27	private $function_return_key;
28
29	public function __construct($index, $function, $return_key = null)
30	{
31		$this->argument_index = $index;
32		$this->function_check = $function;
33		$this->function_return_key = $return_key; // set to null when you don't want it to be set
34	}
35	public function get_argument_index()
36	{
37		return $this->argument_index;
38	}
39	public function get_function_check()
40	{
41		return $this->function_check;
42	}
43	public function get_function_return_key()
44	{
45		return $this->function_return_key;
46	}
47	public function get_function_check_type()
48	{
49		if($this->get_function_check() == array('pts_types', 'is_result_file'))
50		{
51			$type = 'Test Result';
52		}
53		else if($this->get_function_check() == array('pts_types', 'identifier_to_object'))
54		{
55			$type = 'Test | Suite | OpenBenchmarking ID | Test Result';
56		}
57		else if($this->get_function_check() == array('pts_types', 'is_test_or_suite'))
58		{
59			$type = 'Test | Suite';
60		}
61		else if($this->get_function_check() == array('pts_test_profile', 'is_test_profile'))
62		{
63			$type = 'Test';
64		}
65		else if($this->get_function_check() == array('pts_test_suite', 'is_suite'))
66		{
67			$type = 'Suite';
68		}
69		else if($this->get_function_check() == array('pts_openbenchmarking', 'is_openbenchmarking_result_id'))
70		{
71			$type = 'OpenBenchmarking ID';
72		}
73		else if($this->get_function_check() == array('pts_results', 'is_saved_result_file'))
74		{
75			$type = 'Test Result';
76		}
77		else if($this->get_function_check() == array('pts_module', 'is_module'))
78		{
79			$type = 'Phoronix Test Suite Module';
80		}
81		else if($this->get_function_check() == 'is_file')
82		{
83			$type = 'File';
84		}
85		else
86		{
87			$type = 'Unknown Object';
88		}
89		return $type;
90	}
91	public function __toString()
92	{
93		$type = $this->get_function_check_type();
94
95		$type = '[' . $type . ']' . (($this->get_argument_index() === 'VARIABLE_LENGTH') ? '  ...' : null);
96
97		return $type;
98	}
99	protected static function available_tests()
100	{
101		$ob_tests = pts_openbenchmarking::available_tests(false);
102		$base_tests = array();
103
104		foreach($ob_tests as $t)
105		{
106			$base_tests[] = substr($t, strpos($t, '/') + 1);
107		}
108
109		return array_merge($base_tests, $ob_tests);
110	}
111	public function possible_values()
112	{
113		$possible_values = array();
114
115		if($this->get_function_check() == array('pts_types', 'is_result_file'))
116		{
117			$possible_values = pts_results::saved_test_results();
118		}
119		else if($this->get_function_check() == array('pts_types', 'identifier_to_object'))
120		{
121			$possible_values = array_merge(self::available_tests(), pts_results::saved_test_results(), pts_test_suites::all_suites(), array_keys(pts_openbenchmarking::result_uploads_from_this_ip()));
122		}
123		else if($this->get_function_check() == array('pts_types', 'is_test_or_suite'))
124		{
125			$possible_values = array_merge(self::available_tests(), pts_test_suites::all_suites());
126		}
127		else if($this->get_function_check() == array('pts_test_profile', 'is_test_profile'))
128		{
129			$possible_values = self::available_tests();
130		}
131		else if($this->get_function_check() == array('pts_test_suite', 'is_suite'))
132		{
133			$possible_values = pts_test_suites::all_suites();
134		}
135		else if($this->get_function_check() == array('pts_openbenchmarking', 'is_openbenchmarking_result_id'))
136		{
137			$possible_values = array_keys(pts_openbenchmarking::result_uploads_from_this_ip());
138		}
139		else if($this->get_function_check() == array('pts_results', 'is_saved_result_file'))
140		{
141			$possible_values = pts_results::saved_test_results();
142		}
143		else if($this->get_function_check() == array('pts_module', 'is_module'))
144		{
145			$possible_values = pts_module_manager::available_modules();
146		}
147
148		return $possible_values;
149	}
150}
151
152?>
153