09.xhtml 5.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * <https://y.st./>
  4. * Copyright © 2016 Alex Yst <mailto:copyright@y.st>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org./licenses/>.
  18. **/
  19. $xhtml = array(
  20. 'title' => '<code>\\scandir()</code>',
  21. 'body' => <<<END
  22. <p>
  23. For some strange reason, my spider keeps quitting on me without an error message.
  24. At least now, quitting does not cause all the data to be lost.
  25. </p>
  26. <p>
  27. I found a function in the $a[PHP] manual that I had not seen before: <a href="https://secure.php.net/manual/en/function.scandir.php"><code>scandir()</code></a>.
  28. This function lists all files in a directory, and even does it alphabetically.
  29. As far as I can tell, the only thing that directory handles and <code>\\Directory</code> object are good for is listing directories, so this simple function obsoletes both, as both are a pain to use.
  30. Literally every time that I want to use them, I have to consult the manual again to be sure I am using them correctly because you cannot just iterate over them as expected.
  31. Instead, you must explicitly check each return value for being identical to (not just equal to) false while at the same time assigning the values to variables.
  32. I have always thought that such a directory-listing function should exist, but could never find it, so I always just built my own.
  33. This function also obsoletes my own custom <code>dir()</code> function, which just creates a dir object, iterates over it, then alphabetizes and returns the results, so I am removing it.
  34. It obsoletes my dir class as well, though I will be keeping that due to it being one of my wrapper classes.
  35. </p>
  36. <p>
  37. While working on wrapping stream resources, I found some interesting things.
  38. First, that <a href="https://secure.php.net/manual/en/class.streamwrapper.php">class prototype that I found yesterday</a> seems to be for use with the <a href="https://secure.php.net/manual/en/function.stream-wrapper-register.php"><code>stream_wrapper_register()</code> function</a>.
  39. It is completely irrelevant to my current project of wrapping up resources with their function.
  40. Second, and more interestingly, I do not see any functions for actually creating a <a href="https://secure.php.net/manual/en/ref.stream.php">stream resource</a>.
  41. Instead, as best I can tell, the stream functions are used on resources created by more specific functions.
  42. For example, I think that the stream functions apply to <a href="https://secure.php.net/manual/en/book.dir.php">directory resources</a> and <a href="https://secure.php.net/manual/en/book.ftp.php">$a[FTP]</a> resources.
  43. I was thinking about making my stream class into an abstract class for other classes such as the $a[FTP] class to extend, but there is a small issue with that plan.
  44. Specifically, my directory class already extends the default, half-implemented <code>\\Directory</code> class.
  45. I can instead make it into a trait, though that means reworking several classes.
  46. Specifically, my wrapper classes currently use self::\$resource to hold the resource handle, but <code>\\Directory</code> uses <code>self::\$handle</code> instead.
  47. In order to make the trait work, I will need to change any class that uses the stream trait to match.
  48. For consistency, I will probably change all the wrapper classes to match whether they use the stream trait or not.
  49. The one down side to using a trait instead of an abstract class is that I cannot use type hints to require that certain function take only resource wrappers as arguments.
  50. From the looks of it though, if this becomes a problem, I can create an interface to go with the trait.
  51. An interface cannot define working methods and a trait cannot be used for type hinting, but together, they can get the job done.
  52. </p>
  53. <p>
  54. I ran into some strange functions relating to &quot;bucket objects&quot; and &quot;brigade resources&quot;.
  55. There is no documentation that I can find on where brigade resources come from or how to create them.
  56. The only scrap of information that I can find is on the <a href="https://secure.php.net/manual/en/function.stream-bucket-prepend.php"><code>\\stream_bucket_prepend()</code> function</a>&apos;s documentation page.
  57. This documentation says that a brigade resource is a resource used to contain bucket objects, but that is all that is says bout them.
  58. As for bucket object, I ran some tests on my machine, and it seems that bucket objects are just <code>\\stdClass</code> objects that have three properties: a string, an integer, and a &quot;userfilter.bucket&quot; resource.
  59. I am also having trouble wrapping the stream_socket_*() functions, as their descriptions are not consistent.
  60. Some appear to work on a specific type of resource that is used for socket streams, but some imply that they are for streams in general.
  61. </p>
  62. <p>
  63. My <a href="/a/canary.txt">canary</a> still sings the tune of freedom and transparency.
  64. </p>
  65. END
  66. );