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

Examples of Dependency Injection in PHP With Symfony Components
Aug 08, 2018 @ 11:53:33

On the TutsPlus.com site today they've posted a tutorial sharing some examples of dependency injection using the Symfony DependencyInjection component.

In this article, we'll look at some examples of using the Symfony DependencyInjection component. You'll learn the basics of dependency injection, which allows cleaner and more modular code, and you'll see how to use it in your PHP application with the Symfony component.

The tutorial starts by introducing the component and what kind of functionality it includes to help register and fetch services on demand. It then walks through the installation (via Composer) and the installation of other optional related packages. It then dives into the code, showing how to put the package to use to register a new service and pull it back out to use. The article then moves on and shows a more "real world" example with services that have dependencies and configuring it in a YAML configuration file.

tagged: dependency injection tutorial symfony component introduction dependencies

Link: https://code.tutsplus.com/tutorials/examples-of-dependency-injection-in-php-with-symfony-components--cms-31293

Sameer Borate:
Using the TOML configuration format in your applications
Aug 01, 2018 @ 12:54:59

In this new post to his site Sameer Borate looks at using the TOML configuration file format in a PHP application.

As any one who has programmed knows about configuration files. Configuration files are mostly text files used to configure the parameters and initial settings for computer programs – mostly user applications, operating system settings.

[...] In this post we will look into parsing TOML files in PHP. TOML is a configuration file format that is intended to be easy to read due to its obvious semantics and is designed to map unambiguously to a dictionary data structure. “TOML”, the name, is an acronym for “Tom’s Obvious, Minimal Language” referring to its creator Tom Preston-Werner.

He starts with an example of a configuration file in the TOML format and, following the installation/used of the yosymfony/toml library, the result of it being parsed. He also includes an example of using the same library to build out a TOML configuration and dump it to a string for output.

tagged: toml configuration file format introduction tutorial package

Link: https://www.codediesel.com/data/using-the-toml-configuration-format-in-your-applications/

Examples, Tools and Resources for Regular Expressions
Aug 01, 2018 @ 11:27:05

On the Pineco.de blog there's a tutorial posted introducing regular expressions and providing some examples and links to external resources/tools to help put them to use in your code.

Using Regular Expressions is not easy. Mostly we have the feeling we need to learn a new language on the top of those we already know. But, the power and the flexibility that RegEx provides, make it worthy to learn. Take a look at some useful patterns, tools, and sources!

The examples they provide show the matching all the words and matching all the content between specified tags. They end the post linking to several helpful tools including the Laracasts regular expression video and the regexr.com testing tool.

tagged: regularexpression tool resources tutorial introduction example

Link: https://pineco.de/examples-tools-and-resources-for-regular-expressions/

Laravel News:
Introduction to TOML Configuration in PHP
Jul 30, 2018 @ 09:37:31

On the Laravel News site today there's a tutorial posted introducing you to TOML configuration, a new configuration file structure that's designed to be easy for humans to read and highly flexible (all while staying relatively simple).

TOML is a configuration file format language that is intended to be minimal and easy to read. TOML stands for “Tom’s Obvious, Minimal Language,” which refers to the creator Tom Preston-Werner.

[...] TOML aims to be a minimal configuration file format that’s easy to read due to obvious semantics. TOML is designed to map unambiguously to a hash table. TOML should be easy to parse into data structures in a wide variety of languages.

In order to work with it in PHP (since there is no native support) they show you how to install the yosymfony/toml package. The tutorial then walks you through an example TOML configuration file and what the result of using the package to parse it looks like. It then takes it a step further an converts one of the database configuration files for a Laravel application to the TOML format. It also shows the reverse - using the package to create a TOML file and the resulting output.

tagged: toml configuration file custom format introduction tutorial

Link: https://laravel-news.com/toml-configuration-in-php

How to Create Custom CLI Commands Using the Symfony Console Component
Jul 24, 2018 @ 10:54:37

On the TutsPlus.com site there's a new tutorial posted showing you how to use the Symfony Console component to create custom CLI commands.

In this article, we're going to explore how you could create custom command-line interface (CLI) commands in your PHP applications using the Symfony Console component. After installing the necessary libraries, we'll create a few handful of examples to demonstrate the concepts of the Console component.

In fact, this component is used by several PHP frameworks to develop CLI applications, and a few popular frameworks are already using this component as a starting point.

The tutorial starts with a brief introduction to the Console component and what kind of features it offers. Following this it includes the instructions to get the component installed, configured and shows the creation of a first "hello world" command. With some of the basics in place, the tutorial then moves on to a more real-world example showing the creation of a "clear cache" command that includes a "groups" input option.

tagged: tutorial symfony command introduction component

Link: https://code.tutsplus.com/tutorials/how-to-create-custom-cli-commands-using-the-symfony-console-component--cms-31274

Sameer Borate:
How do MVC routers work
Jul 24, 2018 @ 09:21:08

In a quick post to his site Sameer Borate looks more in-depth at how MVC routers work to translate the incoming request and point it to the right code for handling.

A MVC Router class or a Dispatcher inspects the URL of an HTTP request and attempts to match individual URL components to a Controller and a method defined in that controller, passing along any arguments to the method defined.

He provides the code for a simple example, matching the path directly from $_SERVER['PATH_INFO'] to a key name in a set of routes. Routes are added to the list via an add_routes method and are only matched directly. This is the most basic version of a router with many other frameworks stacking features on top including wildcard matching, optional parameters and regular expression matching.

tagged: mvc router functionality introduction path match

Link: https://www.codediesel.com/php/how-do-mvc-routers-work/

Kevin Smith:
What's So Great About OOP?
Jul 12, 2018 @ 10:28:48

In a post to his site Kevin Smith wonders "what's so great about OOP?". In it, he goes back to the basics of OOP (object-oriented programming) and keeps it simple, avoiding more advanced OOP-related topics.

One of my core responsibilities as a senior software engineer is mentoring the junior engineers and interns at work. [...] Recently a question came up with our new interns while talking through the design of a feature: What is object-oriented programming? How is it different from what we're doing now, and why should we write code that way?

I wanted to find a fundamental explanation to send them for later, but nearly everything I came across immediately jumped into SOLID or design patterns or advanced concepts of some kind.

He starts from the beginning, where most PHP developers cut their teeth with the language: procedural programming. He provides some (non-OOP) examples of this, making use of simpler functions rather than objects and methods. He then moves on to compare this with OOP. He talks about how it's more than just a different syntax (a shift in thinking really). He refactors his previous example to use objects and methods. He finishes up the post answering one of his original questions: what's the real benefit of OOP over procedural programming.

tagged: oop objectorientedprogramming tutorial introduction procedural difference

Link: https://kevinsmith.io/whats-so-great-about-oop

Matt Sparks:
PHP Reflection
Jul 02, 2018 @ 12:42:41

Matt Sparks has posted a tutorial to his site introducing one of the more powerful but often misunderstood parts of the PHP language: its Reflection functionality.

Beginning work on the Analyze PHP framework, specifically the container, brought reflection to my awareness. Before that I had maybe heard the term, but I definitely hadn’t used it intentionally. Although it sounds like a scary computer science concept, it’s not. It’s actually quite simple:

Reflection is the ability of a computer program to examine, introspect, and modify its own structure… That’s it.

He starts the tutorial by introducing some of the basics concepts behind reflection in PHP and what it has to offer. He then shares some code examples of it in action getting class properties and getting the constructor. He also shows the use of other built-in PHP functions getting the class methods and the class name.

tagged: reflection tutorial introduction class method name properties constructor

Link: https://developmentmatt.com/php-reflection/

Sameer Borate:
PHP Simple HTML DOM Parser Script
Jun 21, 2018 @ 09:26:38

Scraping content from other sites (while slightly controversial) can be a helpful way to pull information into your application without the overhead of manual interaction. In this new post to his site Sameer Borate shows how to use a DOM parser to extract data from a remote site.

In this post I have explained some elements to scrap data from external websites. Simple HTML DOM parser is a PHP 5+ class which is useful to manipulate HTML elements. This class can work with both valid HTML and HTML pages that do not pass W3C validation. You can find elements by ids, classes, tags and many more. You can also add, delete or alter DOM elements. The only one thing you should care about is memory leaks – but you can avoid memory leaks as explained later.

He starts by walking through some of the basics of creating a new instance of the class and loading the content (either as a string or as a file) to be parsed. He then give several examples of how to query the contents of the document and locate multiple or single elements (including the use of CSS-type selectors for fuzzy attribute matching). He finishes out the post showing how to access element attributes and append content back to the original HTML.

tagged: simpledom parser script tutorial introduction html dom

Link: https://www.codediesel.com/php/php-simple-html-dom-parser-script/

Self-Host Your Team’s Git With Gitolite
Jun 15, 2018 @ 11:17:12

On the php[architect] site they've shared a post from their most recent issue (June 2018 - Command and Control) from author Gabriel Zerbib covering self-hosting Git with Gitolite.

If you wish to set up a private Git server for your personal, work, or team projects, but favor free software and simple architecture, or don’t want a service hosted by a third party, then Gitolite is the solution for you.

The article starts with a brief history of Git and a listing of some of the options for hosting private Git repositories. It then gets into talking about Gitolite, a "collection of Perl scripts, wisely arranged to allow easy management of Git repositories served over the SSH protocol." He talks through some of the features that come along with the tool and how to get it installed. With that setup, he shows how to use it as a Git hosting platform, how to configure repositories, create and configure users, and perform backups. The post ends with some helpful troubleshooting tips and a look at Gitolite's hook system.

tagged: gitolite phparch june2018 article git hosting tutorial introduction

Link: https://www.phparch.com/2018/06/self-host-your-teams-git-with-gitolite/