Codecourse.com: Social Network with PHP: Introduction (Video Series)

Codecourse.com has released a video series walking you through the creation of a simple social network site with PHP, Laravel and Bootstrap.

[This tutorial shows you how to create] a social network built with Laravel and Bootstrap. Authenticate, add and accept friend requests, post to a timeline, reply to and like statuses.

The videos are pretty "bite sized" at just a few minutes each, but they walk you through all of the code you’ll need to get the site up and running as well. There’s 36 videos in the playlist but with the playlist on auto-play you’ll go through them quickly.

PHPDeveloper.org

Larry Garfield: Just how insular is the PHP community?

In this post to his site Larry Garfield takes a look at how insular the PHP community is and, instead of just expressing personal opinions on the subject, looks at data around some of the "same old faces" comments recently pointed at the PHP community.

Periodically, there is a complaint that PHP conferences are just „the same old faces“. That the PHP community is insular and is just a good ol‘ boys club, elitist, and so forth. It’s not the first community I’ve been part of that has had such accusations made against it, so rather than engage in such debates I figured, let’s do what any good scientist would do: Look at the data!

He starts with a look at the Joind.in conference feedback site and the data it has to offer. This is what he’s basing is research on, pulling the information from the site’s JSON API to work through it locally. While the detailed information is attached on another page he does share a summary of his findings. Interestingly enough, just a bit over half of the speakers at these events were first-time speakers. His results show that there’s an average of 13.1% of new speakers at each event too.

PHPDeveloper.org

Andrew Embler: Q&A: Using Composer in a concrete5 Package

Andrew Embler has posted a guide to his site showing you how to use Composer with concrete5 to integrate third party libraries quickly and easily. concrete5 is an open source content management system under the MIT license and is flexible and easy to extend.

Let’s say I’m creating a statistics package and I want to use LavaCharts in it. For those who don’t know, LavaCharts is a PHP library that abstracts Google’s JavaScript Chart API to PHP. Instead of writing JavaScript, you build your charts with object-oriented PHP. It’s nice. LavaCharts is available through Composer, so I’ll include it that way.

He uses this particular package as an example, showing you how to create the composer.json file to include the LavaCharts library and run Composer to install it. He then shows the integration of the package with the concrete5 CMS instance, including the Composer autoloader in the "on start" handling. From there it’s just a matter of referencing the library via its namespace and using it to populate and generate the resulting chart.

PHPDeveloper.org

Phil Sturgeon: Avoid Hardcoding HTTP Status Codes

Phil Sturgeon has a post to his site with a good recommendation for those working with APIs and those "magic numbers" that are HTTP status codes – avoid hard coding them in your applications and tests.

A lot of things in programming are argued to death, but one subject where people almost unanimously agree is that magic numbers can be a pain in the ass, and they should be avoided whenever possible. Sadly when it comes to HTTP status codes, people keep on hardcoding them, and it leads to all sorts of confusion. […] What is 409? If you answer without looking it up on Dash or HTTP Status Dogs then you are a machine.

He shows two implementations of this idea, one in Ruby and the other in Symfony, where the status code value is represented by a constant rather than by a number. The constant correlates to the HTTP status code (number) but the constant makes it easier to read and understand the code. He points out two libraries that can be substituted into your current testing to replace those hard coded values with more expressive versions: lukasoppermann/http-status and Teapot.

PHPDeveloper.org

PHPClasses.org: How to Create a PHP C Extension to Manipulate Arrays Part 2: Adding ArrayAccess and

Dmitry Mamontov has posted the second part of his "How to Create a PHP C Extension to Manipulate Arrays" series on PHPClasses, building on part one and adding in the ArrayAccess and Traversable interface functionality.

In the first part of this article we learned how to create an extension for PHP written in C to create a class that works like arrays. However, to make the class objects really behave as arrays you need to implement certain interfaces in the class.

Read this article to learn how to make a PHP class defined by a C extension implement ArrayAccess and Traversable interfaces, as well understand how to solve problems that you may encounter that can make your extension slower than you expect.

He takes the class he defined in part one and walks you through the addition of the two interfaces. He shows you where they’re defined in the PHP source, what the code looks like and how they integrate with the class. He also shows you how to customize the object class handlers, making it possible to use the custom class (object) as an array. Adding Traversable is easier, adding an iterator return method that allows for the data internal to the class to be iterated through.

PHPDeveloper.org

Revath S Kumar: PHP : Service classes

Revath S Kumar has a post to his site that wants to help get you started writing service classes for your application. Service classes are useful when interacting with multiple pieces of data that need either interaction or correlation.

When I started with MVC in PHP, I used to write the whole logic in controller, then when I learned about skinny controllers fat models I reduced the code in controller and moved logic into models. But that was not enough. […] In order to make this more convenient and reusable I thought of abstracting the logic for creating the order into service classes. I got this idea of service classes from Ruby on Rails. So when I came back to PHP world I thought of using service classes.

He uses examples of service classes he’s written for a Yii framework based application, showing a before and after example of his "Orders" controller. He moves most of the logic from the controller (less reusable) into a service class that creates the order record based on the data its been provided. He uses exceptions to handle validation errors, making it simpler in the controller to catch multiple exception types in one place.

PHPDeveloper.org

That Podcast: Episode 21: The one with all the screen time

That Podcast, hosted by Dave Marshall and Beau Simensen, has posted their latest episode today: Episode #21 – The one with all the screen time.

Beau and Dave change gears and get to some family talk, discussing managing kids with devices and screen time, football/soccer, dance and swimming activities, Beau announces his new position with Monii.com, then the guys get back in their comfort zone and talk briefly about continuous integration services, docker and CQRS.

Other topics and people mentioned in this episode include Symfony Live London, the Three Devs & A Maybe podcast, Jeff Carouth, Circle CI and many more. You can listen to this latest episode either through the in-page audio player or by downloading the mp3 directly. Also be sure to subscribe to their feed and follow them on Twitter if you enjoy the show.

PHPDeveloper.org

Amine Matmati: Testing PDF content with PHP and Behat

In this post to his site Amine Matmati shows you how to use Behat (with a bit of additional PHP) to test the contents of a rendered PDF file.

If you have a PDF generation functionality in your app, and since most of the libraries out there build the PDF content in an internal structure before outputting it to the file system (FPDF, TCPDF). A good way to write a test for it is to test the output just before the rendering process.

Recently however, and due to this process being a total pain in the ass, people switched to using tools like wkhtmltopdf or some of its PHP wrappers (phpwkhtmltopdf, snappy) that let you build your pages in html/css and use a browser engine to render the PDF for you, and while this technique is a lot more developer friendly, you loose control over the building process.

He shows how to get all of the required software installed including the smalot/pdfparser library used to read in the contents of the PDF file. He initializes a Behat test directory and writes a simple test, checking for a string of some "Lorem ipsum" text in the document’s title and that it contains only one page. Some additional methods have to be created to integrate the PDF parsing and string location/page counting and code is included for each. When all the pieces are put in place, executing the test passes for both checks. You can find the code for the tutorial in this repository that also includes two sample PDFs to work with.

PHPDeveloper.org