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

/vendor/zendframework/zend-validator/src/ValidatorPluginManager.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 196 lines | 134 code | 10 blank | 52 comment | 5 complexity | 7e910696f3841c3d5623fe3b2531fc96 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace Zend\Validator;
  10. use Zend\ServiceManager\AbstractPluginManager;
  11. use Zend\ServiceManager\ConfigInterface;
  12. class ValidatorPluginManager extends AbstractPluginManager
  13. {
  14. /**
  15. * Default aliases
  16. *
  17. * @var array
  18. */
  19. protected $aliases = array(
  20. 'Zend\I18n\Validator\Float'=> 'Zend\I18n\Validator\IsFloat',
  21. 'Zend\I18n\Validator\Int' => 'Zend\I18n\Validator\IsInt',
  22. );
  23. /**
  24. * Default set of validators
  25. *
  26. * @var array
  27. */
  28. protected $invokableClasses = array(
  29. 'alnum' => 'Zend\I18n\Validator\Alnum',
  30. 'alpha' => 'Zend\I18n\Validator\Alpha',
  31. 'barcodecode25interleaved' => 'Zend\Validator\Barcode\Code25interleaved',
  32. 'barcodecode25' => 'Zend\Validator\Barcode\Code25',
  33. 'barcodecode39ext' => 'Zend\Validator\Barcode\Code39ext',
  34. 'barcodecode39' => 'Zend\Validator\Barcode\Code39',
  35. 'barcodecode93ext' => 'Zend\Validator\Barcode\Code93ext',
  36. 'barcodecode93' => 'Zend\Validator\Barcode\Code93',
  37. 'barcodeean12' => 'Zend\Validator\Barcode\Ean12',
  38. 'barcodeean13' => 'Zend\Validator\Barcode\Ean13',
  39. 'barcodeean14' => 'Zend\Validator\Barcode\Ean14',
  40. 'barcodeean18' => 'Zend\Validator\Barcode\Ean18',
  41. 'barcodeean2' => 'Zend\Validator\Barcode\Ean2',
  42. 'barcodeean5' => 'Zend\Validator\Barcode\Ean5',
  43. 'barcodeean8' => 'Zend\Validator\Barcode\Ean8',
  44. 'barcodegtin12' => 'Zend\Validator\Barcode\Gtin12',
  45. 'barcodegtin13' => 'Zend\Validator\Barcode\Gtin13',
  46. 'barcodegtin14' => 'Zend\Validator\Barcode\Gtin14',
  47. 'barcodeidentcode' => 'Zend\Validator\Barcode\Identcode',
  48. 'barcodeintelligentmail' => 'Zend\Validator\Barcode\Intelligentmail',
  49. 'barcodeissn' => 'Zend\Validator\Barcode\Issn',
  50. 'barcodeitf14' => 'Zend\Validator\Barcode\Itf14',
  51. 'barcodeleitcode' => 'Zend\Validator\Barcode\Leitcode',
  52. 'barcodeplanet' => 'Zend\Validator\Barcode\Planet',
  53. 'barcodepostnet' => 'Zend\Validator\Barcode\Postnet',
  54. 'barcoderoyalmail' => 'Zend\Validator\Barcode\Royalmail',
  55. 'barcodesscc' => 'Zend\Validator\Barcode\Sscc',
  56. 'barcodeupca' => 'Zend\Validator\Barcode\Upca',
  57. 'barcodeupce' => 'Zend\Validator\Barcode\Upce',
  58. 'barcode' => 'Zend\Validator\Barcode',
  59. 'between' => 'Zend\Validator\Between',
  60. 'bitwise' => 'Zend\Validator\Bitwise',
  61. 'callback' => 'Zend\Validator\Callback',
  62. 'creditcard' => 'Zend\Validator\CreditCard',
  63. 'csrf' => 'Zend\Validator\Csrf',
  64. 'date' => 'Zend\Validator\Date',
  65. 'datestep' => 'Zend\Validator\DateStep',
  66. 'datetime' => 'Zend\I18n\Validator\DateTime',
  67. 'dbnorecordexists' => 'Zend\Validator\Db\NoRecordExists',
  68. 'dbrecordexists' => 'Zend\Validator\Db\RecordExists',
  69. 'digits' => 'Zend\Validator\Digits',
  70. 'emailaddress' => 'Zend\Validator\EmailAddress',
  71. 'explode' => 'Zend\Validator\Explode',
  72. 'filecount' => 'Zend\Validator\File\Count',
  73. 'filecrc32' => 'Zend\Validator\File\Crc32',
  74. 'fileexcludeextension' => 'Zend\Validator\File\ExcludeExtension',
  75. 'fileexcludemimetype' => 'Zend\Validator\File\ExcludeMimeType',
  76. 'fileexists' => 'Zend\Validator\File\Exists',
  77. 'fileextension' => 'Zend\Validator\File\Extension',
  78. 'filefilessize' => 'Zend\Validator\File\FilesSize',
  79. 'filehash' => 'Zend\Validator\File\Hash',
  80. 'fileimagesize' => 'Zend\Validator\File\ImageSize',
  81. 'fileiscompressed' => 'Zend\Validator\File\IsCompressed',
  82. 'fileisimage' => 'Zend\Validator\File\IsImage',
  83. 'filemd5' => 'Zend\Validator\File\Md5',
  84. 'filemimetype' => 'Zend\Validator\File\MimeType',
  85. 'filenotexists' => 'Zend\Validator\File\NotExists',
  86. 'filesha1' => 'Zend\Validator\File\Sha1',
  87. 'filesize' => 'Zend\Validator\File\Size',
  88. 'fileupload' => 'Zend\Validator\File\Upload',
  89. 'fileuploadfile' => 'Zend\Validator\File\UploadFile',
  90. 'filewordcount' => 'Zend\Validator\File\WordCount',
  91. 'float' => 'Zend\I18n\Validator\IsFloat',
  92. 'greaterthan' => 'Zend\Validator\GreaterThan',
  93. 'hex' => 'Zend\Validator\Hex',
  94. 'hostname' => 'Zend\Validator\Hostname',
  95. 'iban' => 'Zend\Validator\Iban',
  96. 'identical' => 'Zend\Validator\Identical',
  97. 'inarray' => 'Zend\Validator\InArray',
  98. 'int' => 'Zend\I18n\Validator\IsInt',
  99. 'ip' => 'Zend\Validator\Ip',
  100. 'isbn' => 'Zend\Validator\Isbn',
  101. 'isfloat' => 'Zend\I18n\Validator\IsFloat',
  102. 'isinstanceof' => 'Zend\Validator\IsInstanceOf',
  103. 'isint' => 'Zend\I18n\Validator\IsInt',
  104. 'lessthan' => 'Zend\Validator\LessThan',
  105. 'notempty' => 'Zend\Validator\NotEmpty',
  106. 'phonenumber' => 'Zend\I18n\Validator\PhoneNumber',
  107. 'postcode' => 'Zend\I18n\Validator\PostCode',
  108. 'regex' => 'Zend\Validator\Regex',
  109. 'sitemapchangefreq' => 'Zend\Validator\Sitemap\Changefreq',
  110. 'sitemaplastmod' => 'Zend\Validator\Sitemap\Lastmod',
  111. 'sitemaploc' => 'Zend\Validator\Sitemap\Loc',
  112. 'sitemappriority' => 'Zend\Validator\Sitemap\Priority',
  113. 'stringlength' => 'Zend\Validator\StringLength',
  114. 'step' => 'Zend\Validator\Step',
  115. 'timezone' => 'Zend\Validator\Timezone',
  116. 'uri' => 'Zend\Validator\Uri',
  117. );
  118. /**
  119. * Whether or not to share by default; default to false
  120. *
  121. * @var bool
  122. */
  123. protected $shareByDefault = false;
  124. /**
  125. * Constructor
  126. *
  127. * After invoking parent constructor, add an initializer to inject the
  128. * attached translator, if any, to the currently requested helper.
  129. *
  130. * @param null|ConfigInterface $configuration
  131. */
  132. public function __construct(ConfigInterface $configuration = null)
  133. {
  134. parent::__construct($configuration);
  135. $this->addInitializer(array($this, 'injectTranslator'));
  136. $this->addInitializer(array($this, 'injectValidatorPluginManager'));
  137. }
  138. /**
  139. * Inject a validator instance with the registered translator
  140. *
  141. * @param ValidatorInterface $validator
  142. * @return void
  143. */
  144. public function injectTranslator($validator)
  145. {
  146. if ($validator instanceof Translator\TranslatorAwareInterface) {
  147. $locator = $this->getServiceLocator();
  148. if ($locator && $locator->has('MvcTranslator')) {
  149. $validator->setTranslator($locator->get('MvcTranslator'));
  150. }
  151. }
  152. }
  153. /**
  154. * Inject a validator plugin manager
  155. *
  156. * @param $validator
  157. * @return void
  158. */
  159. public function injectValidatorPluginManager($validator)
  160. {
  161. if ($validator instanceof ValidatorPluginManagerAwareInterface) {
  162. $validator->setValidatorPluginManager($this);
  163. }
  164. }
  165. /**
  166. * Validate the plugin
  167. *
  168. * Checks that the validator loaded is an instance of ValidatorInterface.
  169. *
  170. * @param mixed $plugin
  171. * @return void
  172. * @throws Exception\RuntimeException if invalid
  173. */
  174. public function validatePlugin($plugin)
  175. {
  176. if ($plugin instanceof ValidatorInterface) {
  177. // we're okay
  178. return;
  179. }
  180. throw new Exception\RuntimeException(sprintf(
  181. 'Plugin of type %s is invalid; must implement %s\ValidatorInterface',
  182. (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
  183. __NAMESPACE__
  184. ));
  185. }
  186. }