In PHP Use is More Like an Alias than an Import

PHP Use is an Alias

PHP has a use statement that allows the importing or, more accurately, aliasing of classes into the current namespace. In other languages, like Python, importing a nonexistent class or module will fail at the import. In PHP, this doesn't happen, instead the program will fail later when the aliased class, function, or constant is is… Continue reading In PHP Use is More Like an Alias than an Import

Posted in PHP

Lifecycle Objects as Extension Points

lifecycle objects

Something I've found myself doing more and more is writing lifecycle objects that add notification-like extension points to other objects. A good example is the MessageLifecycle interface and its implementations in PMG's queue library. Rather than pollute the queue consumers with events or other more generic things directly, the lifecycle provides and extension point into… Continue reading Lifecycle Objects as Extension Points

Parameter & Result Objects: More Than Grouping Values

Parameter and Result Objects

A parameter object replaces one or more parameters to a method with a single object instance. A result object is a object created specifically for a return value from a method. Parameter Objects Changing a method to accept a parameter object is a common refactoring for grouping parameters that belong together. Unfortunately that's not the… Continue reading Parameter & Result Objects: More Than Grouping Values

Logging to Papertrail from Symfony Applications

PMG uses Papertrail to aggregate logs and we've found it to be really solid over the last four years. Example Monolog Configuration Here's a quick example of configuration for Monolog Bundle to get logs to papertrail. This uses Monolog's remote syslog handler to do its work. Couple key points around the services here: PsrLogMessageProcessor is… Continue reading Logging to Papertrail from Symfony Applications

On Library Exceptions I made this statement on twitter about PHP libraries throwing exceptions that I want to expand here. I'd say there are two broad categories of exceptions that a library might throw. Domain Exceptions These are specific to the library's domain. For instance, if I'm working with AdWords I know that AdWords account IDs take… Continue reading On Library Exceptions

AWS Key Management Service Envelope Encryption in PHP

This is a PHP example of what AWS calls envelope encryption. Really this is just a way to use a key hierarchy rooted at a key management service (KMS) key. We'll use PHP 7.2's libsodium support (via paragonie/sodium_compat). The idea is that you have a customer master key that lives in KMS - this never… Continue reading AWS Key Management Service Envelope Encryption in PHP