2015年6月19日星期五

Site News: Popular Posts for the Week of 06.19.2015

Popular posts from PHPDeveloper.org for the past week:

Loosely Coupled Podcast: Episode 24: Minimum Viable Product


The Loosely Coupled podcast, with hosts and PHP community members Jeff Carouth and Matt Frost, has posted their latest episode today - episode #24: Minimum Viable Product.



In this episode Jeff and Matt talk about the concept of a minimum viable product and what it means to us as developers. The concept of an MVP is simple but it often gets used as an excuse to put out poorly-implemented products. Listen as Jeff and Matt discuss their opinions about the problems with MVP in our industry and how we as developers can fight against them.


You can listen to this latest episode either through the in-page audio player, by downloading the mp3 or by subscribing to their feed to get this and other episodes as they're released.


Link: http://looselycoupled.info/blog/2015/06/18/episode-24-minimum-viable-product/

HHVM Blog: Trait and interface requirements in Hack


On the HHVM blog there's a recent post looking at some of the requirements around traits and interfaces in the Hack language. More specifically, they talk about type checking with traits and how interfaces can be used to help provide extra structure.



In PHP, traits are a mechanism of code reuse that, while very powerful, are also difficult to type check both efficiently and exhaustively. In this post we'll dive more deeply into the reasons for that and see how Hack solves those problems, allowing you to use traits in a safe way without limiting their expressiveness.


They start by talking about the main problem with PHP's handling of traits (essentially copy and paste into the current class) and how they felt Hack should "just work" in allowing type checking on these "pasted" methods too. Performance limitations prevented them from handling it how they do with other variable types, so they changed things up, using a "require extends" syntax to tell the Hack engine how to allow the checking based on an interface. There's a lot more to it than this, so be sure to read the rest of the post on how they came to that conclusion.


Link: http://hhvm.com/blog/9581/trait-and-interface-requirements-in-hack

NetTuts.com: Programming With Yii2: Rich Text Input With Redactor


NetTuts.com continues their series about programming with the Yii2 framework in this new article moving on to the use of the Redactor rich text editor that comes bundled with the framework.



In this Programming With Yii2 series, I'm guiding readers in use of the newly upgraded Yii2 Framework for PHP. In this tutorial, I'm going to introduce you to using the rich text editor Redactor within the Yii Framework. For these examples, we'll continue to imagine we're building a framework for posting simple status updates, e.g. our own mini-Twitter.


Thanks to the Yii community purchasing an unlimited license for the Redactor rich text editor, it's easy to install and use via the "yii2-redactor" extension. They help you get it installed and update a sample form to use it instead of the normal basic HTML textarea for content input. They also show you how to add image support and what it looks like both inline in the editor and the resulting HTML output.


Link: http://code.tutsplus.com/tutorials/programming-with-yii2-rich-text-input-with-redactor--cms-23174

Run Geek Radio: Episode 005 - Time Estimation, Conference Talk Rating, Contest Winner


The Run Geek Radio podcast has posted their latest episode today. In it (episode #5) host Adam Culp talks about time estimation, thoughts on conference talk ratings and the contest winner from his standing desk contest mentioned in an earlier episode.



This episode Adam Culp announces the winner, David Stockton (Colorado), of the contest launched in Run Geek Radio episode 004. [...] Adam also talks briefly to clarify his views on "soft talks" versus "soft skills talks", and how he was misrepresented as disliking soft skills talks though the opposite is true. [...] Then this episode is rounded out with a detailed coverage of time estimation in relation to projects, and why it is so vitally important to be accurate. Adam also speaks about how important proper requirements gathering is to the process.


You can either use the in-page audio player to listen to this latest episode or you can download the mp3 of the show. Be sure to subscribe to the feed if you enjoy the show and want to hear more from Adam.


Link: https://rungeekradio.com/episode-005-time-estimation/

Giorgio Sironi: Property-based testing primer


Giorgio Sironi has a new post to his site today talking about a method (and tool) around a different sort of testing practice: property-based testing. The difference is that, instead of hard-coding values and evaluating them post-processing, you're generating random values and ensuring they match against a set of properties, not values.



I'm a great advocate of automated testing and of finding out your code does not work on your machine, 30 seconds after having written it, instead of in production after it has caused a monetary loss and some repair work to be performed. [...] However, classic test suites written with xUnit and BDD styles have some scaling problems they hit when you want to exercise more than some happy paths. [...] Property-based testing is an approach to testing coming from the functional programming world.


He helps to make the point a bit more clear with an example of testing the "sort" function and its results. He talks about how to test it using normal data, empty data, etc. but notes that this kind of testing can become "boring and error-prone". Instead he proposes the property-based testing of the results. He generates random values to feed into the method and checks to ensure the results are sorting by comparing them to each other. He expands this with a bit more complex example, showing how to test some DateTime handling and evaluating the result with logic in a closure. To help make this kind of testing easier, he's created a library (Eris) that extends PHPUnit and provides the methods seen in his examples.


Link: http://www.giorgiosironi.com/2015/06/property-based-testing-primer.html

Sammy Powers: Contributing to the PHP Manual


If you've wanted to contribute something back to PHP but aren't familiar with C (or don't feel comfortable enough with it) Sammy Powers offers another solution. In his latest post he shows you how to contribute to the PHP documentation and update the manual for new features, missing information or fixes to current code examples.



If you've been wanting to contribute to PHP internals, starting with the documentation can be a great entry point; especially because it doesn't require dusting off those old C books from college. But knowing where to start can be tricky since information on how to contribute to the docs is scattered across the internet. This article is a step-by-step guide of how to contribute documentation to the PHP manual.


He starts with the "quick and dirty" way of editing the manual through the edit.php.net site, but points out that it's really only useful for smaller changes, not large documentation updates. The rest of the post shows you how to set up the documentation locally and generate the results to validate your changes. He talks some about the DocBook format they're written in, the build process with the PhD (PHP docs generator) and running the php.net test suite against the changes. This ensures that nothing else has broken on the site in the process.



He shows you where to make your changes, how to generate it from either a skeleton or using the docgen script and submitting the changes back to the repository. There's also a few other random changes to make before committing the files back via SVN and pushing them back upstream. He ends the post talking about the GoPHP7-ext project and how to find extensions that are missing documentation or where it's incomplete (easy thanks to an included "check-missing-docs" file included in the repository).


Link: https://www.sammyk.me/how-to-contribute-to-php-documentation

2015年6月18日星期四

Site News: Blast from the Past - One Year Ago in PHP

Here's what was popular in the PHP community one year ago today:

Scotch.io: Deploy PHP Apps Easily with Laravel Forge


The Scotch.io site has a new post that wants to help make your Laravel deployments on Forge a simple thing. Forge is a "frontend" to make deployment on the hosting platform of your choice simpler with features for configuring the server, application deployment and automation (like push to deploy).



Forge is an incredible tool in the family of Laravel products that helps developers focus on developing, not deploying and hosting. I personally use it when deploying Laravel applications and it does make life much easier. Many of the pain points of hosting are taken care of for you so you can get right back to developing. [...] We'll be diving into how we can deploy a Laravel application to Forge using Digital Ocean and GitHub.


He starts with a brief introduction to how Forge works and cooperates with the Digital Ocean stack to create the server and deploy the application. He answers a few questions about "why should you use Forge" and then gets into the actual setup of the server. He walks you through:



  • Linking the project to a GitHub or BitBucket repository
  • Adding SSH keys to connect to use for connecting to the server
  • Creating a server


He also goes through some of the server management features Forge offers in its dashboard including monitoring services, server tools and basic site management controls. Once everything is set up, he shows how to deploy from the GitHub repository and how to use third-party integrations (like Slack or HipChat) and the use of environment variables.


Link: https://scotch.io/tutorials/deploy-php-apps-easily-with-laravel-forge

MyTechBuilder.com: Optional Value Control-flows in PHP using Traits and Magic-methods


The MyBuilderTech.com site has a new tutorial posted talking about the use of traits and magic methods for optional value handling.



Recently I have been interested in experimenting with different ways to handle optional values. Their are many examples that exist demonstrating the use of the Maybe/Optional structure within the PHP landscape. I would instead like to focus my attention on only looking into the concept of 'orElse', which I have found to be a prominent control-flow whilst using these types of value. Typically, in an imperative mind-set we are accustom to evaluating a value, and based on its existence - defined as falsely in this regard - follow a different course of action, and by-way result.


He gives an example of where a value is checked for null and something else happens when it is. This is a common practice in PHP development, but he's more interested in other ways of handling. The first of these ways is with traits. His example shows an "OrElse" trait that can be used to perform the same evaluation but does some extra magic based on the method name called (his example is "findByIdOrElse"). If the trait method isn't for you, he also offers another possible solution around the use of composition. In this case he uses the same trait but makes it a part of its own class that's then given the object to work with (his "repository").



The post ends with one more "bonus" method for handling optional values - a simple function ("_or") that evaluates the arguments given and returns the first that's "truthy".


Link: http://tech.mybuilder.com/optional-value-control-flows-in-php-using-traits-and-magic-methods/

Ben Ramsey: Composer: Missing Distributions for Explicit References


Ben Ramsey has shared an interesting issue he's come across when installing packages via Composer where it installed a different version than expected when he ran an install. The problem turned out to be from an unexpected place.




For applications I control that are not distributed to the public, I like to hard-lock my Composer dependencies to a specific version. [...] Sometimes a library has updates that haven't yet been released, and I need to use these right away. Composer allows me to specify the specific commit I want to use for a library. In this way, I can hard-lock a dependency to a specific state, even when there is not yet a release for the changes I need. This has worked well until today, when I tried to do a fresh composer install. After installing, one library contained files and methods that I did not expect. It turns out Composer was grabbing the HEAD of dev-master instead of the specific commit I referenced.




After some investigation into his "composer.lock" file's contents, he found the issue: a problem with the way that BitBucket handles the distribution zip files Composer requests. In his example, the zip file was of the HEAD on the repository, not of the specific commit (GitHub doesn't have this problem). His solution was using the (slower) "--prefer-source" option to grab the correct commit contents...not an ideal solution but it does what he needs.


Link: http://benramsey.com/blog/2015/06/composer-missing-distributions/

SitePoint PHP Blog: Popular Users per Language and Region with Silex and Github


The SitePoint PHP blog has a new tutorial posted showing you how to use the data the GitHub API provides to find popular users, per language, in an area. His sample example is a simple Silex framework based application and uses the KNPLabs GitHub library to interface with the API.



The data you can get through the GitHub API V3 is mostly what you can see on the GitHub web interface, except you can use the data in your application to come to interesting conclusions. That is what we are going to do in this article. [...] Now, what if there was a web service in which we could specify a location and a language (e.g. PHP) and get a sorted list of contributors to open-source? [...] In our web service, we will have one endpoint (i.e. action, URL) that shows the most popular ten creators. The most popular creators are the people in a location who have the largest number of stargazers. For this, we will retrieve each person's repositories and add up the number of times each one has been starred.


He steps you through getting a Homestead Improved VM up and running (via Vagrant) and a basic Silex application up and running inside. He then pulls in the KNPLabs GitHub library via Composer and sets up a new client in the default route (and grabs the public user data for a user). He then shows how to change it up and use the Search API and some special queries to locate users by a given location. He adds another class, a "StarGazerCalculator", that's given the users returned, filters out the forks in the list and calculates the total "stargazer" count for the user. He does the same with the "top creators" list and sets it up as a service provider, fetches the data and returns the results as a JSON document.


Link: http://www.sitepoint.com/popular-users-per-language-region-silex-github/

Community News: php[world] 2015 Schedule Announced


The next php[world] conference is coming up in November of this year and they've just announced the full schedule for their 2015 event.



In keeping with the cross-community theme, they've gathered speakers from the general PHP, WordPress, Drupal, Joomla, Zend Framework, Symfony and CakePHP communities together in one place. Sessions at this year's event include:



  • "HTTPS is Coming: Are You Prepared?"
  • "Test, Create, Secure, Repeat"
  • "Scrummy Bums: Adventures in Agile Process"
  • "Using Lessons Learned to Create Web-Manageable Symfony Apps"
  • "Invented Here: Migrating Legacy Data to Drupal 8"
  • "Magento 2 Dependency Injection, Interceptors, and You"
  • "Dev Divas: Amazing Women Who Shaped Computer Tech"


There's also keynotes from well known community members Andrew Nacin, Tessa Mero, Lorna Mitchell and Taylor Otwell. You can see the full lineup here and, if you want to pick up tickets of your own, you can do it directly from the site.


Link: https://world.phparch.com/schedule/

2015年6月17日星期三

Community News: Recent posts from PHP Quickfix

Recent posts from the PHP Quickfix site:

Three Devs & A Maybe: Episode 68 - Podcasting, Remote Working and Testing with Adam Wathan


The Three Devs & A Maybe podcast has released their latest episode today, Episode #68 - Podcasting, Remote Working and Testing with Adam Wathan.



This week we are very lucky to be joined by fellow podcaster and host of Full Stack Radio - Adam Wathan. We begin discussion with his reasons behind starting a podcast, experience being a solo-host and the secret to great podcast recordings. We then move on to how he got into programming at high school - with reflection on that if he had been using a Windows machine at college, he would most likely be a .NET developer by now. As both Edd and Adam work remotely at this time, the topic of remote pair-programming and Kanban style board implementations then arises. Finally, we discuss his thoughts on Message-passing vs. strict-contracts, Smalltalk and Elixir exploration and how it is hard to give a definitive answer on the best way to begin learning TDD.


You can listen to this latest episode either through the in-page audio player or by downloading the mp3. Be sure to subscribe to their feed if you enjoy the show too!


Link: http://threedevsandamaybe.com/podcasting-remote-working-and-testing-with-adam-wathan/

Stephan Hochdörfer: Simple Logging Facade for PSR-3 loggers


In his latest post Stephan Hochdörfer shares a library he's created to hopefully make it easier for developers to integrate PSR-3 compatible logging libraries into their code, a "logging facade" based on an idea from the Java world.




Lately I have seen more and more libraries picking up PSR-3 when it comes to logging. What a lot of libaries do wrong is that they depend on a concrete implementation of PSR-3, e.g. Mongolog instead of relying on the PSR-3 interface. From what I have seen this is because loggers get instantiated directly within the class. This is not a bad thing but it couples your code to a concrete implementation of PSR-3 which in turn means that there`s no interoperability.



The Java community solved the problem by creating a Simple Logging Facade library (SLF4) which I "ported" to PHP last week.




The library makes provides a simple static interface to setting the PSR-3 logger of your choice and fetching it from anywhere in your application. He includes an example of what the code would look like for a basic Monolog instance. He ends the post talking about this method for getting/setting the logger instance and how it compares to using other options like a dependency injection container or even just a manual call to a setter.


Link: https://blog.bitexpert.de/blog/simple-logging-facade-for-psr-3-loggers/

Laravelista.com: Build an API with Lumen and Fractal


On the Laravelista.com site there's a recent tutorial posted showing you how to create an API with Lumen and Fractal, a combination of the popular Laravel-based microframework and Fractal, an output handling library that makes it simpler to transform data to your needs. This is the second part of his series (part one is here), making some improvements on his previous examples.



In the previous post I used Larasponse to get Fractal working with Laravel, but recently I have switched to native Fractal package. One thing to notice is that in this post I will be showing you parts of code from a real project that I am working on called Treeline, instead of just example code like in the previous post. Be sure to check the Treeline repository if you're unclear on something.


He goes back through some of the setup process, getting Fractal installed via Composer and the creation of an ApiController to handle basic things like setting the status code and transforming the response to JSON. He shows how to add in the necessary routes for the "projects" path and creates the matching controller, collection and item classes that integrate the Fractal transformers to format their output as JSON. He also includes the code for the transformer classes themselves, showing you how to pull in and modify the data for the API's needs. He ends the post showing how to integrate other data (the "notes" into a "project" instance) and the resulting JSON output.


Link: http://laravelista.com/build-an-api-with-lumen-and-fractal/

Community News: PHPPackages.org


A new community resource, built on top of the excellent Composer and Packagist technology that's popular in today's PHP development world, has been released and provides more context about libraries and provides a "rank" for each one - PHPPackages.org.



PHPPackages.org was built to solve the following problems: [it] defines popularity rank for php packages, provide a space for discussion and [helps to] discover which packages use a specific package.


The About page has more information about the site, how they calculate the "popularity" metric, what the various icons mean and what kinds of things you can do on the site. It's a great resource, especially for those wondering who is using their packages and to discover new packages that are more widely used. It has a lot of the same information that the Packagist site contains but that little extra bit of data is quite useful.


Link: https://phppackages.org/

Paragon Initiative: Everything [About] Preventing Cross-Site Scripting Vulnerabilities in PHP


The Paragon Initiative has posted a new tutorial that wants to provide you with everything you need to know about preventing cross-site scripting in PHP applications.




Cross-Site Scripting (abbreviated as XSS) is a class of security vulnerability whereby an attacker manages to use a website to deliver a potentially malicious JavaScript payload to an end user. XSS vulnerabilities are very common in web applications. They're a special case of code injection attack; except where SQL injection, local/remote file inclusion, and OS command injection target the server, XSS exclusively targets the users of a website.



[...] Cross-Site Scripting represents an asymmetric in the security landscape. They're incredibly easy for attackers to exploit, but XSS mitigation can become a rabbit hole of complexity depending on your project's requirements.




He introduces the concept of cross-site scripting (XSS) for those new to the term and provides a brief "mitigation guide" for those wanting to jump to the end. He then gets into some examples of what a XSS vulnerability could look like, both stored and reflected and provides the "quick and dirty" method for preventing them. He also mentions some tips in implementing your solution including avoiding HTML in your data if at all possible. He goes on to talk about the use of HTMLPurifier to prevent attacks, context-sensitive escaping (HTML vs JS vs CSS) and some of the browser-level features that help prevent XSS for the user.


Link: https://paragonie.com/blog/2015/06/preventing-xss-vulnerabilities-in-php-everything-you-need-know

2015年6月16日星期二

Community News: Latest PECL Releases for 06.16.2015

Latest PECL Releases:
  • timezonedb 2015.5
    Updated to version 2015.5 (2015e)


  • wxwidgets 3.0.2.0
    * Updated the thread.php example to work properly.
    * Remove delete on the wxThread garbage collector function, which
    should fix most issues on #84.
    * Modified wxWindow::GetHandle to return the XWindowID on Gtk which
    should really fix #86.
    * Enabled wxWindow::GetHandle by casting WXWidget to size_t.
    * Enabled wxOutputStream::Write and wxInputStream::Read variations
    that take a 'void* buf' as argument which should fix issue #87
    * Updated version numbers and added userland version constants:
    WXWIDGETS_LIBRARY_VERSION and WXWIDGETS_EXTENSION_VERSION.
    * Added --with-wxwidgets-version to package.xml so 'pecl install
    wxwidgets' can ask for a different version of wxWidgets library to
    download and compile.
    * Set the default wxWidgets version to download and compile on linux
    and mac to 3.0.2. Also added a new configure option
    --with-wxwidgets-version to explicitly change the version of
    wxWidgets to download, eg: --with-wxwidgets-version=3.0.1
    * Forgot to conditionally fetch tsrm on wxAppWrapper.
    * Fetch TSRM on wxAppWrapper which probably fixes issue #70
    * Unmodified copy of wxImage::GetData to zval which fixes #75.
    * Own the data parameter on wxImage SetData to really fix issue #75.
    * Custom templates for wxImage GetData and SetData which fix
    and close #75.
    * Updating location of Mac OS X SDK in docs (chrisnharvey).
    * Updating docs for building on Mac OS X (chrisnharvey)
    * Updating link to heading
    * Updating macosx-version-min to 10.9
    * Added sdl, sdl_sound as dependencies on archlinux PKGBUILD.
    * Updated config.m4 to require sdl and sdl_sound on linux which
    fixes #2.
    * Removed some testing printf code.
    * Added some wxApp methods.
    * Fix to correctly brake search for wx-config when first found in
    config.m4 file.
    * Added wxPHP shell script in /usr/bin/wxphp.
    * Added some wxApp methods.
    * Automated Mac OSX detection which should fix #94.
    * Simplified README.md and added building steps into INSTALL.md.
    * Removed trace of debugging code.
    * Merge child class method overrides that differ into parent methods
    which should fix #97.
    * Added drag and drop example.
    * Disabled pointer deletion for wxDropTarget and child classes
    to fix segmentation fault which fixes #98.


  • mongo 1.6.9
    ** Bug
    * [PHP-1426] - Ensure buffer lengths are checked in bson_to_zval()
    * [PHP-1448] - Ensure DBPointer namespace length reads as little-endian
    * [PHP-1450] - Ensure strings are null-terminated in bson_to_zval()
    * [PHP-1453] - Ensure BSON buffer is checked before reading regex pattern/flags

    ** Improvement
    * [PHP-1449] - Ensure value is freed when bson_to_zval() encounters an error
    * [PHP-1452] - bson_decode() should require exactly one document in buffer


  • pq 0.6.0RC1
    * Fixed crash with result iterator when the iterator exists longer than the result
    * Fixed array parser compatibility with arrays of boxes
    * Added pqStatement::deallocate{,Async}() and pqStatement::prepare{,Async}() methods
    * Added pqStatement::$query and pqStatement::$types readonly properties
    * Added pqCursor::{open,close}Async() methods
    * Added pqCursor::$query and pqCursor::$flags readonly properties