general-setup.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * User: sourcefabric
  4. * Date: 08/12/14
  5. *
  6. * Class GeneralSetup
  7. *
  8. * Wrapper class for validating and setting up general settings during the installation process
  9. */
  10. class GeneralSetup extends Setup {
  11. // airtime.conf section header
  12. const SECTION = "[general]";
  13. // Constant form field names for passing errors back to the front-end
  14. const GENERAL_PORT = "generalPort",
  15. GENERAL_HOST = "generalHost";
  16. // Form field values
  17. static $user, $host, $port, $root;
  18. // Array of key->value pairs for airtime.conf
  19. static $properties;
  20. // Message and error fields to return to the front-end
  21. static $message = null;
  22. static $errors = array();
  23. function __construct($settings) {
  24. self::$host = $settings[self::GENERAL_HOST];
  25. self::$port = $settings[self::GENERAL_PORT];
  26. self::$properties = array(
  27. "api_key" => $this->generateRandomString(),
  28. "base_url" => self::$host,
  29. "base_port" => self::$port,
  30. );
  31. }
  32. function writeToTemp() {
  33. parent::writeToTemp(self::SECTION, self::$properties);
  34. }
  35. /**
  36. * @return array associative array containing a display message and fields with errors
  37. */
  38. function runSetup() {
  39. // TODO Do we need to validate these settings?
  40. if (count(self::$errors) <= 0) {
  41. $this->writeToTemp();
  42. }
  43. return array(
  44. "message" => self::$message,
  45. "errors" => self::$errors
  46. );
  47. }
  48. }