Monthly Archiv: September, 2020

Site News: Blast from the Past – One Year Ago in PHP (09.24.2020)

Here's what was popular in the PHP community one year ago today:

Dynamically changing the log level in Symfony apps

This is just a quick post sharing something I was able to figure out after doing some research.

The situation: our application throws exceptions by means of "talking back to the user". As developer we don't want to be notified about all these exceptions. They aren't as important as any other exception that should be considered "critical". Still, we do want to find these exceptions in the logs, because they can sometimes provide valuable feedback about the usability of the system.

So basically we just want Symfony to log the exception, but dial the standard log level "critical" for certain types of exceptions down to "info". Monolog has the concept of a processor for that (represented by the optional ProcessorInterface). The implemented process() method should return the modified log record, which is actually an array containing the different parts of a log record (the level, the message, and the context). Since not every log record is related to an exception, we don't have to do anything in most cases. Here's the code:

use Monolog\Logger;
use Monolog\Processor\ProcessorInterface;
use Symfony\Component\HttpKernel\EventListener\ErrorListener;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Throwable;

final class AdjustLogLevelForExceptions implements ProcessorInterface
{
    public function __invoke(array $record): array
    {
        if (!isset($record['context']['exception'])) {
            /**
             * Symfony's ErrorListener will provide a Throwable through the log message's context.
             * If the context has no "exception" key, we don't have to further process this log record.
             *
             * @see ErrorListener::logException()
             */
            return $record;
        }

        $throwable = $record['context']['exception'];
        if (!$throwable instanceof Throwable) {
            // For some reason the provided value is not an actual exception, so we can't do anything with it
            return $record;
        }

        // Change the log level if necessary
        $modifiedLogLevel = $this->determineLogLevel($throwable, $record['level']);

        $record['level'] = $modifiedLogLevel;
        $record['level_name'] = Logger::getLevelName($modifiedLogLevel);

        return $record;
    }

    private function determineLogLevel(Throwable $throwable, int $currentLevel): int
    {
        if ($throwable instanceof UserErrorMessage) {
            // These are exceptions that will be rendered to the user.
            return Logger::INFO;
        }

        return $currentLevel;
    }
}

Now you only have to register this processor as a service and tag it as monolog.processor:

services:
    AdjustLogLevelForExceptions:
        tags:
            - { name: monolog.processor }

If you use auto-wiring and have set up auto-configuration for the directory where the AdjustLogLevelForExceptions is located you don't even have to tag this service. The MonologBundle should automatically do that for you.

PHP 8.0 feature focus: <span>match() expressions</span>

In our last episode, we discussed coming improvements to PHP’s type system. Today we look at a new construct that makes branching logic more powerful. PHP has had a switch statement since the dawn of time, modeled on the same construct in C. You’ve surely seen it before: <?php switch ($var) { case 'a': $message = "The variable was a."; break; case 'b': $message = "The variable was c."; break; case 'c': $message = "The variable was c.

PHP MIT App Inventor Extension Extractor (New)

Package:
PHP MIT App Inventor Extension Extractor
Summary:
Extract details from MIT App Inventor project
Groups:
Files and Folders, Parsers, PHP 5
Author:
Dannel
Description:
This package can extract details from MIT App Inventor Extension...

Read more at https://www.phpclasses.org/package/11822-PHP-Extract-details-from-MIT-App-Inventor-project.html

PHP MIT App Inventor Project Extractor (New)

Package:
PHP MIT App Inventor Project Extractor
Summary:
Extract details from MIT App Inventor project
Groups:
Files and Folders, Parsers, PHP 5
Author:
Dannel
Description:
This package can extract details from MIT App Inventor project...

Read more at https://www.phpclasses.org/package/11822-PHP-Extract-details-from-MIT-App-Inventor-project.html

Laravel Template Engine Modules

Package:
Laravel Template Engine Modules
Summary:
Implement template modules using custom classes
Groups:
Libraries, PHP 5, Templates
Author:
Ivan Semenkov
Description:
This package can implement template modules using custom classes...

Read more at https://www.phpclasses.org/package/11824-PHP-Implement-template-modules-using-custom-classes.html#2020-09-23-03:04:28

Does A Designer’s Opinion Mean More Than The User’s?

Okay. I’m going to come out and say it. Designers are often way too territorial about their designs. It’s only natural, of course. You spend years and years developing your design skills, you create the ideal process for your ideal user to follow so that (you’re certain) they will get the best experience possible.

But here’s the thing: users may not stick to your original vision of how your design “should” be used. The truth is, they don’t have to, and, if your views on their user experience are off the mark, they shouldn’t.

We look at some ways in which users often give designers a run for their money when it comes to the ideal user experience, and explore whether a designer’s opinion means more than the user’s.

Technicality Versus Practicality

Sometimes, there is a clear battle between the designer’s creative vision and what the user really wants. This can be seen in major corporate projects as well as individual website designs for a single client.

Designers, by virtue of being creative professionals, often let their ego get in the way of creating a truly functional product. Some of this is justified. After all, you want to maintain your reputation for quality, both functionally and visually.

But, as the saying goes, form follows function. You don’t want to get so caught up in maintaining your design’s visual appeal that you lose sight of what’s best for the user.

The best way to avoid this pitfall is to regularly interact with your target audience. Talk to people who interact with your website, app, or other designs. Ask them questions about their experience – what they feel could be improved, how your design is helping them achieve solutions to their problems, et cetera.

This knowledge will be invaluable not just to your users and your clients, but also for expanding your career as a designer who really “gets” the ideal user experience.

office discussion designer users desk overhead

Co-Opting Your Environment

Users, by definition, use things. Sounds obvious, I know, but many designers forget this simple fact, or think it only applies to a narrow set of rules. But people who use things are amazingly adaptable. They use the world around them to create their own design solutions, if the ones provided aren’t satisfactory. All users have this ability – including you.

Yes, you routinely violate many designers’ perfect visions for how you should be using their products. Ever scribbled a phone number or email address on the back of someone’s business card? You rebellious user, you.

From holding a supposedly “ergonomic” pen or tool in a way that’s unconventional, but more comfortable for you, to breaking out the sugru and physically altering a product to fit your individual needs, we all take advantage of what I call the user’s authority.

Following Leaders And Precedents

Once a design leaves your studio, it officially belongs to the user, and they will adapt it however they see fit. People use design to communicate with one another out in the world, often in ways that the designer never intended or even expected. Your design may end up serving a completely different purpose than what it was originally created for.

Think about the last time you gave directions to a tourist or someone in your town who was lost. You probably told them something closer to “head left at the intersection with the weird billboard,” rather than rattled off a dry list of street names.

Design infiltrates our daily lives, and we use it as placeholders, markers, and guides every day.

office discussion designer users desk overhead

Does The Design Slow Down Progress?

The most important thing to consider in any design is whether the user can solve the problem they have with the maximum amount of efficiency. If your design is impeding them from doing this, then it’s a failure as a design.

Again, talking to your target users will yield a wealth of information that can help you avoid this common crisis. I’m not talking about formal “focus group” style research either. Even something as simple as a 5 question email survey can help tremendously in the design process.

For example, if you don’t know that the majority of your users are skipping the calls to action that you’ve added to your website, pretty much the only way you can find this out is by interacting with them.

It’s unlikely that they’re going to tell you on their own, and, quite honestly, it’s not their responsibility to do so. You’re the designer – it’s your job to make sure that your designs are providing maximum efficiency for your users.

Building Up Trust

Well designed websites instill a sense of trust in the user. When you see a crappy looking website, your first instinct is that it’s probably a bit shady, or even an outright scam.

Why? Well, because a legitimate business will usually at least make an attempt to have a professional-looking front.

The post Does A Designer’s Opinion Mean More Than The User’s? appeared first on Speckyboy Design Magazine.

Laravel Template Engine Modules (New)

Package:
Laravel Template Engine Modules
Summary:
Implement template modules using custom classes
Groups:
Libraries, PHP 5, Templates
Author:
Ivan Semenkov
Description:
This package can implement template modules using custom classes...

Read more at https://www.phpclasses.org/package/11824-PHP-Implement-template-modules-using-custom-classes.html

Community News: Latest PECL Releases (09.22.2020)

Latest PECL Releases:

  • datadog_trace 0.48.3
    ### Fixed

    • Fix sigsegv in deferred loading #1022
  • apfd 1.0.2
    * PHP-7.2+ compatibility * PHP-8.0 compatiblity
  • xhprof 2.2.1
    - Support PHP 8.0 beta4
  • swoole 4.5.4
    Backward compatibility Break --- * Modify SWOOLE_HOOK_ALL to contain SWOOlE_HOOK_CURL (#3606) (@matyhtf) * Remove ssl_method and Support ssl_protocols (#3639) (@Yurunsoft)

    New APIs

    • Added firstKey and lastKey (swoole/library#51) (@sy-records)

    Enhancement

    • Added open_websocket_ping_frame, open_websocket_pong_frame (#3600) (@Yurunsoft)

    Fixed

    • Fixed fseek ftell file larger than 2G bug (#3619) (@Yurunsoft)
    • Fixed Socket barrier bug (#3627) (@matyhtf)
    • Fixed http proxy handshake bug (#3630) (@matyhtf)
    • Fixed a problem with parsing the HTTP header when send chunk data (#3633) (@matyhtf)
    • Fixed zend_hash_clean assertion failure (#3634) (@twose)
    • Fixed can't remove broken fd from event loop (#3650) (@matyhtf)
    • Fixed crash when receiving invalid packet (#3653) (@matyhtf)
    • Fixed array_key_last (swoole/library#46) (@sy-records)

    Kernel

    • Code optimization (#3615) (#3617) (#3622) (#3635) (#3640) (#3641) (#3642) (#3645) (#3658) (@matyhtf)
    • Reduce unnecessary memory operation to improve write performance (#3620) (@matyhtf)
    • Refactor aio (#3624) (@Yurunsoft)
    • Added readlink/opendir/readdir/closedir hook (#3628) (@matyhtf)
    • Improve swMutex_create, add SW_MUTEX_ROBUST (#3646) (@matyhtf)
  • oauth 2.0.7
    * PHP 8 compatibility
  • parallel 1.1.4
    - Fix #103: memory leaks in Sync - Fix #112: broken type hinting and instanceof operator - Fix #139: crash with opcache enabled
  • xdebug 2.9.7
    Wed, Sep 16, 2020 - xdebug 2.9.7

    = Fixed bugs:

    • Fixed issue #1839: Add keepalive options to debugging socket
  • mailparse 3.1.1
    - Fixed bug #74215: Memory leaks with mailparse (cmb) - Fixed bug #76498: Unable to use callable as callback (cmb) - Compatibility with 8.0.0beta4
Powered by Gewgley