This file is indexed.

/usr/share/php/ApiGen/Configuration/ConfigurationOptionsResolver.php is in php-apigen 4.1.2-1ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php

/**
 * This file is part of the ApiGen (http://apigen.org)
 *
 * For the full copyright and license information, please view
 * the file license.md that was distributed with this source code.
 */

namespace ApiGen\Configuration;

use ApiGen\Configuration\ConfigurationOptions as CO;
use ApiGen\Configuration\Exceptions\ConfigurationException;
use ApiGen\Configuration\Theme\ThemeConfigFactory;
use ApiGen\FileSystem\FileSystem;
use ApiGen\Theme\ThemeConfigPathResolver;
use ReflectionProperty;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;


class ConfigurationOptionsResolver
{

	const AL_PROTECTED = 'protected';
	const AL_PRIVATE = 'private';
	const AL_PUBLIC = 'public';
	const TEMPLATE_THEME_DEFAULT = 'default';
	const TEMPLATE_THEME_BOOTSTRAP = 'bootstrap';

	/**
	 * @var array
	 */
	private $defaults = [
		CO::ANNOTATION_GROUPS => [],
		CO::ACCESS_LEVELS => [],
		CO::BASE_URL => '',
		CO::CONFIG => '',
		CO::DEBUG => FALSE,
		CO::DEPRECATED => FALSE,
		CO::DESTINATION => NULL,
		CO::DOWNLOAD => FALSE,
		CO::EXCLUDE => [],
		CO::EXTENSIONS => [],
		CO::GOOGLE_CSE_ID => '',
		CO::GOOGLE_ANALYTICS => '',
		CO::GROUPS => '',
		CO::CHARSET => [],
		CO::MAIN => '',
		CO::INTERNAL => FALSE,
		CO::PHP => FALSE,
		CO::SKIP_DOC_PATH => [],
		CO::SOURCE => [],
		CO::NO_SOURCE_CODE => FALSE,
		CO::TEMPLATE => NULL,
		CO::TEMPLATE_CONFIG => NULL,
		CO::TEMPLATE_THEME => self::TEMPLATE_THEME_DEFAULT,
		CO::TITLE => '',
		CO::TODO => FALSE,
		CO::TREE => TRUE,
		// helpers
		CO::VISIBILITY_LEVELS => [],
		CO::SOURCE_CODE => ''
	];

	/**
	 * @var ThemeConfigFactory
	 */
	private $themeConfigFactory;

	/**
	 * @var OptionsResolver
	 */
	private $resolver;

	/**
	 * @var OptionsResolverFactory
	 */
	private $optionsResolverFactory;

	/**
	 * @var ThemeConfigPathResolver
	 */
	private $themeConfigPathResolver;


	public function __construct(
		ThemeConfigFactory $themeConfigFactory,
		OptionsResolverFactory $optionsResolverFactory,
		ThemeConfigPathResolver $themeConfigPathResolver
	) {
		$this->themeConfigFactory = $themeConfigFactory;
		$this->optionsResolverFactory = $optionsResolverFactory;
		$this->themeConfigPathResolver = $themeConfigPathResolver;
	}


	/**
	 * @return array
	 */
	public function resolve(array $options)
	{
		$this->resolver = $this->optionsResolverFactory->create();
		$this->setDefaults();
		$this->setRequired();
		$this->setAllowedValues();
		$this->setNormalizers();
		return $this->resolver->resolve($options);
	}


	private function setDefaults()
	{
		$this->resolver->setDefaults($this->defaults);
		$this->resolver->setDefaults([
			CO::VISIBILITY_LEVELS => function (Options $options) {
				return $this->getAccessLevelForReflections($options[CO::ACCESS_LEVELS]);
			},
			CO::TEMPLATE => function (Options $options) {
				if ( ! $options[CO::TEMPLATE_CONFIG]) {
					$config = $this->getTemplateConfigPathFromTheme($options[CO::TEMPLATE_THEME]);

				} else {
					$config = $options[CO::TEMPLATE_CONFIG];
				}
				return $this->themeConfigFactory->create($config)->getOptions();
			}
		]);
	}


	/**
	 * @return int
	 */
	private function getAccessLevelForReflections(array $options)
	{
		$accessLevel = NULL;
		if (in_array(self::AL_PUBLIC, $options)) {
			$accessLevel |= ReflectionProperty::IS_PUBLIC;
		}

		if (in_array(self::AL_PROTECTED, $options)) {
			$accessLevel |= ReflectionProperty::IS_PROTECTED;
		}

		if (in_array(self::AL_PRIVATE, $options)) {
			$accessLevel |= ReflectionProperty::IS_PRIVATE;
		}

		return $accessLevel;
	}


	private function setRequired()
	{
		$this->resolver->setRequired([
			CO::SOURCE,
			CO::DESTINATION
		]);
	}


	private function setAllowedValues()
	{
		$this->resolver->addAllowedValues(CO::DESTINATION, function ($destination) {
			return $this->allowedValuesForDestination($destination);
		});

		$this->resolver->addAllowedValues(CO::SOURCE, function ($source) {
			return $this->allowedValuesForSource($source);
		});

		$this->resolver->addAllowedValues(CO::TEMPLATE_CONFIG, function ($value) {
			if ($value && ! is_file($value)) {
				throw new ConfigurationException("Template config '$value' was not found");
			}
			return TRUE;
		});
	}


	private function setNormalizers()
	{
		$this->resolver->setNormalizers([
			CO::ANNOTATION_GROUPS => function (Options $options, $value) {
				$value = (array) $value;
				if ($options[CO::DEPRECATED]) {
					$value[] = CO::DEPRECATED;
				}
				if ($options[CO::TODO]) {
					$value[] = CO::TODO;
				}
				return array_unique($value);
			},
			CO::DESTINATION => function (Options $options, $value) {
				return FileSystem::getAbsolutePath($value);
			},
			CO::BASE_URL => function (Options $options, $value) {
				return rtrim($value, '/');
			},
			CO::SKIP_DOC_PATH => function (Options $options, $value) {
				$value = (array) $value;
				foreach ($value as $key => $source) {
					$value[$key] = FileSystem::getAbsolutePath($source);
				}
				return $value;
			},
			CO::SOURCE => function (Options $options, $value) {
				if ( ! is_array($value)) {
					$value = [$value];
				}
				foreach ($value as $key => $source) {
					$value[$key] = FileSystem::getAbsolutePath($source);
				}
				return $value;
			},
			CO::SOURCE_CODE => function (Options $options) {
				return ! $options[CO::NO_SOURCE_CODE];
			},
			CO::TEMPLATE_CONFIG => function (Options $options, $value) {
				return FileSystem::getAbsolutePath($value);
			}
		]);
	}


	/**
	 * @param string $theme
	 * @return string
	 */
	private function getTemplateConfigPathFromTheme($theme)
	{
		if ($theme === self::TEMPLATE_THEME_DEFAULT) {
			return $this->themeConfigPathResolver->resolve('/theme-default/config.neon');

		} elseif ($theme === self::TEMPLATE_THEME_BOOTSTRAP) {
			return $this->themeConfigPathResolver->resolve('/theme-bootstrap/config.neon');
		}

		throw new ConfigurationException(CO::TEMPLATE_THEME . ' ' . $theme . ' is not supported.');
	}


	/**
	 * @param string $destination
	 * @return bool
	 */
	private function allowedValuesForDestination($destination)
	{
		if ( ! $destination) {
			throw new ConfigurationException("Destination is not set. Use '-d <dir>' or config to set it");

		} elseif ( ! is_dir($destination)) {
			mkdir($destination, 0755, TRUE);
		}

		if ( ! is_writable($destination)) {
			throw new ConfigurationException("Destination '$destination' is not writable");
		}
		return TRUE;
	}


	/**
	 * @param string|array $source
	 * @return bool
	 */
	private function allowedValuesForSource($source)
	{
		if ( ! $source) {
			throw new ConfigurationException("Source is not set. Use '-s <dir>' or config to set it");

		} elseif ( ! is_array($source)) {
			$source = [$source];
		}

		foreach ($source as $singleSource) {
			if ( ! file_exists($singleSource)) {
				throw new ConfigurationException("Source '$singleSource' does not exist");
			}
		}
		return TRUE;
	}

}