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

/Zend/Tool/Framework/Loader/IncludePathLoader.php

https://gitlab.com/luisrepo/ClienteWS
PHP | 139 lines | 65 code | 21 blank | 53 comment | 10 complexity | d89519d74eb4d867f9343a66ec778480 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Tool
  17. * @subpackage Framework
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: IncludePathLoader.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * @see Zend_Tool_Framework_Loader_Abstract
  24. */
  25. require_once 'Zend/Tool/Framework/Loader/Abstract.php';
  26. /**
  27. * @see Zend_Tool_Framework_Loader_IncludePathLoader_RecursiveFilterIterator
  28. */
  29. require_once 'Zend/Tool/Framework/Loader/IncludePathLoader/RecursiveFilterIterator.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Tool
  33. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Tool_Framework_Loader_IncludePathLoader extends Zend_Tool_Framework_Loader_Abstract
  37. {
  38. /**
  39. * _getFiles()
  40. *
  41. * @return array Array of files to load
  42. */
  43. protected function _getFiles()
  44. {
  45. require_once 'Zend/Loader.php';
  46. $paths = Zend_Loader::explodeIncludePath();
  47. // used for checking similarly named files
  48. $relativeItems = array();
  49. $files = array();
  50. $isZendTraversed = false;
  51. foreach ($paths as $path) {
  52. // default patterns to use
  53. $filterDenyDirectoryPattern = '.*(/|\\\\).svn';
  54. $filterAcceptFilePattern = '.*(?:Manifest|Provider)\.php$';
  55. if (!file_exists($path) || $path[0] == '.') {
  56. continue;
  57. }
  58. $realIncludePath = realpath($path);
  59. // ensure that we only traverse a single version of Zend Framework on all include paths
  60. if (file_exists($realIncludePath . '/Zend/Tool/Framework/Loader/IncludePathLoader.php')) {
  61. if ($isZendTraversed === false) {
  62. $isZendTraversed = true;
  63. } else {
  64. // use the deny directory pattern that includes the path to 'Zend', it will not be accepted
  65. $filterDenyDirectoryPattern = '.*((/|\\\\).svn|' . preg_quote($realIncludePath . DIRECTORY_SEPARATOR) . 'Zend)';
  66. }
  67. }
  68. // create recursive directory iterator
  69. $rdi = new RecursiveDirectoryIterator($path);
  70. // pass in the RecursiveDirectoryIterator & the patterns
  71. $filter = new Zend_Tool_Framework_Loader_IncludePathLoader_RecursiveFilterIterator(
  72. $rdi,
  73. $filterDenyDirectoryPattern,
  74. $filterAcceptFilePattern
  75. );
  76. // build the rii with the filter
  77. $iterator = new RecursiveIteratorIterator($filter);
  78. // iterate over the accepted items
  79. foreach ($iterator as $item) {
  80. $file = (string)$item;
  81. if($this->_fileIsBlacklisted($file)) {
  82. continue;
  83. }
  84. // ensure that the same named file from separate include_paths is not loaded
  85. $relativeItem = preg_replace('#^' . preg_quote($realIncludePath . DIRECTORY_SEPARATOR, '#') . '#', '', $item->getRealPath());
  86. // no links allowed here for now
  87. if ($item->isLink()) {
  88. continue;
  89. }
  90. // no items that are relavitely the same are allowed
  91. if (in_array($relativeItem, $relativeItems)) {
  92. continue;
  93. }
  94. $relativeItems[] = $relativeItem;
  95. $files[] = $item->getRealPath();
  96. }
  97. }
  98. return $files;
  99. }
  100. /**
  101. *
  102. * @param string $file
  103. * @return bool
  104. */
  105. protected function _fileIsBlacklisted($file)
  106. {
  107. $blacklist = array(
  108. "PHPUnit".DIRECTORY_SEPARATOR."Framework",
  109. "Zend".DIRECTORY_SEPARATOR."OpenId".DIRECTORY_SEPARATOR."Provider"
  110. );
  111. foreach($blacklist AS $blacklitedPattern) {
  112. if(strpos($file, $blacklitedPattern) !== false) {
  113. return true;
  114. }
  115. }
  116. return false;
  117. }
  118. }