PHP.net

Reddit.com: Dependency injection in ZF2 and Symfony 2 are service locators

PHPDeveloper.org - Tue, 16/04/2013 - 19:40

On Reddit's PHP section there's a discussion happening about dependency injection versus service locators in two popular PHP frameworks - Zend Framework 2 and Symfony 2 (and how they're not really DI at all).

Both ZF2 and Symfony 2 offer the same behavior: if I'm in a controller, and I want to use a service, I have to get it from the container with $this->get('my_service'). As such, the controller is not using DI, this is the service locator pattern. Controllers become more difficult to tests because of that, and they depend on the container now. I wonder why both frameworks didn't go further: why not treat controllers like services and use dependency injection on them. In other words: if a controller needs a service "A", then it should get it in the constructor, or through setter/property injection.

The comments talk some about the "controller from the DI container" idea, some other ways around the problem and some clarification as to what the frameworks are actually doing related to the container injection.

Link: http://www.reddit.com/r/PHP/comments/1caidn/dependency_injection_in_zf2_and_symfony_2_are

Extending Twig Templates: Inheritance, Filters, and Functions

PHPDeveloper.org - Tue, 16/04/2013 - 18:05

On PHPMaster.com today there's a new tutorial for the Twig templating users out there showing you how to extend your templates via inheritance, filters and functions - all abilities already built in to the tool.

When working within an MVC architecture, it's common to use a template library to populate the dynamic content of our views. There are dozens of such libraries available for PHP, but Twig is one of the standouts because of the ability to extend core features with custom implementations. In this article we'll explore how Twig templates can be extended using template inheritance, filters, and functions.

He starts first with some of the common limitations of templating frameworks (extension) and how Twig gets around this. He shows the use of the "extends" keyword and the "block"/"endblock" for splitting up the page into reusable chunks. He also shows how to use filters and functions in your Twig tags, allowing for more customized content and functionality for your output.

Link: http://phpmaster.com/extending-twig-templates-inheritance-filters-and-functions/

Automated backups to Google Drive with PHP API

PHPDeveloper.org - Tue, 16/04/2013 - 17:57

On his site Lukasz Kujawa has posted a new tutorial showing you how to perform automated backups to Google Drive of files through their API (using his own library).

Where do you keep backups? I guess that depends on what do you backup. You might have a very clever answer for a business critical data but what about less important content? The best example would be a private blog. It will hurt if you lose your data but the odds are you're not willing to pay for any reliable storage. [...] There is one reliable storage, which is 100% free and almost everybody have access to it. Yes, I'm talking about Google Drive.

He walks you through the process of setting up your Google Drive account API access and where to find the data you'll need to make the connection. He then links over to his project that makes the backup a simple few lines of code (mostly configuration) of a backup path of your choice out to the remote Google Drive account.

Link: http://systemsarchitect.net/automated-backups-to-google-drive-with-php-api

Matt Setter: How Simplicity Leads to Greater: Productivity, Quality & Satisfaction

PHPDeveloper.org - Tue, 16/04/2013 - 16:39

Matt Setter has a quick new post that suggests a way you can get more done with less work - simplicity.

Though we can do so many things simultaneously - should we? Does it actually reduce effectiveness and productivity which are the antithesis of professional application development? [...] I had the thought, as is common in a western-based mentality, that to be busy, to be industrious, to try and multi-task a series of independent tasks and projects simultaneously was the right thing to do. It's meant to be a simple formula: "Greater productivity = Greater self-worth right?" Sounds almost like Thatcherism. I felt that this was not only right, but the sign of an intelligent and sophisticated developer, who truly had honed his craft. Perhaps you've felt the same at one time or another?

He points out that, while it's very easy for developers to fall into this trap and way of thinking, it's not sustainable. It leads to stress, bad code and even - possibly - an even higher bug count. Instead he suggests the good standby idea of "KISS" (essentially, simplicity).

Instead of trying to do everything at once - I stopped and decided to only do one thing at once. And that one thing, had my full attention and focus. When it was done, I then moved on to the next one. Not before and not after.

He includes some of his own experience trying to apply this in a Zend Framework 2 application.

Link: http://www.maltblue.com/software-engineering-2/how-simplicity-leads-to-greater-productivity-quality-and-satisfaction

Community News: Packagist Latest Releases for 04.16.2013

PHPDeveloper.org - Tue, 16/04/2013 - 15:01
Recent releases from the Packagist:

Community News: Latest PECL Releases for 04.16.2013

PHPDeveloper.org - Tue, 16/04/2013 - 14:01
Latest PECL Releases:
  • pcsc 0.2 Fixed compile error on >= PHP5.4 and added w32 support

  • couchbase 1.1.4 - Prototype trying to get the thing working for PECL - Reset the error code between each request of a persistent connection - Report libcouchbase version in phpinfo - Remove gettimeofday implementation for win32 - PCBC-206: Prototype for configuration caching - Fixup memory allocation for URL path - PCBC-186: Add method to list all design docs - PCBC-178: Add support for connection_timeout - Update GetReplica test - PCBC-218: Detect invalid characters in CAS - Add bucket manipulation example - PCBC-172: Add design document examples - PCBC-191 Don't coredump for invalid argument - Update the list of supported PHP versions

  • mongo 1.3.7 ** Bug * [PHP-700] - 'MongoCursorException' with message '127.0.0.1:27017: request/cursor mismatch

Dayle Rees: Composer primer

PHPDeveloper.org - Mon, 15/04/2013 - 19:55

For those that might have heard about the Composer package management system for PHP but haven't had the time to get into it, you should definitely check out this great primer from Dayle Rees.

Composer is something special in the world of PHP. It has changed the way we handle application dependencies, and quelled the tears of many PHP developers. You see, in the olden days, when you wanted to build an application that relied on third party dependencies you would have to install them with PEAR or PECL. These two dependency managers both have a very limited set of outdated dependencies and have been a thorn in the side of PHP developers for a long time. [...] Enter composer, king of the package managers.

He jumps right in and gets into the configuration (the composer.json file) and using it to describe the package. He shows how to set up "required" resources complete with version number information. There's a bit about setting up autoloading and classmaps too. He then moves on to getting the tool installed and using the composer.json definition to load in needed packages (and development ones if needed).

Link: http://daylerees.com/composer-primer

7PHP.com: Interview with Manuel Lemos - Founder of PHPClasses.org

PHPDeveloper.org - Mon, 15/04/2013 - 18:43

On 7PHP.com today they've posted the latest PHP community interview - this time with Manuel Lemos of the PHPClasses site.

In this edition I talked with Manuel Lemos who is the founder of the famous and huge PHPClasses.org. @ManuelLemos has been rambling a lot about PHP, doing all sorts of stuffs on phpclasses back since 1999 - podcasts, interviews, sharing scripts, writing scripts, blogging, shouting and I even doubt he drinks-eats-sleeps there too (just to say how much he is hooked in there).

In the interview he answers questions about:

  • His background and how he got started with PHP
  • What he sees as the good and bad parts of the language
  • Some suggestions for developers wanting to learn
  • What frameworks/unit testing tool and CMS he recommends

There's also a section more specifically focused on the Brazilian PHP community, PHP conferences and some of the things he's learned in his time in the wider PHP community.

Link: http://7php.com/php-interview-manuel-lemos

Fabien Potencier: About Symfony: Stability over Features

PHPDeveloper.org - Mon, 15/04/2013 - 17:12

Fabien Potencier (of the Symfony framework) has a new post to his site talking about a philosophy that the Symfony framework community should work towards, providing stability over features.

Long story short: in the coming months, the Symfony core contributors should focus their efforts toward stabilizing the existing features instead of working on new ones. At this point, backward compatibility and stability are more important than everything else.

He highlights some of the points that come along with this effort including less refactoring for the sake of refactoring, fixing more bugs/edge cases and writing more tests/documentation. He gets into some of the specifics of this kind of thinking and points out the things that can and can't be changed during this time. He talks more about stability and suggests that not only can it help enhance performance but it could also help motivate more projects/corporate users to start using the framework.

Link: http://fabien.potencier.org/article/68/about-symfony-stability-over-features

SitePoint.com: What Happened when we Talked PHP with the Experts

PHPDeveloper.org - Mon, 15/04/2013 - 16:05

On SitePoint.com today they've posted the transcript of a "Talk with the Experts" session they did with Lorna Mitchell (instructor of their recent OOP sessions). The transcript includes questions and answers to those in attendance as well as some good links and advice.

Last Thursday I broke with tradition slightly and ran a Talk with the Experts session in the evening (down under), making it a bit more time-zone friendly for our UK audience. It also meant that I was able to swap my usual coffee for a wine, which probably made the session run a bit more smoothly. The subject was PHP and our expert was Lorna Mitchell, tutor of Object-oriented PHP and co-author of PHP Master: Write Cutting-edge Code.

The transcript starts with a collection of some of the links provided during the discussion and then runs through the entire conversation. There's some good advice in there, especially if you're relatively new to the world of PHP object-oriented programming.

Link: http://www.sitepoint.com/what-happened-when-we-talked-php-with-the-experts

Community News: Packagist Latest Releases for 04.15.2013

PHPDeveloper.org - Mon, 15/04/2013 - 15:06
Recent releases from the Packagist:

Community News: Packagist Latest Releases for 04.14.2013

PHPDeveloper.org - Sun, 14/04/2013 - 15:04
Recent releases from the Packagist:

Community News: Packagist Latest Releases for 04.13.2013

PHPDeveloper.org - Sat, 13/04/2013 - 15:02
Recent releases from the Packagist:

Brian Deshong: Top Ten List + CoderFaire Atlanta 2013

PHPDeveloper.org - Fri, 12/04/2013 - 19:27

Brian Deshong has a new post to his site sharing some of the content (videos) from his upcoming CoderFaire Atlanta (April 20th) talk about web application performance that he's learned over his years in development.

Back in March, I gave a new talk at Atlanta PHP: "Top Ten List: PHP and Web Application Performance". This talk is a culmination of my ~14 years of experience primarily as a web application developer, but also as a systems administrator / DevOps-type. After working with PHP and web applications for so many years, I have amassed quite a few tricks for squeezing maximum performance out of web applications, PHP or otherwise.

The tips are presented by various people from around the web development (and PHP) community and relate to things like:

  • Realpath cache settings
  • Using offline processing
  • Optimized queries
  • Gzipping responses
  • Caching everything
  • Using a content delivery network

If you'd like to see Brian present the full talk, there's still time to get your ticket for CoderFaire - they're only $50 USD for the two day event.

Link: http://www.deshong.net/2013/04/top-ten-list-coderfaire-atlanta-2013

Benjamin Eberlei: Traits are Static Access

PHPDeveloper.org - Fri, 12/04/2013 - 18:16

In a new post to his site Benjamin Eberlei shares an opinion about traits, noting that they're basically the same as static functionality when it comes to several things like coupling, not being testable and being a "global state" container.

I used to look forward to traits as a feature in PHP 5.4, but after discussions with Kore I came to the conclusion that traits are nothing else than static access in disguise. They actually lead to the exact same code smells. Familiar with the outcome of too much static use, we should reject traits as just another way of statically coupling your code to other classes.

He includes some code examples showing traits in use in an example controller to handle a simple redirect. He points out at least six different issues with just this simple implementation. He rewrites it as "static" code to help prove his point. He comes to the conclusion that, much like static methods, traits should be avoided and instead aggregation should be favored.

Link: http://www.whitewashing.de/2013/04/12/traits_are_static_access.html

NetTuts.com: PSR-Duh!

PHPDeveloper.org - Fri, 12/04/2013 - 17:46

On NetTuts.com today there's a post that talks about applying the PSR formatting to your application's code. If you haven't already read their introduction to the PSRs, it's highly suggested.

In a previous lesson here on Nettuts+, you learn about PSR; however, that article didn't detail the process of integrating that coding style into your projects. Let's fix that!

They briefly recap the main two PSRs (PSR-1 and PSR-2, but no mention of PSR-3 the logging interface) and show code examples of them being applied. They also point to the PHP_CodeSniffer tool that you can use to keep your code in the correct structure. Instructions are included to install it specifically for the Sublime Text 2 editor via package control. It's just a command-line tool, though, so it could be integrated with just about any other editor/IDE out there too.

Link: http://net.tutsplus.com/tutorials/tools-and-tips/psr-duh

PHPMaster.com: Scrum - An Agile Project's Best Friend

PHPDeveloper.org - Fri, 12/04/2013 - 16:26

PHPMaster.com has posted a bit less of a technical article than usual and shares some of the concepts behind scrum, the project management style that's currently quite popular with development groups.

In an earlier article I wrote, we took a general look at project management and discussed what some of its pitfalls are that should be avoided. As part of that, I mentioned that you should, as much as possible, be using an Agile methodology, particularly Scrum, to manage development. I'd like to follow that up with a look at Scrum and at how we can use it to tame our projects.

He talks about the typical "waterfall" technique of project development - requirements up front and cross your fingers for the rest. He compares this to the agile process and how scrum, in particular, helps keep things from falling apart. He then gets in to "how to scrum" by defining some of the key terms and talking about things like:

  • Holding smaller meetings
  • Limiting scope and time frame
  • Looking for feedback
  • Constant reworking remaining time

...all at the same time, multiple times during the life of the project. Agile focuses on quick changes and updates because the project is constantly getting feedback from those asking for the product, giving them (hopefully) exactly what they want.

Link: http://phpmaster.com/scrum-an-agile-projects-best-friend

Community News: Packagist Latest Releases for 04.12.2013

PHPDeveloper.org - Fri, 12/04/2013 - 15:01
Recent releases from the Packagist:
Syndicate content