I’ve linked to Unsplash before. Â It’s a collection of free high-resolution photos. Â This time however, I’m linking to their excellent 404 page design. Â Every time you hit a 404 page not found error, you see a short funny fail video. Â Every time the video is different. Â Funny!
Month: April 2016
tus.io – open protocol for resumable file uploads
tus.io, in their own words:
People share more and more photos and videos every day. Mobile networks remain fragile however. Platform APIs are a mess and every project builds its own file uploader. There are a thousand one week projects that barely work, when all we need is one real project. One project done right.
We are going to do this right. We aim to solve the problem of unreliable file uploads once and for all. tus is a new open protocol for resumable uploads built on HTTP. It offers simple, cheap and reusable stacks for clients and servers. It supports any language, any platform and any network.
Adventure in composer private repositories
First of all, I would like to take this opportunity and wish composer a happy birthday and many more years to come. Â It’s been five years, and the world of PHP has changed so drastically that not many people remember how it used to be before.
I would have completely missed the birthday if it wasn’t for all the Google searching I did while working on a weird problem. Â But before I get to the problem, let me set the scene.
The big part of composer success is Packagist.org – the repository of almost 100,000 packages (93,572, according to statistics, as of this writing, to be precise), which help one to solve pretty much any problem that PHP can be used for.
As good as the Packagist is, there is often a need for a repository or a package elsewhere. Â Whether it’s a commercial library, or sensitive corporate code, having an ability to store it outside of public eye and handle with the same ease and the same tool as the rest of the dependencies is a very welcome feature.
Now we are getting closer to what actually happened. Â A while back, I’ve setup deployment and development process for WordPress-based projects. Â WordPress doesn’t support composer natively, but there are ways to make it work. Â Huge thanks here goes to Roots.
So. Â The composer.json file was filled with additional repositories and requirements which told composer where from to fetch things, and where to install them. Â Here’s an example:
"repositories": [ { "type": "package", "package": { "name": "wordpress", "type": "webroot", "version": "4.4.1", "dist": { "type": "zip", "url": "https://github.com/WordPress/WordPress/archive/4.4.1.zip" }, "require": { "fancyguy/webroot-installer": "1.1.0" } } }, // ...
This got especially useful, when we need to work with commercial plugins, which we couldn’t push to our public repositories, and which we didn’t want to re-distribute with every project.
So far so good. Fast-forward to a few month ago. We are setting up similar development and deployment process, but now for CakePHP-based projects. Things are much easier, since CakePHP 3 natively supports composer for the application itself and for its plugins.
But we still have the need for private repositories here and there, so we follow the same setup as we did for WordPress. This week, we had an unexpected roadblock, which wasn’t making much sense to me. When trying to pull a CakePHP plugin from a private repository, we’d get a nasty exception like this:
$ composer update Loading composer repositories with package information Updating dependencies (including require-dev) - Installing qobo/cakephp-test-foo (1.0.1) Loading from cache [RuntimeException] Unable to get primary namespace for package qobo/cakephp-test-foo. Ensure you have added proper 'autoload' section to your plugin's config as stated in README on https://github.com/cakephp/plugin-installer
This was confusing. First of all, I’ve never seen this error before. Secondly, I’ve read the README and had the autoloader section in the composer.json as instructed. Thirdly, very similar plugins were working fine.
Long story short, the issue wasn’t related to whether or not the GitHub/BitBucket repository was private or public. It was related to how the repository was configured in the composer.json. Reading and re-reading composer documentation about Repositories finally helped.
You can have a look at our test setup:
- cakephp-project – an empty vanilla CakePHP 3 project with no configurations.
- cakephp-test-foo – an empty CakePHP 3 plugin, baked by CakePHP itself.
- commit #1f1a2ca – fix for the problem
CakePHP plugin installer requires the autoload section in composer.json. Â But, when the repository is of type “package“, for some reason, the autoload section is ignored altogether. Â The RuntimeException “Unable to get primary namespace for package” is thrown by cakephp/plugin-installer (src/Installer/PluginInstaller.php line 274). Â The problem is not actually in the cakephp/plugin-installer, but somewhere in the composer. Â Maybe it’s intentional or maybe it’s not. Â I didn’t have the time to investigate and understand it further.
Switching the repository to type “vcs” fixes the problem. Â It also simplifies the composer.json file and removes the need for multiple version definitions, as now composer is using BitBucket/GitHub API to fetch available versions.
Ice Orb Levitating Speaker
I’ve got a slightly delayed birthday present today, from a good friend of mine.  Ice Orb levitating speaker is a Bluetooth speaker with a twist.  It comes with a base, which, when switched on, makes the speaker levitate over it.  It just hangs in the air, no strings attached.  Or a USB cable attached, if you want to charge it.  Coupled with a few blue LEDs, it makes quite an impression.  The future is here, ladies and gentlemen.  We live in the world of science fiction.
Here’s the video of this thing in action: