SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/Locales/LocaleInfoCHN.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers\Locales;
  15.  
  16. use Sprout\Exceptions\ValidationException;
  17. use Sprout\Helpers\Validator;
  18.  
  19.  
  20. /**
  21.  * Locale info for China; see {@see LocaleInfo}
  22.  */
  23. class LocaleInfoCHN extends LocaleInfo
  24. {
  25. protected $state_list = [
  26. 'Beijing',
  27. 'Tianjin',
  28. 'Hebei',
  29. 'Shanxi',
  30. 'Nei Mongol',
  31. 'Liaoning',
  32. 'Jilin',
  33. 'Heilongjiang',
  34. 'Shanghai',
  35. 'Jiangsu',
  36. 'Zhejiang',
  37. 'Anhui',
  38. 'Fujian',
  39. 'Jiangxi',
  40. 'Shandong',
  41. 'Henan',
  42. 'Hubei',
  43. 'Hunan',
  44. 'Guangdong',
  45. 'Guangxi',
  46. 'Hainan',
  47. 'Chongqing',
  48. 'Sichuan',
  49. 'Guizhou',
  50. 'Yunnan',
  51. 'Xizang',
  52. 'Shaanxi',
  53. 'Gansu',
  54. 'Qinghai',
  55. 'Ningxia',
  56. 'Xinjiang',
  57. 'Taiwan',
  58. 'Xianggang',
  59. 'Aomen',
  60. ];
  61.  
  62.  
  63. /**
  64.   * Validate a Chinese postcode, which is a 6-digit number
  65.   *
  66.   * @param string $code The postcode to validate
  67.   * @throws ValidationException If the format isn't correct
  68.   */
  69. public static function validatePostcode($code)
  70. {
  71. if (!preg_match('/^[0-9]{6}$/i', $code)) {
  72. throw new ValidationException('Incorrect format');
  73. }
  74. }
  75.  
  76.  
  77. /**
  78.   * Validate address fields
  79.   *
  80.   * @param Validator $valid The validation object to add rules to
  81.   * @param bool $required Are the address fields required?
  82.   */
  83. public function validateAddress(Validator $valid, $required = false)
  84. {
  85. parent::validateAddress($valid, $required);
  86.  
  87. $valid->check('postcode', __CLASS__ . '::validatePostcode');
  88. $valid->check('postcode', 'Validity::length', 6, 6);
  89. }
  90. }
  91.