PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/setup/includes/error/modinstalljsonerror.class.php

http://github.com/modxcms/revolution
PHP | 73 lines | 65 code | 0 blank | 8 comment | 0 complexity | d4056e99c886aef9b5bd78732f7e666d MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. require_once strtr(realpath(MODX_SETUP_PATH.'includes/error/modinstallerror.class.php'),'\\','/');
  11. /*
  12. * This file is part of MODX Revolution.
  13. *
  14. * Copyright (c) MODX, LLC. All Rights Reserved.
  15. *
  16. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  17. * files found in the top-level directory of this distribution.
  18. */
  19. class modInstallJSONError extends modInstallError {
  20. public $fields;
  21. public $type;
  22. function __construct(&$modx, $message= '', $type= 'error') {
  23. $this->message= $message;
  24. $this->fields= array ();
  25. $this->type= $type;
  26. parent :: __construct($modx, $message);
  27. }
  28. public function process($message= '', $status = false, $object = null) {
  29. $objarray= parent :: process($message, $status, $object);
  30. @header("Content-Type: text/json; charset=UTF-8");
  31. if ($message != '') $this->message= $message;
  32. return json_encode(array (
  33. 'message' => $this->message,
  34. 'fields' => $this->fields,
  35. 'type' => $this->type,
  36. 'object' => $objarray,
  37. 'success' => $status,
  38. ));
  39. }
  40. public function addField($name, $error) {
  41. $this->fields[]= array (
  42. 'name' => $name,
  43. 'error' => $error
  44. );
  45. }
  46. public function getFields() {
  47. $f= array ();
  48. foreach ($this->fields as $fi) $f[]= $fi['name'];
  49. return $f;
  50. }
  51. public function hasError() {
  52. return count($this->fields) > 0 || ($this->message != '' && $this->type == 'error');
  53. }
  54. public function setType($type= 'error') {
  55. $this->type= $type;
  56. }
  57. public function failure($message = '', $object = null) {
  58. while (ob_get_level() && @ob_end_clean()) {}
  59. die($this->process($message, false, $object));
  60. }
  61. public function success($message = '', $object = null) {
  62. die($this->process($message, true, $object));
  63. }
  64. }