123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?xml version="1.0" encoding="utf-8"?>
- <!--
-
- h t t :: / / t /
- h t t :: // // t //
- h ttttt ttttt ppppp sssss // // y y sssss ttttt //
- hhhh t t p p s // // y y s t //
- h hh t t ppppp sssss // // yyyyy sssss t //
- h h t t p s :: / / y .. s t .. /
- h h t t p sssss :: / / yyyyy .. sssss t .. /
-
- <https://y.st./>
- Copyright © 2015 Alex Yst <mailto:copyright@y.st>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org./licenses/>.
- -->
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <base href="https://y.st./en/weblog/2015/12-December/31.xhtml" />
- <title>Wrapper classes <https://y.st./en/weblog/2015/12-December/31.xhtml></title>
- <link rel="icon" type="image/png" href="/link/CC_BY-SA_4.0/y.st./icon.png" />
- <link rel="stylesheet" type="text/css" href="/link/basic.css" />
- <link rel="stylesheet" type="text/css" href="/link/site-specific.css" />
- <script type="text/javascript" src="/script/javascript.js" />
- <meta name="viewport" content="width=device-width" />
- </head>
- <body>
- <nav>
- <p>
- <a href="/en/">Home</a> |
- <a href="/en/a/about.xhtml">About</a> |
- <a href="/en/a/contact.xhtml">Contact</a> |
- <a href="/a/canary.txt">Canary</a> |
- <a href="/en/URI_research/"><abbr title="Uniform Resource Identifier">URI</abbr> research</a> |
- <a href="/en/opinion/">Opinions</a> |
- <a href="/en/coursework/">Coursework</a> |
- <a href="/en/law/">Law</a> |
- <a href="/en/a/links.xhtml">Links</a> |
- <a href="/en/weblog/2015/12-December/31.xhtml.asc">{this page}.asc</a>
- </p>
- <hr/>
- <p>
- Weblog index:
- <a href="/en/weblog/"><abbr title="American Standard Code for Information Interchange">ASCII</abbr> calendars</a> |
- <a href="/en/weblog/index_ol_ascending.xhtml">Ascending list</a> |
- <a href="/en/weblog/index_ol_descending.xhtml">Descending list</a>
- </p>
- <hr/>
- <p>
- Jump to entry:
- <a href="/en/weblog/2015/03-March/07.xhtml"><<First</a>
- <a rel="prev" href="/en/weblog/2015/12-December/30.xhtml"><Previous</a>
- <a rel="next" href="/en/weblog/2016/01-January/01.xhtml">Next></a>
- <a href="/en/weblog/latest.xhtml">Latest>></a>
- </p>
- <hr/>
- </nav>
- <header>
- <h1>Wrapper classes</h1>
- <p>Day 00299: Thursday, 2015 December 31</p>
- </header>
- <p>
- This morning, I awoke to find that our home's Internet connection was down.
- Everything seems to be fine on our end, leading me to believe that the problem is on our <abbr title="Internet service provider">ISP</abbr>'s side.
- In any case, it got me thinking.
- I am pretty helpless without the Internet.
- This morning, I was not able to accomplish anything of note.
- I could not test my email client to see if everything is in order now.
- I could have worked on my search engine spider, but the point of that thing is to learn.
- I do not already know the functions and parameters I need in order to make it work.
- Without access to the online <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> manual, I could not continue progress.
- Likewise, I considered starting a small project to fill the time by building wrapper classes for as many <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> function sets as I could that pass around a resource.
- However, again, I would need the <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> manual in order to find and understand these function sets.
- I could not work on the <abbr title="Internet Relay Chat">IRC</abbr> server either, as it appears that I do not have the software needed to do so.
- The <abbr title="Internet Relay Chat">IRC</abbr> server is up and running perfectly already, so the only thing left to do is get services running.
- My current services software is incompatible with my current <abbr title="Internet Relay Chat">IRC</abbr> daemon though.
- I need to install a new services package and/or a new <abbr title="Internet Relay Chat">IRC</abbr> daemon, which requires retrieving it or them from the Internet.
- At the very least, I need to download the <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> manual.
- I can put one copy of it at <code>https://php.test/</code> for easy use when my local network is functioning but we cannot access the greater Internet, as well as a second copy on my laptop hard drive, where it willl not be as convenient to use, but will be perfectly accessible even when I have no connection at all.
- </p>
- <p>
- While trying to figure out what to do with myself, I realized that the <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> wrapper class would be a good project for me.
- While it would be incredibly simple, it would also teach me about the different resource types available in <abbr title="PHP: Hypertext Preprocessor">PHP</abbr>.
- At the very least, I make direct use of two different resource types in my code, and I really should clean that up with some object-oriented code.
- I also think that I should move my wrapper classes to a sub-namespace, making them easy to identify both in my code and in my directory tree.
- That was when it hit me.
- I could download the <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> manual on my mobile, then transfer it to my laptop over <abbr title="Media Transfer Protocol">MTP</abbr>.
- </p>
- <p>
- I thought that I would need to grep the manual to find informations on all the resource-using functions, but much to my delight, <code>./php-chunked-xhtml/resource.html</code> has a list of them.
- Most of the entries on the table there have hyperlinks to the sections of the manual that document the functions, though a few do not.
- Having no access to the Internet on my laptop, it was easiest to just assume that the links were not present due to there not being any entries in the manual, and instead focus only on the resource types that did offer links to their related functions.
- </p>
- <p>
- First, I made the modifications necessary to move my existing wrapper class, the one for <abbr title="Client for URLs/Client URL Request Library/Curl URL Request Library">cURL</abbr> resources, into the sub-namespace.
- After that, I turned my focus to attention on <abbr title="GNU Privacy Guard">GnuPG</abbr> handles.
- Much to my surprise though, the <code>gnupg_init()</code> function and the handles that it creates were not mentioned in the manual.
- I would have suspected that functions that are not built-into <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> are mentioned only on the online manual if not for the fact that <abbr title="Client for URLs/Client URL Request Library/Curl URL Request Library">cURL</abbr> resource handle and accompanying functions are in fact listed in this manual.
- In any case, adding a wrapper class to <abbr title="GNU Privacy Guard">GnuPG</abbr> would have to wait until I had Internet access again.
- My next target was the objects output by the <code>dir()</code> function.
- According to the manual, <code>dir()</code> is only used as pseudo-object oriented method of accessing directories.
- However, I found that the class of objects output by this function is completely legitimate.
- Unlike the class used by closures, you can even instantiate this class with the <code>new</code> key word.
- It even has all the functions that one would expect it to have, with the exception of two: a constructor and a destructor.
- The <code>dir()</code> function acts as a sort of pseudo-constructor though, and a destructor is not strictly needed.
- I decided not to try extending this class, as it would pretty much just mean changing the line <code>$var = dir($file);</code> into the longer line <code>$var = new dir($file);</code>, which would need to be preceded by a second line reading <code>use st\y\wrapper\dir;</code> for the first line to even be that short.
- My guess from reading the documentation is that the <code>dir()</code> function basically acts like this:
- </p>
- <p>
- <code><span class="PHP-T_OPEN_TAG"><?php<br/>
- </span><span class="PHP-T_FUNCTION">function</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T_STRING">dir</span><span class="PHP-T">(</span><span class="PHP-T_VARIABLE">$directory</span><span class="PHP-T">,</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T_VARIABLE">$context</span><span class="PHP-T">=</span><span class="PHP-T_STRING">null</span><span class="PHP-T">)</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T">{</span><span class="PHP-T_WHITESPACE"><br/>
-     </span><span class="PHP-T_VARIABLE">$new</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T">=</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T_NEW">new</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T_STRING">Dir</span><span class="PHP-T">;</span><span class="PHP-T_WHITESPACE"><br/>
-     </span><span class="PHP-T_VARIABLE">$new</span><span class="PHP-T_OBJECT_OPERATOR">-></span><span class="PHP-T_STRING">path</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T">=</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T_VARIABLE">$directory</span><span class="PHP-T">;</span><span class="PHP-T_WHITESPACE"><br/>
-     </span><span class="PHP-T_VARIABLE">$new</span><span class="PHP-T_OBJECT_OPERATOR">-></span><span class="PHP-T_STRING">handle</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T">=</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T_STRING">opendir</span><span class="PHP-T">(</span><span class="PHP-T_VARIABLE">$directory</span><span class="PHP-T">,</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T_VARIABLE">$context</span><span class="PHP-T">)</span><span class="PHP-T">;</span><span class="PHP-T_WHITESPACE"><br/>
- </span><span class="PHP-T_RETURN">return</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T_VARIABLE">$new</span><span class="PHP-T">;</span><span class="PHP-T_WHITESPACE"> </span><span class="PHP-T">}</span></code>
- </p>
- <p>
- It might have some input checks in it unlike the code above, but aside from that, I think that it behaves about the same way.
- </p>
- <p>
- Before I could get any actual new classes written, I was whisked away to work in my mother's classroom for most of the day.
- On the bright side though, it sounds like I can probably go to Portland with Alyssa with minimal problems attached! I will likely stay there for three weeks.
- Durring that time, I may or may not be able to update my canary.
- This should be awesome though, I will get to see what she is doing to make a difference in the world and hopefully even help.
- </p>
- <p>
- It looks like I was not the only one having mail issues, but Zoho <a href="https://forums.zoho.com/topic/error-fetching-folders-syntax-expecting-s-found-c">fixed the problem</a>! It looks like tha other two users that joined the conversation were using the same mail client as I, though I did not mention what mail client I use.
- After posting about the issue, I realized that I should have mentioned that I was using an <abbr title="Internet Message Access Protocol">IMAP</abbr> client.
- </p>
- <p>
- While out today, I realized that I should work on the directory wrapper, despite my initial decision not to.
- In the case of the way that the built-in directory class and directory functions work, they are really only useful when a complex iterative loop is built around them.
- The class should be able to iterate over itself, or at least work well in a simple loop.
- I quickly found the likely reason that iteration was not included in the built-in class though.
- The directory resource handles are not built in a way that makes using the Iterator interface easy.
- Putting these wrapper classes together has proven to be quite boring though, so I do not think I want to sit down and complete them all at once.
- Instead, I will make sure to complete at least one to throw in with each regular update I perform on my library.
- </p>
- <p>
- I found a <a href="https://secure.php.net/manual/en/ref.dbx.php">dbx extension for <abbr title="PHP: Hypertext Preprocessor">PHP</abbr></a> in the manual while looking for functions that need to be wrapped.
- The documentation says that instead of a resource, an object is passed around between functions.
- Why are these functions not made object methods? It might be worth extending the class used and add the methods in, but testing the name of the class used is undocumented and and finding out from <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> itself would require setting up some sort of database so that the class can be successfully instantiated using the provided functions and the object class checked with the <a href="https://secure.php.net/manual/en/function.get-class.php"><code>get_class()</code> function</a>.
- I only managed to get four new wrapper classes built today, but I will continue the project later.
- </p>
- <p>
- My <a href="/a/canary.txt">canary</a> still sings the tune of freedom and transparency.
- </p>
- <hr/>
- <p>
- Copyright © 2015 Alex Yst;
- You may modify and/or redistribute this document under the terms of the <a rel="license" href="/license/gpl-3.0-standalone.xhtml"><abbr title="GNU's Not Unix">GNU</abbr> <abbr title="General Public License version Three or later">GPLv3+</abbr></a>.
- If for some reason you would prefer to modify and/or distribute this document under other free copyleft terms, please ask me via email.
- My address is in the source comments near the top of this document.
- This license also applies to embedded content such as images.
- For more information on that, see <a href="/en/a/licensing.xhtml">licensing</a>.
- </p>
- <p>
- <abbr title="World Wide Web Consortium">W3C</abbr> standards are important.
- This document conforms to the <a href="https://validator.w3.org./nu/?doc=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2015%2F12-December%2F31.xhtml"><abbr title="Extensible Hypertext Markup Language">XHTML</abbr> 5.1</a> specification and uses style sheets that conform to the <a href="http://jigsaw.w3.org./css-validator/validator?uri=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2015%2F12-December%2F31.xhtml"><abbr title="Cascading Style Sheets">CSS</abbr>3</a> specification.
- </p>
- </body>
- </html>
|