Library.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Hoa
  4. *
  5. *
  6. * @license
  7. *
  8. * New BSD License
  9. *
  10. * Copyright © 2007-2017, Hoa community. All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * * Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * * Neither the name of the Hoa nor the names of its contributors may be
  20. * used to endorse or promote products derived from this software without
  21. * specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. namespace Hoa\Protocol\Node;
  36. /**
  37. * Class \Hoa\Protocol\Node\Library.
  38. *
  39. * `hoa://Library/` node.
  40. *
  41. * @copyright Copyright © 2007-2017 Hoa community
  42. * @license New BSD License
  43. */
  44. class Library extends Node
  45. {
  46. /**
  47. * Queue of the component.
  48. *
  49. * @param string $queue Queue of the component (generally, a filename,
  50. * with probably a query).
  51. * @return mixed
  52. */
  53. public function reach($queue = null)
  54. {
  55. if (!WITH_COMPOSER) {
  56. return parent::reach($queue);
  57. }
  58. if (!empty($queue)) {
  59. $head = $queue;
  60. if (false !== $pos = strpos($queue, '/')) {
  61. $head = substr($head, 0, $pos);
  62. $queue = DIRECTORY_SEPARATOR . substr($queue, $pos + 1);
  63. } else {
  64. $queue = null;
  65. }
  66. $out = [];
  67. foreach (explode(RS, $this->_reach) as $part) {
  68. $out[] = "\r" . $part . strtolower($head) . $queue;
  69. }
  70. $out[] = "\r" . dirname(dirname(dirname(dirname(__DIR__)))) . $queue;
  71. return implode(RS, $out);
  72. }
  73. $out = [];
  74. foreach (explode(RS, $this->_reach) as $part) {
  75. $pos = strrpos(rtrim($part, DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR) + 1;
  76. $head = substr($part, 0, $pos);
  77. $tail = substr($part, $pos);
  78. $out[] = $head . strtolower($tail);
  79. }
  80. $this->_reach = implode(RS, $out);
  81. return parent::reach($queue);
  82. }
  83. }