/monica/vendor/zendframework/zendframework/library/Zend/Filter/FilterPluginManager.php

https://bitbucket.org/alexandretaz/maniac_divers · PHP · 118 lines · 76 code · 6 blank · 36 comment · 2 complexity · d61f03c7ed94a107ad71d45dbc6e0bed 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-2013 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace Zend\Filter;
  10. use Zend\ServiceManager\AbstractPluginManager;
  11. /**
  12. * Plugin manager implementation for the filter chain.
  13. *
  14. * Enforces that filters retrieved are either callbacks or instances of
  15. * FilterInterface. Additionally, it registers a number of default filters
  16. * available, as well as aliases for them.
  17. */
  18. class FilterPluginManager extends AbstractPluginManager
  19. {
  20. /**
  21. * Default set of filters
  22. *
  23. * @var array
  24. */
  25. protected $invokableClasses = array(
  26. 'alnum' => 'Zend\I18n\Filter\Alnum',
  27. 'alpha' => 'Zend\I18n\Filter\Alpha',
  28. 'basename' => 'Zend\Filter\BaseName',
  29. 'boolean' => 'Zend\Filter\Boolean',
  30. 'callback' => 'Zend\Filter\Callback',
  31. 'compress' => 'Zend\Filter\Compress',
  32. 'compressbz2' => 'Zend\Filter\Compress\Bz2',
  33. 'compressgz' => 'Zend\Filter\Compress\Gz',
  34. 'compresslzf' => 'Zend\Filter\Compress\Lzf',
  35. 'compressrar' => 'Zend\Filter\Compress\Rar',
  36. 'compresssnappy' => 'Zend\Filter\Compress\Snappy',
  37. 'compresstar' => 'Zend\Filter\Compress\Tar',
  38. 'compresszip' => 'Zend\Filter\Compress\Zip',
  39. 'decompress' => 'Zend\Filter\Decompress',
  40. 'decrypt' => 'Zend\Filter\Decrypt',
  41. 'digits' => 'Zend\Filter\Digits',
  42. 'dir' => 'Zend\Filter\Dir',
  43. 'encrypt' => 'Zend\Filter\Encrypt',
  44. 'encryptblockcipher' => 'Zend\Filter\Encrypt\BlockCipher',
  45. 'encryptopenssl' => 'Zend\Filter\Encrypt\Openssl',
  46. 'filedecrypt' => 'Zend\Filter\File\Decrypt',
  47. 'fileencrypt' => 'Zend\Filter\File\Encrypt',
  48. 'filelowercase' => 'Zend\Filter\File\LowerCase',
  49. 'filerename' => 'Zend\Filter\File\Rename',
  50. 'filerenameupload' => 'Zend\Filter\File\RenameUpload',
  51. 'fileuppercase' => 'Zend\Filter\File\UpperCase',
  52. 'htmlentities' => 'Zend\Filter\HtmlEntities',
  53. 'inflector' => 'Zend\Filter\Inflector',
  54. 'int' => 'Zend\Filter\Int',
  55. 'localizedtonormalized' => 'Zend\Filter\LocalizedToNormalized',
  56. 'normalizedtolocalized' => 'Zend\Filter\NormalizedToLocalized',
  57. 'null' => 'Zend\Filter\Null',
  58. 'numberformat' => 'Zend\I18n\Filter\NumberFormat',
  59. 'pregreplace' => 'Zend\Filter\PregReplace',
  60. 'realpath' => 'Zend\Filter\RealPath',
  61. 'stringtolower' => 'Zend\Filter\StringToLower',
  62. 'stringtoupper' => 'Zend\Filter\StringToUpper',
  63. 'stringtrim' => 'Zend\Filter\StringTrim',
  64. 'stripnewlines' => 'Zend\Filter\StripNewlines',
  65. 'striptags' => 'Zend\Filter\StripTags',
  66. 'urinormalize' => 'Zend\Filter\UriNormalize',
  67. 'wordcamelcasetodash' => 'Zend\Filter\Word\CamelCaseToDash',
  68. 'wordcamelcasetoseparator' => 'Zend\Filter\Word\CamelCaseToSeparator',
  69. 'wordcamelcasetounderscore' => 'Zend\Filter\Word\CamelCaseToUnderscore',
  70. 'worddashtocamelcase' => 'Zend\Filter\Word\DashToCamelCase',
  71. 'worddashtoseparator' => 'Zend\Filter\Word\DashToSeparator',
  72. 'worddashtounderscore' => 'Zend\Filter\Word\DashToUnderscore',
  73. 'wordseparatortocamelcase' => 'Zend\Filter\Word\SeparatorToCamelCase',
  74. 'wordseparatortodash' => 'Zend\Filter\Word\SeparatorToDash',
  75. 'wordseparatortoseparator' => 'Zend\Filter\Word\SeparatorToSeparator',
  76. 'wordunderscoretocamelcase' => 'Zend\Filter\Word\UnderscoreToCamelCase',
  77. 'wordunderscoretodash' => 'Zend\Filter\Word\UnderscoreToDash',
  78. 'wordunderscoretoseparator' => 'Zend\Filter\Word\UnderscoreToSeparator',
  79. );
  80. /**
  81. * Whether or not to share by default; default to false
  82. *
  83. * @var bool
  84. */
  85. protected $shareByDefault = false;
  86. /**
  87. * Validate the plugin
  88. *
  89. * Checks that the filter loaded is either a valid callback or an instance
  90. * of FilterInterface.
  91. *
  92. * @param mixed $plugin
  93. * @return void
  94. * @throws Exception\RuntimeException if invalid
  95. */
  96. public function validatePlugin($plugin)
  97. {
  98. if ($plugin instanceof FilterInterface) {
  99. // we're okay
  100. return;
  101. }
  102. if (is_callable($plugin)) {
  103. // also okay
  104. return;
  105. }
  106. throw new Exception\RuntimeException(sprintf(
  107. 'Plugin of type %s is invalid; must implement %s\FilterInterface or be callable',
  108. (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
  109. __NAMESPACE__
  110. ));
  111. }
  112. }