Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Christian Scheb:
PHPStorm Inspections for your Continuous Integration Process
Feb 27, 2019 @ 21:24:33

In a new post to his site Christian Scheb has written up a guide to help you set up inspections in PHPStorm to help make your continuous integration process simpler.

Did you know that PHPStorm (or any other Jetbrains IDE) can run inspections from command line and generate XML files for the results? This is a great “hidden” feature of those IDEs and machine-readable output means it can be somehow integrated with a continuous integration (CI) process. So let’s do this!

He walks you through the full process to get the integration set up to easily report the results of various code inspections:

  • Setting Up PHPStorm on a Server
  • Plugin installation (such as the PHP annotations checker)
  • Running the inspections (including configuration)
  • Publishing the result

All commands and configuration examples are included.

tagged: phpstorm continuousintegration inspection tutorial setup configure

Link: https://www.christianscheb.de/archives/808

Leonid Mamchenkov:
Refactoring.Guru : Design Patterns + PHP
Feb 27, 2019 @ 20:52:17

In a new post to his blog, Leonid Mamchenkov has linked to a resource that aims to help developers refactor their code to use best practices and design patterns: Refactoring.Guru.

Refactoring.Guru is a great resource for learning about refactoring best practices and design patterns. A lot of the website’s content is also available as Dive into Design Patterns ebook.

Today I came across this GitHub repository, which makes this resource even better specifically for PHP developers. Yup, that’s right, the GitHub repository features all code examples written in PHP 7.3, making it super easy to jump into coding.

The repository includes a Composer configuration to pull in some analysis tools and includes examples of about twenty different design patterns in use.

tagged: refactor designpattern ebook resource github tutorial

Link: http://mamchenkov.net/wordpress/2019/02/26/refactoring-guru-design-patterns-php/

Sergey Zhuk:
Building a RESTful API Using ReactPHP and MySQL
Feb 25, 2019 @ 18:56:37

In a recent post to his site, Sergey Zhuk walks through the process for building a REST API with ReactPHP and MySQL and a bit of help from a simple routing package to handle the requests.

Today we will be looking at creating a RESTful API using ReactPHP, MySQL and nikic/FastRoute. Let’s look at the API we want to build and what it can do.

He then steps through the development of the REST API:

  • showing the file structure of the resulting application
  • installing dependencies
  • the code to set up the HTTP server for handling requests (using React)
  • building out the database with a user table

He then gets into the main part of the tutorial, showing the build out of each of the routes for the CRUD operations (Create, Read, Update, Delete). He provides both the code to make the endpoint work and examples of the requests they handle.

tagged: rest api tutorial reactphp mysql fastroute

Link: https://sergeyzhuk.me/2019/02/18/restful-api-with-reactphp-and-mysql/

Rob Allen:
Using img2lambda to publish your Serverless PHP layer
Feb 25, 2019 @ 17:45:24

Rob Allen has published another post covering the use of serverless technology and PHP to run your applications. In this new post he shows how to use img2lambda to publish your Serverless PHP layer out to an AWS Lambda instance.

[The] img2lambda tool will take the layers of a Docker container and convert them to AWS layers for use in Lambda.

I poked around with Clare’s example and updated my lambda-php project in order to understand how it works. I also rewrote my runtime’s bootstrap to make it clearer.

The clever thing from my point of view is that you can build your PHP runtime layer locally using Docker and then publish the layers to AWS for use in your Lambda functions. This means you can now use the layer in different projects and have them all reference the same PHP runtime.

He digs deeper into the tool, looking at the "magic" happening under the covers using Docker. He provides an example of the Dockerfile it creates and walks through what it does. He then shows how to create the layer in AWS and use a serverless framework and a PHP runtime to execute the "hello world" application. He wraps up the post showing how to test it locally, building from the Dockerfile and using a docker run on the result with simple user input.

tagged: tutorial img2lambda docker package serverless layer aws

Link: https://akrabat.com/using-img2lambda-to-publish-your-serverless-php-layer/

Matt Glaman:
Writing better Drupal code with static analysis using PHPStan
Jan 11, 2019 @ 18:09:23

Matt Glaman has written up a post for his site showing how you can write better Drupal code using PHPStan, the PHP static analysis tool.

PHP is a loosely typed interpreted language. That means we cannot compile our scripts and find possible execution errors without doing explicit inspections of our code. It also means we need to rely on conditional type checking or using phpDoc comments to tell other devs or IDE what kind of value to expect. Really there is no way to assess the quality of the code or discover possible bugs without thorough test coverage and regular review.

If you use PhpStorm, you will notice all of their helpers which analyze your code and add static analysis. [...] That's awesome. It's pretty amazing that PhpStorm and a few plugins can give us some stability in our PHP code.

While the functionality in PhpStorm is useful, there are some pitfalls including the fact that everyone would have to use PhpStorm. He makes the suggestion that PHPStan can effectively replace these helpers and, with a bit of customization, provide just as much quality control for your Drupal code. He links over to a custom PHPStan extension for Drupal and an example YAML configuration. He also includes helpful tips around bootstrapping the autoloader, return typing and changes it provides for using the entity manager.

tagged: static code analysis drupal tutorial phpstan extension

Link: https://glamanate.com/blog/writing-better-drupal-code-static-analysis-using-phpstan

Tomas Votruba:
9 Steps to Migrate From Jekyll to Statie
Jan 11, 2019 @ 17:22:58

In a new post to his site Tomas Votruba walks you through the process he followed for moving his site [away from the Jekyll static site generator over to Statie], PHP-based static site generator.

Jekyll is great to start for micro websites like gomonorepo.org and <a href="https://gophp71.org/>gophp71.org from Jekyll to Statie. Can new init command make this piece of cake? And what needs to be done next?

He goes through each step of the process (nine of them), providing code and configuration examples along the way:

  • Create Basic Statie Structure
  • Move Source files to /source Directory
  • Move Parameters Files Under parameters > [param name] Sections
  • Upgrade Absolute Links to Moved Files
  • Load Moved YAML Files in statie.yml
  • Remove site.data. and use Variables Directly
  • Setup Github Pages deploy in Travis
  • Clean Metadata from Headers

The final step in the process are the commands to run the project locally and ensure that everything it working as expected before deployment.

tagged: tutorial migration jekyll statie static generator

Link: https://www.tomasvotruba.cz/blog/2019/01/10/9-steps-to-migrate-from-jekyll-to-statie/#4-upgrade-absolute-links-to-moved-files

Pineco.de:
Notify Locked Out Users in Laravel
Jan 07, 2019 @ 19:17:27

On the Pineco.de blog they've posted a tutorial for the Laravel users out there showing how to notify locked out users making use of functionality already included with the framework.

Laravel offers a nice feature, that locks out the users that attempted to login too much. It’s a nice way to prevent brute force logins. But how can we notify the user, when the lockout happens? Maybe it wasn’t the user who attempted to log in.

The tutorial starts with the details on setting up the listener to capture the Lockout event and pass it off to a UserLockedOut class. Once this is created, they show how to use this class and, via the included "notification" system in Laravel, send an email to the user in question with more information about their account being locked.

tagged: laravel tutorial user lockout notification

Link: https://pineco.de/notify-locked-out-users-in-laravel/

php[architect]:
It’s About Time
Jan 07, 2019 @ 18:08:02

On the php[architect] site they've shared an article from their December 2018 edition by Colin DeCarlo and issues with dates and times that most developers deal with at some point in their careers.

As applications scale and gain adoption, dates and time become much more of a concern than they once were. Bugs crop up, and developers start learning the woes of time zones and daylight saving time. Why did that reminder get sent a day early? How could that comment have been made at 5:30 a.m. if the post didn’t get published until 9:00 a.m.? Indiana has how man time zones?!

Luckily, PHP developers have the tools they need to face these problems head-on and take back control of their apps.

The article covers some of the basics of "time" and some of the concepts that PHP uses to measure it. It then introduces the different time functionality that PHP offers including timestamps and functions like strtotime and date as well as the DateTime handling. They dig into this last one in more detail before talking about timezones and date arithmetic.

tagged: article phparchitect magazine date time datetime introduction tutorial

Link: https://www.phparch.com/2018/12/its-about-time/

TutsPlus.com:
How to Use AJAX in PHP and jQuery
Jan 07, 2019 @ 17:40:40

The TutsPlus.com site has a new tutorial posted showing you how you can use PHP, jQuery and AJAX together to help make the overall user experience of your application better and more responsive.

Today, we’re going to explore the concept of AJAX with PHP. The AJAX technique helps you to improve your application's user interface and enhance the overall end user experience.

The post starts with an introduction to AJAX - what it is, how it's commonly used and how the normal requests flow. They then show how it works with normal "vanilla" Javascript (no jQuery) and how that compares to the jQuery version. It then dives into the real-world example script, showing how to create a form that sends login information to the backend for evaluation via a POST request.

tagged: ajax tutorial jquery login form introduction

Link: https://code.tutsplus.com/tutorials/how-to-use-ajax-in-php-and-jquery--cms-32494

Tomas Votruba:
How To Convert All Your Symfony Service Configs to Autodiscovery
Jan 03, 2019 @ 17:51:26

Tomas Votruba has a tutorial posted to his site showing you how to update your Symfony application to make all of your services use auto-discovery rather than hard-coded configuration settings.

Do you use Symfony autodiscovery services registration everywhere and your configs have no extra lines? Skip this post and rather read another one.

But if you have many configs with manual service registration, tagging, and autowiring, keep reading. I'll show you how you can convert them easily be new Symplify package.

He starts off by talking about a few e-commerce projects he's been working with lately that define service configurations manually. He then mentions a package that's been created to help convert these over easily to autodiscovery rather than having to change them one by one. He provides the instructions to use this package and mentions some of the things that could go wrong in the conversion process to keep an eye out for.

tagged: tutorial convert symfony configuration autodiscovery package cli

Link: https://www.tomasvotruba.cz/blog/2018/12/27/how-to-convert-all-your-symfony-service-configs-to-autodiscovery/


Trending Topics: