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

TutsPlus.com:
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

Tomas Votruba:
Stylish and Standard Console Output with Symfony Style
Aug 07, 2018 @ 10:28:12

Tomas Votruba has continued his series covering the use of the Symfony Console component with a new tutorial. In this latest article he shows how to get "stylish and standard console output" using the output formatting included with the package.

Even if you don't use any component from Symfony or even installed one, you can use this trick in your PHP CLI App.

It's simple, provides standard and makes your output look like a design from Apple - useful and nice at the same time.

He starts by introducing the OutputInterface that the Symfony Console package includes and shows a few screenshots of the difference between normal console output and the Console component's look. He also covers the SymfonyStyle functionality that allows for even more fine-grained control over the input and output handling of your application. He finishes the post showing a few tips on integrating these styles into your command line application and setting it up to fetch SymfonyStyle as a service.

tagged: symfony console component tutorial series style output input

Link: https://www.tomasvotruba.cz/blog/2018/08/06/stylish-and-standard-console-output-with-symfony-style/

TutsPlus.com:
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

TutsPlus.com:
Set Up Routing in PHP Applications Using the Symfony Routing Component
Jul 16, 2018 @ 13:14:04

On the TutsPlus.com site today there's a new tutorial where they spotlight one of the components in the Symfony framework: the routing component. The tutorial outlines some of the basics about the component, installing it and putting it to use.

The Symfony Routing Component is a very popular routing component which is adapted by several frameworks and provides a lot of flexibility should you wish to set up routes in your PHP application.

If you've built a custom PHP application and are looking for a feature-rich routing library, the Symfony Routing Component is more than a worth a look. It also allows you to define routes for your application in the YAML format. Starting with installation and configuration, we'll go through real-world examples to demonstrate a variety of options the component has for route configuration.

The tutorial starts with the commands to get the component installed (via Composer) and other related components for YAML parsing, HTTP handling and configuration parsing. It then provides examples of:

  • setting up the instance and defining some basic routes
  • how route matching works
  • loading routes from a YAML file

The tutorial finishes with an example of an "all in one" router that pulls in the route configuration and creates a new Router instance with them ready and waiting to handle requests.

tagged: routing symfony component tutorial yaml configuration http

Link: https://code.tutsplus.com/tutorials/set-up-routing-in-php-applications-using-the-symfony-routing-component--cms-31231

Laravel News:
Introducing View Components in Laravel, an alternative to View Composers
May 16, 2018 @ 10:55:56

On the Laravel News site there's a new post covering a refactoring of view handling that's possible with recent versions of the framework: using view components instead of view composers..

In software development, one of the “best practices” is to create reusable code that can be implemented in different parts of your application if needed. [...] View composers allow you to move the logic outside your controller and pass the data to the specified set of views. [Using view components instead of composers lets you] reuse complex components using dynamic data on any view within your application.

To help illustrate the difference they set up a scenario of a blog with a "highlights" sidebar based on data from an API response. With view composers you could extract this logic out of the controllers and add it more automatically to the view itself. They point out that this can work for a majority of the situations there's another method that is even more flexible: a reusable component implemented directly on the view. He provides the complete code showing an examples of this components, including a custom Blade directive.

tagged: laravel tutorial view composer component refactor

Link: https://laravel-news.com/introducing-view-components-on-laravel-an-alternative-to-view-composers

Agustín Houlgrave:
A guide to a proper PHP Console Application
Feb 08, 2018 @ 11:14:28

On his Medium.com site Agustín Houlgrave has posted a tutorial with some suggestions about building PHP console applications correctly.

Googling this topic, I could only find official documentation on Symfony’s Console Component and some tutorials on quick building, but i’d like to write about making a real scalable console application that you could use in an actual production project. I’ll explain the reasons we do each of the things.

I like to write decoupled, reusable and as raw as possible code, so we’ll try to aim on that direction. Also, we’ll take advantage of all of the new features of PHP 7.

He decided on the combination of the Symfony Console Component and the Zend Service Manager to handle the use of the decoupled components. He then gets into the installation of the required packages and the initial code to create the Symfony command. He then sets up the Composer autoloading and the "factory" configuration for the command. From there he includes the code to build out the command runner and gives an example of executing the command and the output.

tagged: console command symfony tutorial zendframework servicemanager component

Link: https://medium.com/@a.houlgrave/a-guide-to-a-proper-php-console-application-325ef677faf1

Zend Framework Blog:
A new release of zend-db
Dec 07, 2017 @ 10:46:48

On the Zend Framework blog today Enrico Zimuel has posted an announcement about the zend-db component including a look at the new release and the future of the component.

Today, we released zend-db 2.9.0! This is our first new feature release in over 18 months, and contains 7 bug fixes, 6 new features, numerous unit test additions, and many documentation improvements.

zend-db is an important component of many PHP projects, and we know that its support is crucial for many people. As such, we allocated a number of weeks to triaging the various open issues and patches (more than 50) to ensure we would provide a stable release.

The post lists out the issues fixed and the features added, linking to the bugs that were files related to each. It then talks about the future of the component, noting that a v3.0 release is expected to come in 2018 and will include a lot of new features. This will help to make working with more modern features of the various databases easier directly from the code (without as much manual query creation or hackery). The post finishes with some thanks to those that contributed to this v2.9.0 release.

tagged: zendframework component zenddb database release future plan

Link: https://framework.zend.com/blog/2017-12-06-zend-db-2.9.0.html

Symfony Blog:
Interview with Pawel Jedrzejewski, founder of Sylius project
Oct 24, 2017 @ 13:45:01

The Symfony blog has a new post featuring an interview with Pawe? J?drzejewski, the founder of the Sylius project - an ecommerce platform based on the Symfony components.

Sylius, an e-commerce project based on Symfony components, recently released its 1.0.0 stable version. After several years of work and thousands of commits from hundred of contributors, Sylius is now ready to take the e-commerce world by storm. We chatted with Pawe? J?drzejewski, founder and leader of the project, to celebrate this milestone.

In the interview Pawe? answers questions about the project itself, why it stands out from some of the other ecommerce projects, the state of ecommerce and why they chose Symfony components as the base for the project.

tagged: symfony interview sylius ecommerce platform component

Link: http://symfony.com/blog/interview-with-pawe-jdrzejewski-founder-of-sylius-project

Sergey Zhuk:
Promise-Based Cache With ReactPHP
Sep 20, 2017 @ 10:11:55

Sergey Zhuk has written up a tutorial showing you how to implement promise-based caching with ReactPHP, a continuation of a previous post.

In the previous article, we have already touched caching (when caching DNS records). It is an asynchronous promise-based Cache Component. The idea behind this component is to provide a promise-based CacheInterface and instead of waiting for a result to be retrieved from a cache the client code gets a promise. If there is a value in a cache the fulfilled with this value promise is returned. If there is no value by a specified key the rejected promise returns.

He starts by defining the caching interface and how it would look in use to set/get a cache value. He shows how to update this with a "done" handler to output the value when the get is complete. He continues on showing how to use a fallback handler: either "otherwise" or "then". He also shows how these can be chained together to make more complex operations. The post ends with an example of this caching component in action and links to other library that use the same ideas.

tagged: promise cache reactphp get set tutorial component interface

Link: http://seregazhuk.github.io/2017/09/15/reactphp-cache/

Zend Framework Blog:
Logging PHP applications
Sep 13, 2017 @ 10:56:38

On the Zend Framework blog there's a new post in their series highlighting components of the main framework. In this new tutorial they look a the Zend-log component and how it can be used for logging in your application.

Every PHP application generates errors, warnings, and notices and throws exceptions. If we do not log this information, we lose a way to identify and solve problems at runtime. Moreover, we may need to log specific actions such as a user login and logout attempts. All such information should be filtered and stored in an efficient way.

[...] Zend Framework offers a logging component, zend-log; the library can be used as a general purpose logging system. It supports multiple log backends, formatting messages sent to the log, and filtering messages from being logged.

The tutorial then walks you through the installation of the component and some basic usage of it to write directory to the 'php://output' stream. It then shows you how to set up custom formatting on the message and a few other examples of it in use:

  • logging PHP events (errors/exceptions)
  • using the built-in data (level) filtering functionality
  • custom processors
  • working with multiple backends for storage

The post ends with a look at using the Zend-log package in either a traditional MVC application or one based more on middleware (like an Expressive application).

tagged: zendframework component zendlog logging tutorial mvc middleware

Link: https://framework.zend.com/blog/2017-09-12-zend-log.html