Posts about PHP (old posts, page 1)
-
I released the first PHP 8 library ever
At least among the libraries listed on the Packagist. On this Tuesday sandfoxme/bencode was updated to 2.0 that requires PHP 8 as a minimum. While it was meant mostly as an experiment and a joke, it allowed me to try some new features like
Stringable
interface and remove some old compatibility handling thanks tombstring.func_overload
being finally removed. -
sabre/xml
An awesome discovery of today was made in an article titled An XML library for PHP you may not hate. As an unexpected twist I really didn't hate it, in fact it helped me to solve a problem that I had. It is called sabre/xml and it's a part of the sabre/dav project.
-
Install Composer in Docker
Here is a small snippet adapted from the official instruction:
RUN php -r "copy('https://composer.github.io/installer.sig', '/tmp/composer.sig');" && \ php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');" && \ php -r '$expected = file_get_contents("/tmp/composer.sig"); $actual = hash_file("sha384", "/tmp/composer-setup.php"); exit(intval(!hash_equals($expected, $actual)));' && \ php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer && \ chmod +x /usr/local/bin/composer && \ rm /tmp/composer-setup.php /tmp/composer.sig
It doesn't require a script file, doesn't deal with environment variables, and doesn't depend on the shell.
-
PHP 7.4: Splat Inconsistency
PHP 7.4 has this great new feature: splat operator now works in array expressions.
-
Encryptor
Created a simple cli file encryptor using libsodium
The app can create a password-protected file encoded with XSalsa20 and Argon2id
See my dev portal: https://sandfox.dev/php/encryptor.html
-
Composer Yaml
My new library to allow composer to read config from YAML file. There is some demand in comments for composer config but the developers are not interested and most 3rd party attempts to solve it are limited to yaml2json converters.
I tried a slightly different approach. There is a command in the composer itself that changes the way the config is read:
composer global
. During its execution it changes current working directory, resets composer state, and forces the composer to read config from another directory.What I tried to do: I put yaml2json converter in place of
global
's directory changing code, and it seems it worked. Of course, some things got broken like any command that tries to change composer.json will no longer have any effect, however many people don't use them and it may be an acceptable tradeoff for using yml-based config.You can find the project on my new dev website: https://sandfox.dev/php/composer-yaml.html
-
Private Composer Repo with GitLab and Satis
You can easily create your own composer repository using Satis and GitLab. I will use global https://gitlab.com but it should be most useful for private corporate GitLab installations. You will need CI and Pages
-
PhpStorm Advanced Metadata Exporter
As a Silex user I liked Pimple Container Dumper that worked with Silex Idea Plugin to enable code completion for Pimple DI in PhpStorm. But now with Silex EOL'd I have to move to Slim.
I've found no such projects so I had to write my own. Here it is: sandfoxme/phpstorm-metadata-export. It currently supports exporting data from Pimple and has 3 integration middlewares: for Slim, for Silex and for Psr-15 compatible frameworks.
P.S. Code completion support for ArrayAccess containers seem to be currently broken in PhpStorm (WI-33309, WI-35503). So I don't currently recommend replacing Silex Idea Plugin with this library unless you use Pimple in Psr-11 compliant way (like Slim does by default)
-
Composer Viz
A tool inspired by
bundle viz
command.Just look at its selfie:
Get it on my dev site: https://sandfox.dev/php/composer-viz.html
-
PHP Access Private Methods and Fields
These two simple functions can come in handy as helpers for something like PsySH. PHP >= 7.0 is required.