I am pleased to say that most of the non-blog parts of my site are now served from static files. I have been working toward making a static version of my site for a while. I have created a PHP static web task that can crawl a site and turn the responses into an Apache friendly directory structure. Those pages now can be served extra fast, without going through PHP, and could be served on a free static host if I wanted. To go static, I not only had to write the code to build the static files, but also had to modify my site code to have the desired output when called from that context and modify my Apache configuration to respond correctly and add some headers that were being added by PHP before.
Continue reading post "Site partially static"static posts
Playing with GitHub Pages
This past weekend, I started playing with GitHub Pages for the first time. It took a while to figure out, but was somewhat fun. I’ve been interested in it for a while, but was unsure of how to do what I wanted, such as building with PHP, Sass, and Rollup. Turns out it was fairly easy with GitHub Actions to do most any sort of build steps I want. It is very interesting for free static site web-hosting.
Continue reading post "Playing with GitHub Pages"Notes on Using PHP Class With Statics for Configuration
I will be talking about using namespaced PHP classes with static properties for configuration. Since my use was in relation to Symfony, it is important to note that the Config component should be used for everything possible, but that it can’t be used before it is instantiated.
Reasons to use namespaced static class properties for configuration:
- A class can be defined in a file. When that file is included from elsewhere, the class is defined.
- Once a class is defined, it is accessible anywhere after that point, regardless of scope. Like a superglobal.
- Statics are variables set on a class rather than on an instance and can be accessed directly from the class. This means no variables outside of the class need to be set to work with the variables. Like a superglobal singleton.
- Statics are not static and can be modified just like any other variables.
- Static methods can control access and provide other behaviors you may want for working with your configuration.
- Namespaces help prevent collisions of class names by essentially adding characters to a class name that make it less likely to be used elsewhere. With psr-0 / psr-4 autoloaders, the namespaces should be well controlled.
- Variables can’t be namespaced, so classes (or constants or functions) are the only way to take advantage of their benefits.
- Using constants and functions inside of a namespace is similar to static properties and methods of a class, except the constants are immutable and have limited data types, and there aren’t the niceties like
self
for the functions. - Being in PHP (as opposed to some config file format) allows use of
__DIR__
(my primary need was for storing paths, and it wouldn’t be ideal to have to put in the full filesystem paths to things), string concatenation and other operations, and any other PHP behavior or values desired.