PHPDeveloper.org

SitePoint PHP Blog: Best Practices REST API from Scratch - Implementation

Thu, 07/24/2014 - 19:11

PHPMaster.com has posted the second part of their best practices in REST APIs series with this new post focusing more on the implementation part of things.

We ended the first part of this tutorial with all the basic layers of our API in place. We have our server setup, authentication system, JSON input/output, error management and a couple of dummy routes. But, most importantly, we wrote the README file that defines resources and actions. Now it's time to deal with these resources.

They move on and add more functionality for creating (POST) and updating (PUT/PATCH) contacts in the system. They also show how to list contacts and add in some search handling allowing for sorting and returning only certain data. There's also some code for pagination handling, locating a single contact record, basic caching and simple rate limiting.

Link: http://www.sitepoint.com/best-practices-rest-api-scratch-implementation/

/Dev/Hell Podcast: Episode 48: Old as Dirt

Thu, 07/24/2014 - 18:55

The /Dev/Hell podcast has released their latest episode today, number 48: Old As Dirt. In this episode hosts Chris Hartjes and Ed Finkler are joined by guest Elizabeth Smith about being "old as dirt" and mentoring other developers.

Our guest this week is Elizabeth Smith, PHP internals veteran and guru of PHP on Windows (she says "I wish every company was as good at giving back to open source as Microsoft"). We talk about being Old as Dirt in relation to a blog post Ed made last week, how to mentor up and coming developers, and the history of PHP on Windows.

They also talk about Ed's The Developer's Dystopian Future article, PHP-GTK and the PHPMentoring project. You can listen to this latest episode either through the in-page player or by downloading the mp3 directly.

Link: http://devhell.info/post/2014-07-11/old-as-dirt/

NetTuts.com: Refactoring Legacy Code: Part 9 - Analyzing Concerns

Thu, 07/24/2014 - 17:27

The NetTuts.com site has posted part nine in their series sharing helpful hints and methods for refactoring legacy code. In this new post they continue on with their example application and look at where methods should be moved to/created and mocking in their tests.

In this tutorial, we will continue to focus on our business logic. We will evaluate if RunnerFunctions.php belongs to a class and if so, to which class? We will think about concerns and where methods belong. Finally, we will learn a little bit more about the concept of mocking.

They show how to move some of the "Runner" functions from procedural to OOP, integrating them with some of the classes and methods that already exist. Tests are also included showing how it all links together. From there they get into concerns about the placement of functionality and how that relates to the work at hand. They also use Mockery to mock out some of the needed objects in their tests for the new structure.

Link: http://code.tutsplus.com/tutorials/refactoring-legacy-code-part-9-analyzing-concerns--cms-21760

Phil Sturgeon: The Neverending Muppet Debate of PHP 6 v PHP 7

Thu, 07/24/2014 - 16:18

Phil Sturgeon has posted about something he calls the "neverending muppet debate of PHP 6 versus PHP 7. As the PHP language moves forward, the PHP 5.x series is coming to a close. The discussion as started up whether to name it "PHP 6" or "PHP 7" and both sides have their proponents.

There are a few major, important conversations happening in the PHP internals mailing list as we speak: The Facebook lot heading up a specification based off of PHP 5.6 Should phpng be moved into master to be the base of the next major PHP version How can we best go about scalar typehinting? There is also another conversation: Should it be PHP 6 or PHP 7 Wait... what?

He goes on to provide a little context, pointing out that back in 2010 PHP 6 was being slated for release as the next major version of the language (this was around the PHP 5.2 days). Unfortunately, it stalled out and some of what was planned went into PHP 5.3. This didn't stop publishers from releasing books and articles about "PHP 6" though. It's already being put up for a vote with "PHP 7" pulling ahead. Phil also includes more context around the discussions, sharing the main points of each side and snippets from the RFC and mailing list thread currently ongoing.

Link: http://philsturgeon.uk/blog/2014/07/neverending-muppet-debate-of-php-6-v-php-7

That Podcast: Episode 5: The One Where Everyone Is Going to London

Thu, 07/24/2014 - 15:08

That Podcast, hosted by PHP community members Beau Simensen and Dave Marshall has posted their latest episode - Episode #5, "The One Where Everyone is Going to London".

Beau and Dave discuss having been selected to Symfony Live London and how they plan to bring their families with them so everyone can hang out in person for the first time. Beau discusses his other upcoming talks including Nomad PHP EU and php[world] and Dave talks a bit about his pair programming setup. Both agree that rewriting code from another project is a great way to really understand how the thing ticks.

There's a wide variety of topics discussed in this episode including:

You can listen to this latest episode either through the in-page player or by downloading it directly.

Link: http://thatpodcast.io/episodes/episode-5-the-one-where-everyone-is-going-to-london/

Community News: Packagist Latest Releases for 07.24.2014

Thu, 07/24/2014 - 14:09
Recent releases from the Packagist:

Master Zend Framework: Configuring the ServiceManager with Abstract Factories

Wed, 07/23/2014 - 19:41

On the Master Zend Framework site today Matthew Setter has a new post covering the configuring of the service manager using abstract factories.

One of the best features about Zend Framework 2 is undoubtedly the ServiceManager; because it makes it almost painless to configure and retrieve services in a consistent and predictable manner, anywhere in your application, at any time. [...] But the catch is, there's quite a bit to learn if you want to use it properly. As well as that, there's quite a number of ways to use it.

He walks you through some of the pros and cons of the various ways to work with the ServiceManager and where the factories fit in. He takes a bit of time to introduce the concepts behind abstract factories and how to define them in a Zend Framework v2 application. He finishes out the post with a more practical, working example using the interfaces provided to get a "MyUserTable" service.

Link: http://www.masterzendframework.com/servicemanager/configuring-servicemanager-with-abstract-factories

Voices of the ElePHPant: Interview with Evan Coury

Wed, 07/23/2014 - 18:36

The Voices of the ElePHPant podcast is back with a new episode of its podcast. This time it's an interview with PHP community member Evan Coury.

The interview is recoded live at this year's Midwest PHP Conference. They talk about Evan's work around Zend Framework and where he sees things going with the project. He also mentions some of the work being put towards Zend Framework v3 (and if there will be many backwards compatibility breaks like there was with ZF2).

You can listen to this latest episode either through the in-page player or by downloading the mp3. If you like what you hear, consider subscribe to their feed.

Link: http://voicesoftheelephpant.com/2014/07/22/interview-with-evan-coury/

Three Devs & A Maybe Podcast: Functional Programming with Simon Holywell

Wed, 07/23/2014 - 17:03

Three Devs & A Maybe podcast has released their latest episode today: Episode #35 - an interview with Simon Holywell. Simon is the author of an upcoming book about functional programming in PHP.

This week we are lucky to have Simon Holywell on the show to talk all things Functional Programming. Initially starting off with a concrete definition of Functional Programming, we move on to a brief history of the paradigm and immutability. Following this we explain recursion (and tail-recursion), along with closures and higher-order functions. From this base we are able to then talk about the different languages available to you which cater towards the functional mindset (i.e. Haskell). We then set our sights on the PHP language and what/wish it had to offer when exploring the functional paradigm. Finally, we mention his upcoming book, along with experiences presenting at user-group meet-ups.

Topics mentioned in this episode include:

You can listen to this latest episode either through the in-page player or by downloading the mp3 directly.

Link: http://threedevsandamaybe.com/posts/functional-programming-with-simon-holywell/

Anna Filina: Common PHP Mistakes

Mon, 07/21/2014 - 19:53

Anna Filina has posted her own addendum to a top ten list of common PHP programmer mistakes, adding seven more of her own.

I was recently asked by one of my readers to give feedback on the following article he read: 10 Most Common PHP Mistakes. It is well written and very thorough. Most of the tips are specific to PHP, others are about web programming in general or database performance. It's a very good read. I was also asked to contribute to this list, so here are 7 more tips.

Her list of seven touches on topics like caching, allowing SQL injection, disabling error reporting and ignoring accessibility. She also includes some configuration settings, code and links to other tools/resources to help provide information on preventing these other mistakes.

Link: http://afilina.com/common-php-mistakes/

php[architect]: Sending HTML Emails with Drupal 7, Webform, and Mandrill

Mon, 07/21/2014 - 18:42

The php[architect] site has a new tutorial posted giving you a step by step guide to sending HTML email with the combination of Drupal 7, Webform and Mandrill (the mail service by Mailchimp).

By default, Drupal is configured to send out plain text emails. For many developers, plain text email is sufficient and preferable to HTML email. HTML email is still, in this day and age, not guaranteed to render the same across email clients, more likely to be labeled as spam, and requires a significant amount of testing to make sure it works. Still, a minimally styled HTML message can be easier for recipients to read and help reinforce your brand/design (if you don't depend on images to do so). In this article, we'll look at the modules to install and configure to enable HTML emails and, specifically, how to change the default Webform email template to send submissions as HTML.

The tutorial comes in four different sections, each with plenty of description and some code to make it happen:

  • Set up your site to send email
  • Allow outgoing email to use HTML
  • Formatting Outgoing Email
  • Send Webform Submission as HTML Emails
Link: http://www.phparch.com/2014/07/sending-html-emails-with-drupal-7-webform-and-mandrill/

SitePoint PHP Blog: Social Network Authentication: Twitter and Facebook

Mon, 07/21/2014 - 17:32

The SitePoint PHP blog continues their series of tutorials showing how to authentication your users against various social networks. In the previous post they covered connecting to Google+ and in this latest post they move on to two other popular social networks: Facebook and Twitter.

In the previous parts of this series, we created our initial interfaces, set up our Google+ login functionality and talked about how we can merge our accounts together. In this article, we will integrate Twitter and Facebook within our application. You will see a lot of similarities with the Google+ article, so if you could follow that one easily, you won't have much trouble with this one. If you haven't read that article yet, I suggest you read it first before continuing this article.

He starts off with the Twitter authentication, creating a new "SocialLogin" object type for it and defining the three required properties it needs to connect. Code is included to make the OAuth connection, pass along the callback URL and forward on the user to the Twitter site for approval. Code is also included to store the data about the Twitter user in your application. Next up is Facebook. The connection is very similar to the others with only a slight difference in the data that's required. You can find the full code for the tutorial so far in this Github repository.

Link: http://www.sitepoint.com/social-network-authentication-twitter-facebook/

NetTuts.com: Best Practices When Working With Sensitive Data: Securing Your Application

Mon, 07/21/2014 - 16:27

The NetTuts.com site has a new tutorial posted today sharing some tips about working with sensitive data in your applications and steps to secure it.

In my previous article, I showed you how to protect your server from attacks and malicious software. This part will focus completely on the third layer of security - your application itself. So here, I will show you techniques that you can use to protect your application from attacks and intrusions.

There's three main topics covered here, each with a few subpoints and some code examples:

  • Using a Database
  • Use a Salt When Hashing
  • POSIX: Drop Privileges When You Don't Need Them
Link: http://code.tutsplus.com/tutorials/best-practices-when-working-with-sensitive-data-securing-your-application--cms-21719

Phil Sturgeon: Send PSR-0 to the Standards Farm in the Sky

Mon, 07/21/2014 - 15:09

In his latest post Phil Sturgeon makes a request of the PHP community - to "send PSR-0 to to Standards Farm in the Sky". Or, to put it another way, deprecate it in favor of the more recent autoloader handling of PSR-4.

This article attempts to convince you that deprecating the PSR-0 auto-loading standard in favor of the PSR-4 auto-loading standard is not only a good idea, but a problemless wonderland of happy benefits, in the hope that when I try to get this done on the FIG mailing list, people will be happy about it instead of sad or rage-mode. [...] I believe it was talked about as an alternative at the time because we knew that the PHP community would drop their collective bricks if we tried to pull PSR-0 out from under them, right as they were just slowly getting used to using it.

He covers a few different topics and his opinions on each including the "hate" for PSR-0 (for wanting to get rid of it) and why it should even be considered for deprecation in the first place. He also reminds readers that he's advocating the deprecation of PSR-0, not the removal of it as a standard. It can still exist and be used but it will no longer be the "moving forward" method of autoloading (in favor of PSR-4). He also comments on the large user base out there on PHP <=5.2 that wouldn't be able to make the update to PSR-4 and a suggestion to projects wanting to encourage the migration.

Link: http://philsturgeon.uk/blog/2014/07/deprecate-psr0

Community News: Packagist Latest Releases for 07.21.2014

Mon, 07/21/2014 - 14:04
Recent releases from the Packagist:

Reddit.com: What constitutes the "PHP community"?

Fri, 07/18/2014 - 18:09

There's a good conversation happening over on Reddit today about what constitutes the "PHP community" and how it can be defined. JordanLeDoux wonders if those who just write PHP are included in that group as well.

One conversation was with a dev who hates PHP because (mostly) they work with code that was written by some non-PHP dev who was asked to write it. The other was with /u/krakjoe from the PHP internals team, where I was commenting on a sentiment that sometimes finds its way into the internals mailing list: if you want a real programming language, then go use one. In both cases, I made the assertion that most people who utilize PHP or edit a script aren't actually part of the PHP community. [...] How can someone that is functionally isolated from any other person working in PHP be part of the PHP community?

Responses to the post are, for the most part, encouraging suggesting that

  • There's not a single "PHP community" but many smaller ones
  • sub-communitiies can revolve around technology or a product
  • The different definitions of community
  • The broad range of skills that "PHP developers" are known to have

Check out the full post for more opinions and share your own!

Link: http://www.reddit.com/r/PHP/comments/2ayxkg/what_constitutes_the_php_community/

Lorna Mitchell: Using Phing with Travis CI

Fri, 07/18/2014 - 17:23

Lorna Mitchell has a quick post to her site today showing you how to link up Travis-CI and phing to execute the phing build on the Travis-CI service.

We've started using Travis CI on one of my projects to run some build processes to check that everything looks good before we merge/deploy code. One thing I ran into quite quickly was that I wanted to install phing in order to use the build scripts we already have and use elsewhere, but that it isn't provided by default by Travis CI.

To get it all cooperating, she uses the "before_install" settings/functionality Travis provides to use PEAR to discover and install phing. Then in the "script" section, the build can call the phing executable without problems. She does point out one "magic" kind of thing that rehashes the Travis environment and lets to know phing exists: the...well..."rehash" configuration setting.

Link: http://www.lornajane.net/posts/2014/using-phing-with-travis-ci

Paul Jones: Action-Domain-Responder, Content Negotiation, and Routers

Fri, 07/18/2014 - 16:17

In his latest post Paul Jones comes back to his proposed application structure, the idea of Action-Domain-Responder, and answers some questions about where content negotiation happens and routing.

While talking about Action-Domain-Responder on the Crafting Code Tour, one of the common questions I got was: "Where does content negotiation happen?" My response was always: "Where does it happen in Model-View-Controller?" That opened up a discussion on how content negotiation is a tricky bit that can go in different places, depending on how you want the concerns separated, and is not a problem specific to ADR.

He goes on and tries to answer the question a bit better, pointing out that "it's a problem for everyone" isn't really good enough to take action on. He works through the different pieces of the ADR pattern, trying to reason out where the right fit is. He suggests a "first filter" on the Controller level, more specifically at the Router level. That's not to say that the Router needs to know about content handling, but it does need to know how to pass that information on.

Link: http://paul-m-jones.com/archives/6020