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

Tomas Votruba:
How to Teach Your Team Private Method Sorting in 3 mins
Nov 05, 2018 @ 16:28:25

Tomas Votruba has written up a new post to his site covering the sorting of private methods in classes and why he considers it important to the quality of your code.

When I started PHP in 2004, all you had to do is to learn a few functions to become the most senior dev in your town. Nowadays, devs have to learn a framework, IDE and coding patterns to get at least to an average level.

Instead of reading 346 pages of Clean Code, you need to produce code and learn as you read it at the same time. There will be never less information than it is today. That's why effective learning is a killer skill. Today we learn how to sort private methods in 2 mins.

He starts off by talking about why private method ordering is important, giving an example of a simple class with several private methods. He suggests that, by ordering private methods within the class more related to the functionality that uses them, developers in the system can more easily relate the functionality. He also includes an example of his the PrivateMethodOrderByUseFixer coding standard service to automate this in your code.

tagged: tutorial private method ordering opinion code clarity

Link: https://www.tomasvotruba.cz/blog/2018/11/01/how-teach-your-team-private-method-sorting-in-3-mins/

TutsPlus.com:
Get Started With Pusher - Using Private Channels
Aug 09, 2018 @ 16:56:46

TutsPlus.com has posted the next part of their series covering the use of "channels" with Pusher, the real-time messaging service. In the previous article they introduced Pusher and its "channels" functionality to build a simple real-time chat. In this new tutorial they show how to modify this application to use private channels.

n this series, we've been learning about Channels from Pusher, a platform that allows you to give your users the seamless real-time experience they want.

Private channels provide your applications with a secure, private medium for publishing messages. The best part is how easy it is to implement and use private channels for your apps.

Much like the previous article, they've included a screencast of the entire process right along side the text version. The tutorial walks you through setting up the server (the ChannelsController), the endpoint for client authorization and the changes to make to the client itself.

tagged: pusher private channel private tutorial series part2

Link: https://code.tutsplus.com/tutorials/get-started-with-pusher-using-private-channels--cms-31253

TutsPlus.com:
Get Started With Pusher - Using Private Channels
Aug 09, 2018 @ 16:56:46

TutsPlus.com has posted the next part of their series covering the use of "channels" with Pusher, the real-time messaging service. In the previous article they introduced Pusher and its "channels" functionality to build a simple real-time chat. In this new tutorial they show how to modify this application to use private channels.

n this series, we've been learning about Channels from Pusher, a platform that allows you to give your users the seamless real-time experience they want.

Private channels provide your applications with a secure, private medium for publishing messages. The best part is how easy it is to implement and use private channels for your apps.

Much like the previous article, they've included a screencast of the entire process right along side the text version. The tutorial walks you through setting up the server (the ChannelsController), the endpoint for client authorization and the changes to make to the client itself.

tagged: pusher private channel private tutorial series part2

Link: https://code.tutsplus.com/tutorials/get-started-with-pusher-using-private-channels--cms-31253

Mark Baker:
Using PHP Anonymous Classes as Package Private Classes
Jun 26, 2018 @ 20:09:36

Mark Baker has a post to his site about some of the interesting things you can do with anonymous classes, focusing on their use outside of testing (as he has in previous articles).

I’ve written before about the benefits of using PHP’s Anonymous Classes for test doubles; but Anonymous Classes also have potential usecases within production code as well. In this article I’m going to describe one such usecase that can be particularly useful within libraries, and that is replicating the access of Package Private (in Java), or Protected Internal Classes (as per C#).

He briefly explains what the package private/protected internal classes functionality entails before getting into his own use of the method with the PHPExcel/PHPSpreadsheet packages. He defines how he thinks the system should be structured and the isolation the anonymous classes would provide (without having to make whole separate classes just for that). He creates a class that has all public methods accessible but cannot be instantiated from outside the library. He shares some example code to illustrate his point, walking through each step to show what it's doing and how.

tagged: anonymous class package private class tutorial phpexcel

Link: https://markbakeruk.net/2018/06/25/using-php-anonymous-classes-as-package-private-classes/

Tomas Vortuba:
How to Test Private Services in Symfony
May 18, 2018 @ 16:21:39

Tomas Vortuba has a tutorial posted to his site showing you how to test private services in Symfony in unit tests for pre-4.1 Symfony installations (it has been resolved via simpler testing methods in Symfony 4.1 with the FrameworkBundle).

2 versions of Symfony are affected by this dissonance between services and tests. Do you use Symfony 3.4 or 4.0? Do you want to test your services, but struggle to get them in a clean way?

Today we look at possible solutions.

He starts with an example of the error you'd face if you tried to pull a service directly from the container that was marked as private. While you can specifically make it public in the yaml configuration, this potentially means doing that for all of the services you need to test. While this might work for smaller projects, it's unmaintainable for larger ones. He then shares some other options that could help resolve the issue including the one he ended up on: a compiler pass. He gets into a bit of detail on the changes this would require and where the "magic" is that lets it work.

tagged: test unittest private service symfony tutorial compiler pass

Link: https://www.tomasvotruba.cz/blog/2018/05/17/how-to-test-private-services-in-symfony/

Pineco.de:
Hosting Private Laravel Packages on GitLab
Dec 19, 2017 @ 18:58:27

On the Pine site they've posted a quick tutorial showing how to host private packages on Gitlab, in their case it's for Laravel-related packages but it would work with any project making use of Composer for package management.

When we want to restrict the access to the package we made but we don’t want to pay for a service like Private Packagist, we can use tagged: hosting gitlab private package accesstoken tutorial composer configuration

Link: https://pineco.de/hosting-private-laravel-packages-gitlab/

Fabien Potencier:
Symfony Flex Private Repositories
Nov 27, 2017 @ 17:45:25

Fabien Potencier has a new post to his site covering the addition of support for private repositories to the features Symfony Flex provides.

Many Flex early adopters asked for it. The Symfony Flex server now supports private recipes repositories as announced during my keynote at SymfonyCon Cluj.

Creating a repository for your private recipes is easy. Create a regular Github repository (probably a private one) to store the recipes. The directory structure is the same as for the official Flex recipes repositories. Then, register the repository as a recipes repository. Done.

The private repositories will behave just like the other public ones in your application. You can also use them to override aliases. There are a few differences between public and private, however, like auto-merge not being supported.

tagged: symfony symfonyflex private repository support addition

Link: http://fabien.potencier.org/symfony4-flex-private-repositories.html

Exakat Blog:
Make everything private in your PHP classes
Oct 06, 2017 @ 14:25:25

In a new post to the Exakat blog they propose an interesting idea: making everything private in your PHP classes with the basic idea being that you can more easily move from a place with more control (private) to less control (protected/public).

It is a good recommendation to make everything private in a class : constants, methods, properties. With private, comes a tighter control on the element : no one from outside may use it, limiting the unwanted impact on the object. Of course, some of the class has to be accessible from the outside, or the object may only be manipulated as a token.

[...] Eventually, when the code matures, it becomes desirable to apply the above principle of encapsulation. This helps keeps the code clean and made of independent components. This is the beginning of a long hunt.

They show how the results look for an Exakat scan of a class and go through each of the results touching on class constants, methods and properties. It also catches when a class property is a "constant" and not modified - or able to be modified - by any means. The post ends with a recommendation to "update your code with your brain" based on the interpretation of the results.

tagged: private visibility class exakat scan results recommendation

Link: https://www.exakat.io/make-everything-private-php-classes/

Freek Lijten:
Final, private, a reaction
Jun 21, 2016 @ 15:39:37

In response to a few other posts about the use of "final" in PHP development, Freek Lijten has posted some of his own thoughts and some of the things he came to realize about its use in his own development.

I read a blog by Brandon Savage a couple of weeks ago and it triggered some thoughts. He refers to a blog by Marco Pivetta which basically states "Final all the things!". Brandon comes back with a more mild opinion where he offers the notion that this approach might be overkill. Since both posts got me thinking I tried to organise my thoughts on this in the following post.

Freek talks about a pretty common trend in the PHP world: the very rare use of "final". He suggests that "extension" of classes is a bad idea (or at least should be used a lot less) and how he has seen it commonly misused. He then shares two reasons why he thinks "final" is a good idea, mostly centering around how easy it is and how the Open/Closed principle applies. In the end, he notes that he'll be trying to use more "final" in the future and see where it takes him and his code.

tagged: final private reaction development practice class oop openclosed

Link: http://www.freeklijten.nl/2016/06/17/Final-private-a-reaction

Leonid Mamchenkov:
Adventure in composer private repositories
Apr 22, 2016 @ 14:19:44

In this new post to his site Leonid Mamchenkov talks about some of his "adventure with Composer private repositories" in some of his deployment work with CakePHP 3 applications.

As good as the Packagist is, there is often a need for a repository or a package elsewhere. Whether it’s a commercial library, or sensitive corporate code, having an ability to store it outside of public eye and handle with the same ease and the same tool as the rest of the dependencies is a very welcome feature.

[...] We are setting up similar development and deployment process, but now for CakePHP-based projects. Things are much easier, since CakePHP 3 natively supports composer for the application itself and for its plugins. But we still have the need for private repositories here and there, so we follow the same setup as we did for WordPress.

Unfortunately he was getting a RuntimeException when he was trying to pull in a plugin through the same private repository workflow. Not only had he not seen the error before but the autoloader was configured as defined and other plugins were working with the same structure. As it turns out, it was the composer.json of the main application repository that was the problem. He includes the fix he made to the configuration on a sample CakePHP 3 project, showing how to switch it to a "vcs" type for more correct handling.

tagged: composer private repository issue runtime exception composerjson configuration

Link: http://mamchenkov.net/wordpress/2016/04/21/adventure-in-composer-private-repositories/


Trending Topics: