PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/classes/fuel/validation_error.php

https://github.com/jay3/core
PHP | 59 lines | 29 code | 5 blank | 25 comment | 5 complexity | 680d7ccf13ee4c0ee9cc2923988c5e5f MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * NOVIUS OS - Web OS for digital communication
  4. *
  5. * @copyright 2011 Novius
  6. * @license GNU Affero General Public License v3 or (at your option) any later version
  7. * http://www.gnu.org/licenses/agpl-3.0.html
  8. * @link http://www.novius-os.org
  9. */
  10. class Validation_Error extends Fuel\Core\Validation_Error
  11. {
  12. /**
  13. * Load validation Language file when errors are thrown
  14. */
  15. public static function _init()
  16. {
  17. // Prevents from loading validation translations
  18. // parent::_init();
  19. \Config::load('nos::validation', true);
  20. }
  21. /**
  22. * Get Message
  23. *
  24. * Shows the error message which can be taken from loaded language file.
  25. *
  26. * @param string HTML to prefix error message
  27. * @param string HTML to postfix error message
  28. * @param string Message to use, or false to try and load it from Lang class
  29. * @return string
  30. */
  31. public function get_message($msg = false, $open = '', $close = '')
  32. {
  33. $open = empty($open) ? \Config::get('validation.open_single_error', '') : $open;
  34. $close = empty($close) ? \Config::get('validation.close_single_error', '') : $close;
  35. if ($msg === false and ! ($msg = $this->field->get_error_message($this->rule))) {
  36. if (is_null($msg)) {
  37. $msg = $this->field->fieldset()->validation()->get_message($this->rule);
  38. }
  39. if ($msg === false) {
  40. $msg = \Config::get('nos::validation.'.$this->rule, false) ?: __(\Arr::get(explode(':', $this->rule), 0));
  41. }
  42. }
  43. if ($msg == false) {
  44. return $open.strtr(__('The field ‘{{field}}’ doesn’t respect the rule ‘{{rule}}’'), array(
  45. '{{rule}}' => $this->rule,
  46. '{{field}}' => $this->field->label,
  47. )).$close;
  48. }
  49. // Translator placeholder is '{{param:1}}', internal Fuel placeholder is ':param:1'
  50. $msg = preg_replace('`{{param:(\d+)}}`', ':param:$1', $msg);
  51. // only parse when there's tags in the message
  52. return $open.(strpos($msg, ':') === false ? $msg : $this->_replace_tags($msg)).$close;
  53. }
  54. }