Complex classes like GeneratorOptions often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GeneratorOptions, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | class GeneratorOptions extends AbstractYamlReader implements \JsonSerializable |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Common values used as option's value |
||
| 9 | */ |
||
| 10 | const VALUE_CAT = 'cat'; |
||
| 11 | const VALUE_END = 'end'; |
||
| 12 | const VALUE_FALSE = false; |
||
| 13 | const VALUE_NONE = 'none'; |
||
| 14 | const VALUE_START = 'start'; |
||
| 15 | const VALUE_TRUE = true; |
||
| 16 | /** |
||
| 17 | * Possible option keys |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | const ADD_COMMENTS = 'add_comments'; |
||
| 21 | const ARRAYS_FOLDER = 'arrays_folder'; |
||
| 22 | const BASIC_LOGIN = 'basic_login'; |
||
| 23 | const BASIC_PASSWORD = 'basic_password'; |
||
| 24 | const CATEGORY = 'category'; |
||
| 25 | const COMPOSER_NAME = 'composer_name'; |
||
| 26 | const COMPOSER_SETTINGS = 'composer_settings'; |
||
| 27 | const DESTINATION = 'destination'; |
||
| 28 | const ENUMS_FOLDER = 'enums_folder'; |
||
| 29 | const GATHER_METHODS = 'gather_methods'; |
||
| 30 | const GENERATE_TUTORIAL_FILE = 'generate_tutorial_file'; |
||
| 31 | const GENERIC_CONSTANTS_NAME = 'generic_constants_names'; |
||
| 32 | const NAMESPACE_PREFIX = 'namespace_prefix'; |
||
| 33 | const ORIGIN = 'origin'; |
||
| 34 | const PREFIX = 'prefix'; |
||
| 35 | const PROXY_HOST = 'proxy_host'; |
||
| 36 | const PROXY_LOGIN = 'proxy_login'; |
||
| 37 | const PROXY_PASSWORD = 'proxy_password'; |
||
| 38 | const PROXY_PORT = 'proxy_port'; |
||
| 39 | const SERVICES_FOLDER = 'services_folder'; |
||
| 40 | const SOAP_CLIENT_CLASS = 'soap_client_class'; |
||
| 41 | const SOAP_OPTIONS = 'soap_options'; |
||
| 42 | const SRC_DIRNAME = 'src_dirname'; |
||
| 43 | const STANDALONE = 'standalone'; |
||
| 44 | const STRUCT_ARRAY_CLASS = 'struct_array_class'; |
||
| 45 | const STRUCT_CLASS = 'struct_class'; |
||
| 46 | const STRUCTS_FOLDER = 'structs_folder'; |
||
| 47 | const SUFFIX = 'suffix'; |
||
| 48 | const VALIDATION = 'validation'; |
||
| 49 | const SCHEMAS_SAVE = 'schemas_save'; |
||
| 50 | const SCHEMAS_FOLDER = 'schemas_folder'; |
||
| 51 | /** |
||
| 52 | * Generator's options |
||
| 53 | * @var array |
||
| 54 | */ |
||
| 55 | protected $options; |
||
| 56 | /** |
||
| 57 | * @param string $filename |
||
| 58 | */ |
||
| 59 | 50 | protected function __construct($filename) |
|
| 64 | /** |
||
| 65 | * Parse options for generator |
||
| 66 | * @param string $filename options's file to parse |
||
| 67 | * @return GeneratorOptions |
||
| 68 | */ |
||
| 69 | 50 | protected function parseOptions($filename) |
|
| 79 | /** |
||
| 80 | * Returns the option value |
||
| 81 | * @throws \InvalidArgumentException |
||
| 82 | * @param string $optionName |
||
| 83 | * @return mixed |
||
| 84 | */ |
||
| 85 | 1495 | public function getOptionValue($optionName) |
|
| 92 | /** |
||
| 93 | * Allows to add an option and set its value |
||
| 94 | * @throws \InvalidArgumentException |
||
| 95 | * @param string $optionName |
||
| 96 | * @param mixed $optionValue |
||
| 97 | * @param array $values |
||
| 98 | * @return GeneratorOptions |
||
| 99 | */ |
||
| 100 | 1150 | public function setOptionValue($optionName, $optionValue, array $values = []) |
|
| 101 | { |
||
| 102 | 1150 | if (!isset($this->options[$optionName])) { |
|
| 103 | 10 | $this->options[$optionName] = [ |
|
| 104 | 10 | 'value' => $optionValue, |
|
| 105 | 10 | 'values' => $values, |
|
| 106 | ]; |
||
| 107 | 1147 | } elseif (!empty($this->options[$optionName]['values']) && !in_array($optionValue, $this->options[$optionName]['values'], true)) { |
|
| 108 | 10 | throw new \InvalidArgumentException(sprintf('Invalid value "%s" for option "%s", possible values: %s', $optionValue, $optionName, implode(', ', $this->options[$optionName]['values'])), __LINE__); |
|
| 109 | } else { |
||
| 110 | 1135 | $this->options[$optionName]['value'] = $optionValue; |
|
| 111 | } |
||
| 112 | 1140 | return $this; |
|
| 113 | } |
||
| 114 | /** |
||
| 115 | * @throws \InvalidArgumentException |
||
| 116 | * @param string $filename options's file to parse |
||
| 117 | * @return GeneratorOptions |
||
| 118 | */ |
||
| 119 | 1135 | public static function instance($filename = null) |
|
| 120 | { |
||
| 121 | 1135 | return parent::instance(empty($filename) ? self::getDefaultConfigurationPath() : $filename); |
|
| 122 | } |
||
| 123 | /** |
||
| 124 | * @return string |
||
| 125 | */ |
||
| 126 | 460 | public static function getDefaultConfigurationPath() |
|
| 127 | { |
||
| 128 | 460 | return __DIR__ . '/../resources/config/generator_options.yml'; |
|
| 129 | } |
||
| 130 | /** |
||
| 131 | * Get category option value |
||
| 132 | * @return string |
||
| 133 | */ |
||
| 134 | 410 | public function getCategory() |
|
| 135 | { |
||
| 136 | 410 | return $this->getOptionValue(self::CATEGORY); |
|
| 137 | } |
||
| 138 | /** |
||
| 139 | * Set current category option value |
||
| 140 | * @throws \InvalidArgumentException |
||
| 141 | * @param string $category |
||
| 142 | * @return GeneratorOptions |
||
| 143 | */ |
||
| 144 | 45 | public function setCategory($category) |
|
| 145 | { |
||
| 146 | 45 | return $this->setOptionValue(self::CATEGORY, $category); |
|
| 147 | } |
||
| 148 | /** |
||
| 149 | * Get add comments option value |
||
| 150 | * @return array |
||
| 151 | */ |
||
| 152 | 305 | public function getAddComments() |
|
| 153 | { |
||
| 154 | 305 | return $this->getOptionValue(self::ADD_COMMENTS); |
|
| 155 | } |
||
| 156 | /** |
||
| 157 | * Set current add comments option value |
||
| 158 | * @throws \InvalidArgumentException |
||
| 159 | * @param array $addComments |
||
| 160 | * @return GeneratorOptions |
||
| 161 | */ |
||
| 162 | 95 | public function setAddComments(array $addComments = []) |
|
| 163 | { |
||
| 164 | /** |
||
| 165 | * If array is type array("author:john Doe","Release:1",) |
||
| 166 | */ |
||
| 167 | 95 | $comments = []; |
|
| 168 | 95 | foreach ($addComments as $index => $value) { |
|
| 169 | 20 | if (is_numeric($index) && strpos($value, ':') > 0) { |
|
| 170 | 5 | list($tag, $val) = explode(':', $value); |
|
| 171 | 5 | $comments[$tag] = $val; |
|
| 172 | 2 | } else { |
|
| 173 | 18 | $comments[$index] = $value; |
|
| 174 | } |
||
| 175 | 38 | } |
|
| 176 | 95 | return $this->setOptionValue(self::ADD_COMMENTS, $comments); |
|
| 177 | } |
||
| 178 | /** |
||
| 179 | * Get gather methods option value |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | 420 | public function getGatherMethods() |
|
| 183 | { |
||
| 184 | 420 | return $this->getOptionValue(self::GATHER_METHODS); |
|
| 185 | } |
||
| 186 | /** |
||
| 187 | * Set current gather methods option value |
||
| 188 | * @throws \InvalidArgumentException |
||
| 189 | * @param string $gatherMethods |
||
| 190 | * @return GeneratorOptions |
||
| 191 | */ |
||
| 192 | 40 | public function setGatherMethods($gatherMethods) |
|
| 193 | { |
||
| 194 | 40 | return $this->setOptionValue(self::GATHER_METHODS, $gatherMethods); |
|
| 195 | } |
||
| 196 | /** |
||
| 197 | * Get generate tutorial file option value |
||
| 198 | * @return bool |
||
| 199 | */ |
||
| 200 | 50 | public function getGenerateTutorialFile() |
|
| 201 | { |
||
| 202 | 50 | return $this->getOptionValue(self::GENERATE_TUTORIAL_FILE); |
|
| 203 | } |
||
| 204 | /** |
||
| 205 | * Set current generate tutorial file option value |
||
| 206 | * @throws \InvalidArgumentException |
||
| 207 | * @param bool $generateTutorialFile |
||
| 208 | * @return GeneratorOptions |
||
| 209 | */ |
||
| 210 | 75 | public function setGenerateTutorialFile($generateTutorialFile) |
|
| 211 | { |
||
| 212 | 75 | return $this->setOptionValue(self::GENERATE_TUTORIAL_FILE, $generateTutorialFile); |
|
| 213 | } |
||
| 214 | /** |
||
| 215 | * Get namespace option value |
||
| 216 | * @return string |
||
| 217 | */ |
||
| 218 | 380 | public function getNamespace() |
|
| 219 | { |
||
| 220 | 380 | return $this->getOptionValue(self::NAMESPACE_PREFIX); |
|
| 221 | } |
||
| 222 | /** |
||
| 223 | * Set current namespace option value |
||
| 224 | * @throws \InvalidArgumentException |
||
| 225 | * @param string $namespace |
||
| 226 | * @return GeneratorOptions |
||
| 227 | */ |
||
| 228 | 55 | public function setNamespace($namespace) |
|
| 229 | { |
||
| 230 | 55 | return $this->setOptionValue(self::NAMESPACE_PREFIX, $namespace); |
|
| 231 | } |
||
| 232 | /** |
||
| 233 | * Get generic constants name option value |
||
| 234 | * @return bool |
||
| 235 | */ |
||
| 236 | 90 | public function getGenericConstantsName() |
|
| 237 | { |
||
| 238 | 90 | return $this->getOptionValue(self::GENERIC_CONSTANTS_NAME); |
|
| 239 | } |
||
| 240 | /** |
||
| 241 | * Set current generic constants name option value |
||
| 242 | * @throws \InvalidArgumentException |
||
| 243 | * @param bool $genericConstantsName |
||
| 244 | * @return GeneratorOptions |
||
| 245 | */ |
||
| 246 | 75 | public function setGenericConstantsName($genericConstantsName) |
|
| 247 | { |
||
| 248 | 75 | return $this->setOptionValue(self::GENERIC_CONSTANTS_NAME, $genericConstantsName); |
|
| 249 | } |
||
| 250 | /** |
||
| 251 | * Get standalone option value |
||
| 252 | * @return bool |
||
| 253 | */ |
||
| 254 | 95 | public function getStandalone() |
|
| 255 | { |
||
| 256 | 95 | return $this->getOptionValue(self::STANDALONE); |
|
| 257 | } |
||
| 258 | /** |
||
| 259 | * Set current standalone option value |
||
| 260 | * @throws \InvalidArgumentException |
||
| 261 | * @param bool $standalone |
||
| 262 | * @return GeneratorOptions |
||
| 263 | */ |
||
| 264 | 45 | public function setStandalone($standalone) |
|
| 265 | { |
||
| 266 | 45 | return $this->setOptionValue(self::STANDALONE, $standalone); |
|
| 267 | } |
||
| 268 | /** |
||
| 269 | * Get validation option value |
||
| 270 | * @return bool |
||
| 271 | */ |
||
| 272 | 180 | public function getValidation() |
|
| 273 | { |
||
| 274 | 180 | return $this->getOptionValue(self::VALIDATION); |
|
| 275 | } |
||
| 276 | /** |
||
| 277 | * Set current validation option value |
||
| 278 | * @throws \InvalidArgumentException |
||
| 279 | * @param bool $validation |
||
| 280 | * @return GeneratorOptions |
||
| 281 | */ |
||
| 282 | 40 | public function setValidation($validation) |
|
| 283 | { |
||
| 284 | 40 | return $this->setOptionValue(self::VALIDATION, $validation); |
|
| 285 | } |
||
| 286 | /** |
||
| 287 | * Get struct class option value |
||
| 288 | * @return string |
||
| 289 | */ |
||
| 290 | 155 | public function getStructClass() |
|
| 291 | { |
||
| 292 | 155 | return $this->getOptionValue(self::STRUCT_CLASS); |
|
| 293 | } |
||
| 294 | /** |
||
| 295 | * Set current struct class option value |
||
| 296 | * @throws \InvalidArgumentException |
||
| 297 | * @param string $structClass |
||
| 298 | * @return GeneratorOptions |
||
| 299 | */ |
||
| 300 | 45 | public function setStructClass($structClass) |
|
| 301 | { |
||
| 302 | 45 | return $this->setOptionValue(self::STRUCT_CLASS, $structClass); |
|
| 303 | } |
||
| 304 | /** |
||
| 305 | * Get struct array class option value |
||
| 306 | * @return string |
||
| 307 | */ |
||
| 308 | 60 | public function getStructArrayClass() |
|
| 309 | { |
||
| 310 | 60 | return $this->getOptionValue(self::STRUCT_ARRAY_CLASS); |
|
| 311 | } |
||
| 312 | /** |
||
| 313 | * Set current struct array class option value |
||
| 314 | * @throws \InvalidArgumentException |
||
| 315 | * @param string $structArrayClass |
||
| 316 | * @return GeneratorOptions |
||
| 317 | */ |
||
| 318 | 35 | public function setStructArrayClass($structArrayClass) |
|
| 319 | { |
||
| 320 | 35 | return $this->setOptionValue(self::STRUCT_ARRAY_CLASS, $structArrayClass); |
|
| 321 | } |
||
| 322 | /** |
||
| 323 | * Get struct array class option value |
||
| 324 | * @return string |
||
| 325 | */ |
||
| 326 | 135 | public function getSoapClientClass() |
|
| 327 | { |
||
| 328 | 135 | return $this->getOptionValue(self::SOAP_CLIENT_CLASS); |
|
| 329 | } |
||
| 330 | /** |
||
| 331 | * Set current struct array class option value |
||
| 332 | * @throws \InvalidArgumentException |
||
| 333 | * @param string $soapClientClass |
||
| 334 | * @return GeneratorOptions |
||
| 335 | */ |
||
| 336 | 35 | public function setSoapClientClass($soapClientClass) |
|
| 337 | { |
||
| 338 | 35 | return $this->setOptionValue(self::SOAP_CLIENT_CLASS, $soapClientClass); |
|
| 339 | } |
||
| 340 | /** |
||
| 341 | * Get origin option value |
||
| 342 | * @return string |
||
| 343 | */ |
||
| 344 | 780 | public function getOrigin() |
|
| 345 | { |
||
| 346 | 780 | return $this->getOptionValue(self::ORIGIN); |
|
| 347 | } |
||
| 348 | /** |
||
| 349 | * Set current origin option value |
||
| 350 | * @throws \InvalidArgumentException |
||
| 351 | * @param string $origin |
||
| 352 | * @return GeneratorOptions |
||
| 353 | */ |
||
| 354 | 410 | public function setOrigin($origin) |
|
| 355 | { |
||
| 356 | 410 | return $this->setOptionValue(self::ORIGIN, $origin); |
|
| 357 | } |
||
| 358 | /** |
||
| 359 | * Get destination option value |
||
| 360 | * @return string |
||
| 361 | */ |
||
| 362 | 440 | public function getDestination() |
|
| 363 | { |
||
| 364 | 440 | return $this->getOptionValue(self::DESTINATION); |
|
| 365 | } |
||
| 366 | /** |
||
| 367 | * Set current destination option value |
||
| 368 | * @throws \InvalidArgumentException |
||
| 369 | * @param string $destination |
||
| 370 | * @return GeneratorOptions |
||
| 371 | */ |
||
| 372 | 415 | public function setDestination($destination) |
|
| 373 | { |
||
| 374 | 415 | return $this->setOptionValue(self::DESTINATION, $destination); |
|
| 375 | } |
||
| 376 | /** |
||
| 377 | * Get src dirname option value |
||
| 378 | * @return string |
||
| 379 | */ |
||
| 380 | 375 | public function getSrcDirname() |
|
| 381 | { |
||
| 382 | 375 | return $this->getOptionValue(self::SRC_DIRNAME); |
|
| 383 | } |
||
| 384 | /** |
||
| 385 | * Set current src dirname option value |
||
| 386 | * @throws \InvalidArgumentException |
||
| 387 | * @param string $srcDirname |
||
| 388 | * @return GeneratorOptions |
||
| 389 | */ |
||
| 390 | 25 | public function setSrcDirname($srcDirname) |
|
| 391 | { |
||
| 392 | 25 | return $this->setOptionValue(self::SRC_DIRNAME, $srcDirname); |
|
| 393 | } |
||
| 394 | /** |
||
| 395 | * Get prefix option value |
||
| 396 | * @return string |
||
| 397 | */ |
||
| 398 | 775 | public function getPrefix() |
|
| 399 | { |
||
| 400 | 775 | return $this->getOptionValue(self::PREFIX); |
|
| 401 | } |
||
| 402 | /** |
||
| 403 | * Set current prefix option value |
||
| 404 | * @throws \InvalidArgumentException |
||
| 405 | * @param string $prefix |
||
| 406 | * @return GeneratorOptions |
||
| 407 | */ |
||
| 408 | 135 | public function setPrefix($prefix) |
|
| 409 | { |
||
| 410 | 135 | return $this->setOptionValue(self::PREFIX, $prefix); |
|
| 411 | } |
||
| 412 | /** |
||
| 413 | * Get suffix option value |
||
| 414 | * @return string |
||
| 415 | */ |
||
| 416 | 745 | public function getSuffix() |
|
| 417 | { |
||
| 418 | 745 | return $this->getOptionValue(self::SUFFIX); |
|
| 419 | } |
||
| 420 | /** |
||
| 421 | * Set current suffix option value |
||
| 422 | * @throws \InvalidArgumentException |
||
| 423 | * @param string $suffix |
||
| 424 | * @return GeneratorOptions |
||
| 425 | */ |
||
| 426 | 65 | public function setSuffix($suffix) |
|
| 427 | { |
||
| 428 | 65 | return $this->setOptionValue(self::SUFFIX, $suffix); |
|
| 429 | } |
||
| 430 | /** |
||
| 431 | * Get basic login option value |
||
| 432 | * @return string |
||
| 433 | */ |
||
| 434 | 785 | public function getBasicLogin() |
|
| 435 | { |
||
| 436 | 785 | return $this->getOptionValue(self::BASIC_LOGIN); |
|
| 437 | } |
||
| 438 | /** |
||
| 439 | * Set current basic login option value |
||
| 440 | * @throws \InvalidArgumentException |
||
| 441 | * @param string $basicLogin |
||
| 442 | * @return GeneratorOptions |
||
| 443 | */ |
||
| 444 | 35 | public function setBasicLogin($basicLogin) |
|
| 445 | { |
||
| 446 | 35 | return $this->setOptionValue(self::BASIC_LOGIN, $basicLogin); |
|
| 447 | } |
||
| 448 | /** |
||
| 449 | * Get basic password option value |
||
| 450 | * @return string |
||
| 451 | */ |
||
| 452 | 785 | public function getBasicPassword() |
|
| 453 | { |
||
| 454 | 785 | return $this->getOptionValue(self::BASIC_PASSWORD); |
|
| 455 | } |
||
| 456 | /** |
||
| 457 | * Set current basic password option value |
||
| 458 | * @throws \InvalidArgumentException |
||
| 459 | * @param string $basicPassword |
||
| 460 | * @return GeneratorOptions |
||
| 461 | */ |
||
| 462 | 35 | public function setBasicPassword($basicPassword) |
|
| 463 | { |
||
| 464 | 35 | return $this->setOptionValue(self::BASIC_PASSWORD, $basicPassword); |
|
| 465 | } |
||
| 466 | /** |
||
| 467 | * Get basic proxy host option value |
||
| 468 | * @return string |
||
| 469 | */ |
||
| 470 | 785 | public function getProxyHost() |
|
| 471 | { |
||
| 472 | 785 | return $this->getOptionValue(self::PROXY_HOST); |
|
| 473 | } |
||
| 474 | /** |
||
| 475 | * Set current proxy host option value |
||
| 476 | * @throws \InvalidArgumentException |
||
| 477 | * @param string $proxyHost |
||
| 478 | * @return GeneratorOptions |
||
| 479 | */ |
||
| 480 | 35 | public function setProxyHost($proxyHost) |
|
| 481 | { |
||
| 482 | 35 | return $this->setOptionValue(self::PROXY_HOST, $proxyHost); |
|
| 483 | } |
||
| 484 | /** |
||
| 485 | * Get basic proxy port option value |
||
| 486 | * @return string |
||
| 487 | */ |
||
| 488 | 785 | public function getProxyPort() |
|
| 489 | { |
||
| 490 | 785 | return $this->getOptionValue(self::PROXY_PORT); |
|
| 491 | } |
||
| 492 | /** |
||
| 493 | * Set current proxy port option value |
||
| 494 | * @throws \InvalidArgumentException |
||
| 495 | * @param string $proxyPort |
||
| 496 | * @return GeneratorOptions |
||
| 497 | */ |
||
| 498 | 35 | public function setProxyPort($proxyPort) |
|
| 499 | { |
||
| 500 | 35 | return $this->setOptionValue(self::PROXY_PORT, $proxyPort); |
|
| 501 | } |
||
| 502 | /** |
||
| 503 | * Get basic proxy login option value |
||
| 504 | * @return string |
||
| 505 | */ |
||
| 506 | 785 | public function getProxyLogin() |
|
| 507 | { |
||
| 508 | 785 | return $this->getOptionValue(self::PROXY_LOGIN); |
|
| 509 | } |
||
| 510 | /** |
||
| 511 | * Set current proxy login option value |
||
| 512 | * @throws \InvalidArgumentException |
||
| 513 | * @param string $proxyLogin |
||
| 514 | * @return GeneratorOptions |
||
| 515 | */ |
||
| 516 | 35 | public function setProxyLogin($proxyLogin) |
|
| 517 | { |
||
| 518 | 35 | return $this->setOptionValue(self::PROXY_LOGIN, $proxyLogin); |
|
| 519 | } |
||
| 520 | /** |
||
| 521 | * Get basic proxy password option value |
||
| 522 | * @return string |
||
| 523 | */ |
||
| 524 | 785 | public function getProxyPassword() |
|
| 525 | { |
||
| 526 | 785 | return $this->getOptionValue(self::PROXY_PASSWORD); |
|
| 527 | } |
||
| 528 | /** |
||
| 529 | * Set current proxy password option value |
||
| 530 | * @throws \InvalidArgumentException |
||
| 531 | * @param string $proxyPassword |
||
| 532 | * @return GeneratorOptions |
||
| 533 | */ |
||
| 534 | 35 | public function setProxyPassword($proxyPassword) |
|
| 535 | { |
||
| 536 | 35 | return $this->setOptionValue(self::PROXY_PASSWORD, $proxyPassword); |
|
| 537 | } |
||
| 538 | /** |
||
| 539 | * Get basic soap options option value |
||
| 540 | * @return array |
||
| 541 | */ |
||
| 542 | 775 | public function getSoapOptions() |
|
| 543 | { |
||
| 544 | 775 | return $this->getOptionValue(self::SOAP_OPTIONS); |
|
| 545 | } |
||
| 546 | /** |
||
| 547 | * Set current soap options option value |
||
| 548 | * @throws \InvalidArgumentException |
||
| 549 | * @param array $soapOptions |
||
| 550 | * @return GeneratorOptions |
||
| 551 | */ |
||
| 552 | 40 | public function setSoapOptions(array $soapOptions) |
|
| 553 | { |
||
| 554 | 40 | return $this->setOptionValue(self::SOAP_OPTIONS, $soapOptions); |
|
| 555 | } |
||
| 556 | /** |
||
| 557 | * Get composer name option value |
||
| 558 | * @return string |
||
| 559 | */ |
||
| 560 | 75 | public function getComposerName() |
|
| 561 | { |
||
| 562 | 75 | return $this->getOptionValue(self::COMPOSER_NAME); |
|
| 563 | } |
||
| 564 | /** |
||
| 565 | * Set current composer name option value |
||
| 566 | * @throws \InvalidArgumentException |
||
| 567 | * @param string $composerName |
||
| 568 | * @return GeneratorOptions |
||
| 569 | */ |
||
| 570 | 105 | public function setComposerName($composerName) |
|
| 571 | { |
||
| 572 | 105 | return $this->setOptionValue(self::COMPOSER_NAME, $composerName); |
|
| 573 | } |
||
| 574 | /** |
||
| 575 | * Get composer settings option value |
||
| 576 | * @return array |
||
| 577 | */ |
||
| 578 | 60 | public function getComposerSettings() |
|
| 579 | { |
||
| 580 | 60 | return $this->getOptionValue(self::COMPOSER_SETTINGS); |
|
| 581 | } |
||
| 582 | /** |
||
| 583 | * Set current composer settings option value |
||
| 584 | * @throws \InvalidArgumentException |
||
| 585 | * @param array $composerSettings |
||
| 586 | * @return GeneratorOptions |
||
| 587 | */ |
||
| 588 | 90 | public function setComposerSettings(array $composerSettings = []) |
|
| 589 | { |
||
| 590 | /** |
||
| 591 | * If array is type array("config.value:true","require:library/src",) |
||
| 592 | */ |
||
| 593 | 90 | $settings = []; |
|
| 594 | 90 | foreach ($composerSettings as $index => $value) { |
|
| 595 | 35 | if (is_numeric($index) && strpos($value, ':') > 0) { |
|
| 596 | 35 | $path = implode('', array_slice(explode(':', $value), 0, 1)); |
|
| 597 | 35 | $val = implode(':', array_slice(explode(':', $value), 1)); |
|
| 598 | 35 | self::dotNotationToArray($path, $val, $settings); |
|
| 599 | 14 | } else { |
|
| 600 | 23 | $settings[$index] = $value; |
|
| 601 | } |
||
| 602 | 36 | } |
|
| 603 | 90 | return $this->setOptionValue(self::COMPOSER_SETTINGS, $settings); |
|
| 604 | } |
||
| 605 | /** |
||
| 606 | * turns my.key.path to array('my' => array('key' => array('path' => $value))) |
||
| 607 | * @param string $string |
||
| 608 | * @param mixed $value |
||
| 609 | * @param array $array |
||
| 610 | */ |
||
| 611 | 35 | protected static function dotNotationToArray($string, $value, array &$array) |
|
| 612 | { |
||
| 613 | 35 | $keys = explode('.', $string); |
|
| 614 | 35 | foreach ($keys as $key) { |
|
| 615 | 35 | $array = &$array[$key]; |
|
| 616 | 14 | } |
|
| 617 | 35 | $array = ($value === 'true' || $value === 'false') ? $value === 'true' : $value; |
|
| 618 | 35 | } |
|
| 619 | /** |
||
| 620 | * Get structs folder option value |
||
| 621 | * @return string |
||
| 622 | */ |
||
| 623 | 380 | public function getStructsFolder() |
|
| 624 | { |
||
| 625 | 380 | return $this->getOptionValue(self::STRUCTS_FOLDER); |
|
| 626 | } |
||
| 627 | /** |
||
| 628 | * Set current structs folder option value |
||
| 629 | * @throws \InvalidArgumentException |
||
| 630 | * @param string $structsFolder |
||
| 631 | * @return GeneratorOptions |
||
| 632 | */ |
||
| 633 | 35 | public function setStructsFolder($structsFolder) |
|
| 634 | { |
||
| 635 | 35 | return $this->setOptionValue(self::STRUCTS_FOLDER, $structsFolder); |
|
| 636 | } |
||
| 637 | /** |
||
| 638 | * Get arrays folder option value |
||
| 639 | * @return string |
||
| 640 | */ |
||
| 641 | 80 | public function getArraysFolder() |
|
| 642 | { |
||
| 643 | 80 | return $this->getOptionValue(self::ARRAYS_FOLDER); |
|
| 644 | } |
||
| 645 | /** |
||
| 646 | * Set current arrays folder option value |
||
| 647 | * @throws \InvalidArgumentException |
||
| 648 | * @param string $arraysFolder |
||
| 649 | * @return GeneratorOptions |
||
| 650 | */ |
||
| 651 | 35 | public function setArraysFolder($arraysFolder) |
|
| 652 | { |
||
| 653 | 35 | return $this->setOptionValue(self::ARRAYS_FOLDER, $arraysFolder); |
|
| 654 | } |
||
| 655 | /** |
||
| 656 | * Get enums folder option value |
||
| 657 | * @return string |
||
| 658 | */ |
||
| 659 | 150 | public function getEnumsFolder() |
|
| 660 | { |
||
| 661 | 150 | return $this->getOptionValue(self::ENUMS_FOLDER); |
|
| 662 | } |
||
| 663 | /** |
||
| 664 | * Set current enums folder option value |
||
| 665 | * @throws \InvalidArgumentException |
||
| 666 | * @param string $enumsFolder |
||
| 667 | * @return GeneratorOptions |
||
| 668 | */ |
||
| 669 | 35 | public function setEnumsFolder($enumsFolder) |
|
| 670 | { |
||
| 671 | 35 | return $this->setOptionValue(self::ENUMS_FOLDER, $enumsFolder); |
|
| 672 | } |
||
| 673 | /** |
||
| 674 | * Get services folder option value |
||
| 675 | * @return string |
||
| 676 | */ |
||
| 677 | 740 | public function getServicesFolder() |
|
| 678 | { |
||
| 679 | 740 | return $this->getOptionValue(self::SERVICES_FOLDER); |
|
| 680 | } |
||
| 681 | /** |
||
| 682 | * Set current services folder option value |
||
| 683 | * @throws \InvalidArgumentException |
||
| 684 | * @param string $servicesFolder |
||
| 685 | * @return GeneratorOptions |
||
| 686 | */ |
||
| 687 | 35 | public function setServicesFolder($servicesFolder) |
|
| 688 | { |
||
| 689 | 35 | return $this->setOptionValue(self::SERVICES_FOLDER, $servicesFolder); |
|
| 690 | } |
||
| 691 | /** |
||
| 692 | * Get schemas save option value |
||
| 693 | * @return bool |
||
| 694 | */ |
||
| 695 | 20 | public function getSchemasSave() |
|
| 696 | { |
||
| 697 | 20 | return $this->getOptionValue(self::SCHEMAS_SAVE); |
|
| 698 | } |
||
| 699 | /** |
||
| 700 | * Set schemas save option value |
||
| 701 | * @throws \InvalidArgumentException |
||
| 702 | * @param bool $saveSchemas |
||
| 703 | * @return GeneratorOptions |
||
| 704 | */ |
||
| 705 | 40 | public function setSchemasSave($saveSchemas) |
|
| 709 | /** |
||
| 710 | * Get schemas folder option value |
||
| 711 | * @return string |
||
| 712 | */ |
||
| 713 | 15 | public function getSchemasFolder() |
|
| 717 | /** |
||
| 718 | * Set schemas folder option value |
||
| 719 | * @throws \InvalidArgumentException |
||
| 720 | * @param string $schemasFolder |
||
| 721 | * @return GeneratorOptions |
||
| 722 | */ |
||
| 723 | 40 | public function setSchemasFolder($schemasFolder) |
|
| 724 | { |
||
| 725 | 40 | return $this->setOptionValue(self::SCHEMAS_FOLDER, $schemasFolder); |
|
| 726 | } |
||
| 727 | /** |
||
| 728 | * @return string[] |
||
| 729 | */ |
||
| 730 | 45 | public function toArray() |
|
| 731 | { |
||
| 732 | 45 | $options = []; |
|
| 733 | 45 | foreach (array_keys($this->options) as $name) { |
|
| 734 | 45 | $options[$name] = $this->getOptionValue($name); |
|
| 735 | 18 | } |
|
| 736 | 45 | return $options; |
|
| 737 | } |
||
| 738 | 10 | public function jsonSerialize() |
|
| 739 | { |
||
| 740 | 10 | return $this->toArray(); |
|
| 741 | } |
||
| 742 | } |
||
| 743 |