In a recent post Nate Krantz has shared some of his own methods around writing functional and unit tests.So...testing. That thing that everyone says is so important but you don't really learn about it in school. I've had some trials and tribulations with testing so I'm going to just dump out some thoughts here.
He starts with a bit of background on his own experiences in development and how he finally decided that testing would "solve everything". He started with unit tests (for a CodeIgniter application) and how he got them up and running. He talks about issues he found around dependencies (and static methods) and how he made use of mocks to reduce some of the issues with dynamic loading, at least how CodeIgniter does it. Unfortunately, this didn't work out as planned so he fell back to a test database and create more effective and simpler functional tests. Code examples are sprinkled through out the post to show how he was trying to solve the problem at different points in the process.Link: http://www.natekrantz.com/why-test-driven-development-rocks-sucks/
NetTuts.com has posted the next part of their "Programming with Yii2" tutorial series today. This new tutorial in the series focuses on the use of the timestamp behavior to assign the current date to an object (like for create or update dates).In this tutorial, we'll explore Timestamp Behaviors, which reduce the amount of code you need to write with each new model for the common operation of creating timestamps for inserts and updates. We'll also dive into the Yii2 source code, examining how a behavior is implemented.
He starts with a brief look at what behaviors are (a reminder for those that may have already read about the sluggable and blameable behaviors). He then gets into the Timestamp behavior specifically and how to apply it to the sample project's "Status" instances. He shows the updates needed for the behavior configuration and rules. He also looks inside the component at the code that makes it up and the "touch" method it provides.Link: http://code.tutsplus.com/tutorials/programming-with-yii2-timestamp-behavior--cms-23329
On the Bigcommerce Engineering blog there's a new post sharing a few tips for memory optimization in your PHP applications. This includes tips you can implement at a code level without too many changes to the server or the need for external services.Lately, I've been working on optimizing the memory of some of our backend PHP applications and wanted to share some of the tricks that I have come across, especially dealing with large set of data using PHP.
Each of their tips includes code to illustrate the technique:
- Always cap your internal in-memory caching
- Use layered caching
- (Freeing) DB Resources
- Free large blocks of memory
Some of the examples include output from the scripts showing the reduction (or non-growth) of the peak memory usage of the script.Link: http://bigeng.io/post/119546277718/php-memory-optimization
- PHP.net: Release of PHP 5.4.41 & 5.5.25
- Product & Support: Interview with Taylor Otwell
- FogCreek.com: How to Find, Hire, and Retain Developers - Interview with Cal Evans
- BeMyCTO.com: Why Doctrine ORM is not suited for PHP
- Site News: Popular Posts for the Week of 05.15.2015
- Matthew Weier O'Phinney: PSR-7 Accepted!
- Acquia Blog: Web Accessibility Tips for Developers - Part 2
- Sound of Symfony: Episode 8 - Concerning command buses
- Ross Tuck: How I Use Traits
- Run Geek Radio: Episode 003 - OpenWest Namebadges, Overtraining, Dev Salary & Freelance Rates, [...]
The SitePoint PHP blog has kicked off a new series about using the Laravel framework to create a basic CRUD application relatively easily.In this tutorial, we're going to build and run a simple CRUD application from scratch using Laravel 5.
The target audience for the tutorial are those completely new to the world of Laravel so they start at the beginning. He walks you through the creation of a new Laravel project and the database setup and configuration. He goes through the creation of "resourceful routing" and using the Laravel "artisan" command line tool to generate the matching controller. From there he talks about views and Blade templating followed by the creation and execution of the needed database migrations. The tutorial wraps up with a look at the model system included with Laravel and how they fit in with the Eloquent ORM.Link: http://www.sitepoint.com/bootstrapping-laravel-crud-project/
Matthew Weier O'Phinney has a recent post about recent work that's been done to split up the componenents in Zend Framework 2 into their own repositories and linked as dependencies.Today we accomplished one of the major goals towards Zend Framework 3: splitting the various components into their own repositories. This proved to be a huge challenge, due to the amount of history in our repository (the git repository has history going back to 2009, around the time ZF 1.8 was released!), and the goals we had for what component repositories should look like. This is the story of how we made it happen.
Matthew talks about the methods that were used to split things apart, even more so than they already were. While the components could be installed separately before, the methods used to get there were "cringeworthy". He talks about the different methods they've tried and the version bump issue that came with them, even when no changes were present. He talks about the ultimate goal of the refactor and the techniques to get there - a combination of grafts, subtree, subdirectory-filter and tree-filter through git. He covers some of the "stumbling blocks" they hit along the way including empty merge commits. The end result was a one-line command that could be executed and split out the provided component (well, with a lot of help behind the scenes).
He ends the post talking about the speed of the extraction process (hint: parallel processing is a happy thing), the ultimate results of the entire framework being split and a few lessons they learned along the way.Link: https://mwop.net/blog/2015-05-15-splitting-components-with-git.html
He suggests two options, running a small Node application or using the V8JS extension, and opts for trying the second option to meet his needs. He talks about the "why" of rendering server-side JS and gives a brief introduction to V8JS and the workflow he'll follow to use it. He helps you get this library via Composer to make working with it easier and provides an example of how to use it. After trying out this method, he then goes back to option #1, the small Node application (what he ended up choosing). He walks through the setup of this application, showing how to set it up inside a Lumen application and using Express to output the generated templates and data. He then hooks this into the PHP application via a simple HTTP client grabbing the results and pushing them back out to the page.Link: http://blog.frankdejonge.nl/rendering-reactjs-templates-server-side/
In the latest post to the PMG blog Chris Davis shows us how to create a Symfony application from scratch, that is without using the Symfony Standard repository/skeleton application.The end goal here is to have an application that will send a simple Hello World message. So we're going to cover the core framework stuff, but save things like templating, database access, ORMs, and forms for later. The goal here to see how to scaffold a Symfony app to better understand why symfony standard does what it does and where to deviate. We'll end up with an app that uses the Symfony 3 directory structure.
Starting with the smallest "composer.json" he can (just symfony/symfony) he walks through the creation of the application one step at a time:
- The Application Kernel
- Handling Web Requests
- What's in a Bundle?
- Stepping into Configuration
- Hello, World
The end result is a simple page outputting a "Hello, World" message, but it gives you a good foundation to work from and understanding of the simplest pieces needed to make a Symfony application.Link: https://www.pmg.com/blog/symfony-from-scratch/
- Code Yellow Blog: What Your Framework Never Told You About SQL Injection Protection
- NetTuts.com: Refactoring Legacy Code: Part 4 - Our First Unit Tests
- Site News: Popular Posts for the Week of 05.23.2014
- LeaseWebLabs.com: How to use the "yield" keyword in PHP 5.5 and up
- Lorna Mitchell: PHP 5.6 Benchmarks
- Matthias Noback: Inject a repository instead of an entity manager
- Master Zend Framework: Creating Custom ZFTool Diagnostic Classes
- Community News: Latest PECL Releases for 05.20.2014
- HHVM Blog: Hack Community Roundup
- Community News: Latest PEAR Releases for 05.19.2014
- Community News: Packagist Latest Releases for 05.20.2014
- SitePoint PHP Blog: IronMQ and Laravel: Setup
- Three Devs & A Maybe Podcast: virtPHP with Jacques Woodcock and Ben Ramsey
- php[architect]: May 2014 Issue Released - Making a Difference
- Brandon Savage: The framework you learn doesn't really matter
The ByMyCTO.com blog has a recent post that makes the suggestion that the Doctrine ORM isn't suited for PHP...or to put it another way why they think it's not a good option for database integration.I know, this title sounds like a troll. But it's not, it's a fact. I'm not saying Doctrine is a bad technology or shouldn't be used. I'm just saying it's not suited for PHP and this can lead to critical problems if misused.
He covers a few different topics including:
- Differences between Java and PHP (and the fact that Doctrine's inspiration was Hibernate)
- The "session problem" (entity serialization)
- Identity Map, useless in a stateless environment
- UnitOfWork, far too complex
- EntityManager, too magical
Despite all of these points, he does remind the reader that Doctrine isn't useless or inherently bad, it's just that he sees it as reinforcing bad behaviors and suggests using something else.Link: http://blog.bemycto.com/software-architecture/2015-05-17/doctrine-orm-not-suited-php/
The SitePoint PHP blog continues their series showing how to integrate content from the YouTube API into your application with this new tutorial. It covers the use of categories, searching and suggestions.In the first part, we introduced the Youtube API and built a small demo to list the most popular videos on Youtube. In this part, we will extend our application to have search functionality, and we'll also list the available categories on Youtube to let the user narrow down their area of interest.
He starts with with the updates you'll need to make to the routes and controllers for the "categories" functionality and the API call needed to popular the content. He updates the "videos" page to show the category information and integrate the category into the pagination. Next up is the search, allowing the users to find videos based on a search string. The search route/controller/view functionality is added as well. He ends the post talking about a way to extend the demo and advice to keep an eye on quotas and implementing cache.Link: http://www.sitepoint.com/youtube-videos-php-categories-search-suggestions/
NetTuts.com has continued their series about programming with the Yii2 framework with this new tutorial talking about blamable behaviors. These behaviors can de defined similarly to a common concept in other languages/tools, mixinsIn this tutorial, I'll guide you through another of Yii2's interesting behaviors: helping automate the common web development task of assigning created by and updated by user_ids across the models in your web app using DRY coding and Yii2 BlameableBehavior. We'll also create a log that records who updated the Status table for every change made.
In his example he shows the code needed to insert and update these two dates related to users of your system. He shows what kind of updates are needed to support it in your migrations and adding in the support for the BlameableBehavior in the models. He then modifies this example to not only log the latest person to modify a record but a history of IDs in a "status log" table.Link: http://code.tutsplus.com/tutorials/programming-with-yii2-blameable-behaviors--cms-23287
As Matthew Weier O'Phinney mentions in his latest post, the PSR-7 standard (HTTP) has passed and is officially accepted as a standard by the PHP-FIG group.The road to PSR-7 was a long and winding one. It started in summer of 2012 as a draft proposal on HTTP clients by Benjamin Eberlei, during which others proposed that perhaps a smaller standard on the HTTP message interfaces themselves - which would also allow targeting server-side applications, as those rely on the messages.
He follows the proposal's flow through the PHP-FIG process, pointing out several others who contributed along the way and what changed along the way. He also includes a section of thanks for some of the other developers and PHP-FIG members that made contributions along the way.Link: https://mwop.net/blog/2015-05-18-psr-7-accepted.html
He walks through each step you'll need to configure the logging:
- Overriding the bootstrap ConfigureLogging class (including the code needed)
- Updating your composer.json to change up the PSR-4 autoloading
- Modifying the Kernel.php file to update the constructor for the bootstrap (both HTTP and Console)
With these changes in place you can then use the normal "Log" handling Laravel provides and the magic will all happen behind the scenes. He includes two examples of this, one with a simple log string and another with something a bit more complex (and the resulting log output).Link: https://blog.muya.co.ke/configure-custom-logging-in-laravel-5/
- A Slim3 Skeleton | Rob Allen
#phpquickfix, #slimframework, #slim3, #skeleton, #application
- Radar: A PSR-7 Action-Domain-Responder Framework | Paul M. Jones
#phpquickfix, #radar, #framework, #psr7, #http, #adr
- Are You Ready for MySQL extension Removal from PHP - Lately in PHP podcast episode 59 - PHP Classes blog - PHP Classes
#phpquickfix, #mysql, #extension, #removal, #latelyinphp, #podcast, #ep59
- Setting Virtualhost Using XAMPP In localhost
#phpquickfix, #xampp, #virtualhost, #localhost, #tutorial, #configuration
- A Walkthrough on Conditional Tags in WordPress: 1 to 13 - Tuts Code Tutorial
#phpquickfix, #conditional, #tags, #wordpress, #tutorial
- PHP: rfc:php8
#phpquickfix, #php8, #discussion, #rfc
- BrandonSavage.net Breaking the Single Responsibility Principle - BrandonSavage.net
#phpquickfix, #singleresponsibilityprinciple, #solid, #development, #break
- Problematic PHP Cryptography Advice in Popular Questions - Meta Stack Overflow
#phpquickfix, #cryptography, #advice, #popular, #stackoverflow, #questions, #fix, #websecquickfix
- What are the optimistic and pessimistic timelines for PHP 7 making it into different Linux distributions? : PHP
#phpquickfix, #reddit, #timeline, #php7, #linux, #distributions
- PHP 5.5 on Oracle VirtualBox | codediesel
#phpquickfix, #tutorial, #install, #php5.5, #virtualbox, #oracle
- Moving WordPress: Moving a Site Into a Multisite Network - Tuts Code Tutorial
#phpquickfix, #wordpress, #moving, #multisite, #network, #tutorial
The PHP Town Hall podcast has posted their latest episode recorded live at the Lone Star PHP conference this year (2015). In episode 41, Loosely Town Hall - Dallas Edition, they're joined by Loosely Coupled podcast hosts Jeff Carouth and Matt Frost.
This episode is brought to you from thunderstruck Dallas, as part of the awesome conference that is Lone Star PHP. We are joined once again by the dynamic duo Jeff Carouth and Matt Frost off of the Loosely Coupled podcast!
We mostly make a bunch of bad jokes then drag up the audience to talk about stuff. Lets be honest, this was a bit of a crapshoot, but Elizabeth Smith goes into some detail on PECL and the problems of ownership. PSR-7 is chatted about for the 19th time and Jordi talks a bit about pickles. Also, we debate "haytch" vs. "atch" as the correct pronunciation of the "H" in HTTP. Important stuff.
You can listen to this latest episode either via the in-page audio player or by downloading the mp3 of the show. If you enjoy it, be sure to subscribe to their feed to get the latest episodes as they're released in the future.Link: http://phptownhall.com/blog/2015/04/18/episode-41-loosely-town-hall-dallas/
The NetTuts.com site has a new tutorial posted today sharing more information about the authentication facade in Laravel 5 and how to use it to implement simple, custom authentication handling.Authentication is a part of almost all the web applications you work with. It's really boring to keep repeating all the boilerplate code in every project. Well, the good news is Laravel 5 rids you of this boredom by providing a ready-to-use authentication facade. All you need to do is configure and customize the authentication service provider to your project's needs. In this quick tip, I am going to show you exactly how to do that.
It's a seven step process to get things up and running (it sounds like a lot but all the code is provided):
- Setting Up the Environment
- Setting Up the Migrations
- Configuring the Registrar Service
- Updating the User Model
- Updating the View
- Securing Your Routes
- Modifying the Default Authentication Routes
Each step includes the code needed and a brief summary of what's happening and how it effects the overall authentication setup. He also ends the post with a brief mention of the "password reset" email functionality and where the content for that email is located.Link: http://code.tutsplus.com/tutorials/using-laravel-5s-authentication-facade--cms-23461
He starts off with thinking that lexing and parsing the routes out into their respective tokens instead of breaking them up as many do (i.e. splitting on the slashes). He shows the results of this lexing and some parser code to handle these results and turn them into something useful. He did find that the current setup caused a lot of overhead (255 new states per character) so he optimizes the processing with a "default" trie but it was still pretty intensive.
He decided to go a different way at this point, opting for the radix tree structure instead. He includes the implementation of this tree for parsing the routes and his matching lexer updates. Finally he shows how to apply code generation to the results of these changes and how coming back to the "slash splitting" could help...Link: http://blog.ircmaxell.com/2015/05/prefix-trees-and-parsers.html
In her most recent post Lorna Mitchell talks about her own experiences in getting a current application upgraded and ready to run on PHP7. It can best be summed up in a tweet from her: "Total lines of code change needed to make the @joindin API work on PHP7: zero"With PHP7 looking increasingly stable (relatively speaking, it's still pre-alpha so it's VERY early days and anything could happen!), and work going well on the GoPHP7-ext project to get extensions converted, I have been thinking about the migration guides we'll need to help people upgrade their existing applications. To this end, I took the simplest project I currently have (http://api.joind.in) and gave it a whirl on PHP7, using Rasmus' PHP7 dev box. [...] All in all, it wasn't a great study of what kinds of things can go wrong when upgrading projects, because as far as I can tell with the test coverage that we have, it Just Works (TM).
She points out that a major contributing factor to it "just working" in PHP7 probably has to do with the few amount of dependencies. She also suggests looking at the tools you do use and see if they're already doing work to make it cooperate on PHP7 when the time comes. She describes some codebases that should "just work" with PHP7 including smaller codebases and things created with more modern tools/libraries/frameworks/etc.Link: http://www.lornajane.net/posts/2015/php7-easiest-upgrade-yet
The Sound of Symfony podcast has released their latest episode today, episode #8 - Concerning command buses with hosts Magnus Nordlander and Tobias Nyholm and special guest Matthias Noback.In this episode we talk to Matthias Noback about command-query separation, command buses, hexagonal architecture, REST and his library SimpleBus.
You can listen to this latest episode either through the in-page player or by downloading the mp3 of the show. If you enjoy the topic or the show be sure to also subscribe to their feed to get this and future episodes as they're released.Link: http://www.soundofsymfony.com/episode/episode-8/