News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Master Zend Framework:
Creating Custom ZFTool Diagnostic Classes
May 21, 2014 @ 11:23:59

Continuing on from his previous post introducing you to the ZFTool for Zend Framework 2 applications, Matthew Setter has posted part two of the series focusing on the creation of custom diagnostic classes for the tool.

In this week's tutorial, we're going to see how to step beyond the in-built classes and write our own custom checks. Specifically, we're going to write a check which runs php lint on the module's config file, module.config.php. The reason for doing this is because this file is so important in the configuration of a ZF2 module, that we should have a helpful sanity check for it.

He starts by helping you get all the needed dependencies in place, the ZFTool and ZendDiagnostics modules, installed via Composer. He includes code to help get started on the new diagnostic class and accompanying files. He implements some required methods from an interface, and shows how to enable its checking and define the configuration file. He includes a screenshot of the output so you can ensure things are working as they should be.

0 comments voice your opinion now!
zendframework2 zftool custom diagnostic class tutorial

Link: http://www.masterzendframework.com/zftool-2/creating-a-custom-zftool-diagnostic-class

PHPClasses.org:
Speedup Your Web Deployments Using Composer to Install PHP Classes Packages
December 12, 2013 @ 11:43:01

On the PHPClasses.org site today Manuel Lemos has a new post showing how you can use Composer in your deployments to help install packages from the PHPClasses site.

You can install one or more packages from PHP Classes, JS Classes or other Composer repository sites. [...] To make it simpler for you, PHP Classes and JS Classes generate a sample composer.json file for each package available in the Composer repository. Just go in the page of the package you want to install and click on the Install with Composer link.

He includes a brief guide on installing Composer and an example of the resulting "composer.json" file when you click on a link in a package. He points out the use of logins (depends on the package maintainer) and the use of an "auth.json" to automatically provide this information.

This is a great example of how a site that puts the Composer ecosystem to work to provide packages outside of Packagist. Composer, by default, relies on Packagist for its package information, but you can provide alternate repositories too - including using something like Satis for local packages.

0 comments voice your opinion now!
phpclasses composer install repository custom

Link: http://www.phpclasses.org/blog/post/221-Speedup-Your-Web-Deployments-Using-Composer-to-Install-PHP-Classes-Packages.html

Chris Hartjes:
Testing Listeners
September 30, 2013 @ 11:56:39

In the latest post to his site, Chris Hartjes offers some advice about unit testing with listeners to help teach PHP developers the right way to test.

I had an idea to put together some kind of "PHP Testing Koans" site as a way to help PHP developers get better at learning how to actually write tests. Most developers who are introduced to testing get blocked at the point of actually writing a test. [...] So I started to brainstorm ways to make it happen. With some help from Joel Clermont I stumbled upon using test listeners for this.

He uses the built-in test listeners for PHPUnit to write a system that checks to ensure a certain test exists in a "Koan1Listener" class. This class implements the PHPUnit_Framework_TestListener interface and has several methods to catch events and handle issues thrown during execution.

The approach is simple: for each test class that gets executed, add the names of all the methods to an internal list. When the entire test suite is finished, we then check to see if the test names that we were expecting are in our list of methods we found. I am sure there is a more efficient way to do it, so let me know in the comments of a different approach.
0 comments voice your opinion now!
unittest testing listener custom phpunit koans

Link: http://www.littlehart.net/atthekeyboard/2013/09/27/test-listeners/

PHPMaster.com:
Openbiz Cubi A Robust PHP Application Framework, Part 2
May 22, 2013 @ 10:27:16

PHPMaster.com has posted the second part of their look at the Openbiz Cubi framework (part one here), this time focusing on the code - mostly XML - that you'll need to create your own custom module.

In the first part of this series we talked about the development challenges we face and how Openbiz Cubi can help by providing a solid, ready-to-use web application framework. In this part we'll see how to build our own module and dive a bit deeper into the core architecture of the framework.

They include the SQL you'll need to run to create a new table for the "Customer" module they're going to help you build. With that in place, they walk you through the command to execute to make the module skeleton, the locations of the XML files to work with and the contents of each. Included in the module are things like a data object, a module description file and the form object. He finishes up the post with a look at the overall flow of the Cubi execution so you know where each piece falls.

0 comments voice your opinion now!
openbiz cubi tutorial series part2 application framework module custom

Link: http://phpmaster.com/openbiz-cubi-a-robust-php-application-framework-2

NetTuts.com:
Your One-Stop Guide to Laravel Commands
March 01, 2013 @ 10:56:44

Over on NetTuts.com today they've published a "one stop guide" to creating Laravel commands that can make using the Laravel PHP framework simpler. The format for these commands are more related to the Laravel 4 version of the framework (still in beta).

In this day and age, it's quite normal for a developer to have an understanding of consoles, and how to issue basic commands. But what if you could code your own custom commands to improve your workflow? If we look back to Laravel 3, you might remember that it offered tasks. Tasks were extremely helpful, but still came up short for more complex operations. Thankfully, Laravel 4 packs a beefed up Artisan that will make your life as a developer so much easier!

They start by introducing you to Artisan and what it can do already, then move into how you can create you own custom commands (with code examples). They show you how to add a description, coloring for the output, work with arguments, use confirm/question prompts and working with dependencies you might need.

0 comments voice your opinion now!
tutorial laravel4 artisan commandline example custom


Joshua Thijssen:
Custom symfony2 config loader
January 30, 2013 @ 11:51:47

In his latest post Joshua Thjissen looks at the creation of a custom configuration loader for a Symfony2 application. This kind of thing is mostly useful for parsing configurations that Symfony2 doesn't already know how to parse.

It happens more and more: large projects where your symfony2 site is just a small part in the big picture. Lots of additional components might even play a bigger part, especially when you are dealing with asynchronous components which are connected through message queues for instance. [...] Our first idea is obvious: symfony2 uses by default a parameters.yml file, which gets imported by your configuration (config.yml) [...] So nothing new here and this setup works perfectly, provided that your symfony2 project is the ONLY thing that needs to be configured. As soon as you add multiple other components (like gearman or activemq workers that need to connect to solr too), they need to share this configuration.

His solution involves falling back to the INI-file format that's known as useful for several different languages and tools. Because of how Symfony2 reads these files though (only looking for "parameters") he's had to create a "ConfFileLoader" instance of the "FileLoader" that uses the parse_ini_file method to parse the data and return it back to the main container as parameters. He also includes the code/config you'll need to implement this custom loader into your application.

0 comments voice your opinion now!
custom loader symfony2 configuration file ini loader


PHPMaster.com:
Exceptional Exceptions
November 16, 2012 @ 11:49:08

On PHPMaster.com today they have a new post from Remi Woler about "exceptional exceptions" - using exceptions to handle the flow of your application's execution a bit better.

Unlike errors, exceptions are designed to be handled by the calling code and will bubble up the execution chain until they are caught. Code in the current scope will stop executing as soon as an exception is thrown (so any lines after a throw statement won't be executed) and control is handed back to the first matching exception handler (either a catch block, configured exception handler, or language-provided exception handler). Only when an exception is caught will code execution continue from there. This article does not aim to teach you exceptions at a 101 level, but instead gives an opinion on how to use exceptions better

The post helps you determine the difference between an error and an exceptional event and gives examples of the sorts of things he considers exceptions useful for. He also talks about throwing different kinds of exceptions to make their context more meaningful, but notes that this has been known to cause trouble if used too much.

In summary, only throw exceptions when your code cannot complete the requested instruction with the given input, always throw a custom exception that actually tells the calling code what the situation is, and if you call other code then only catch the exceptions that you can and should handle.
0 comments voice your opinion now!
exception tutorial cases custom error catchall


PHPMaster.com:
Setting Custom Error Messages for Zend_Form_Element
October 11, 2012 @ 08:58:37

On PHPMaster.com today there's a new post for all the Zend Framework (v1) users out there. In it, Aurelio De Rosa shows you how to set custom error messages for elements in a Zend_Form.

In this article I'll show the solution to a common problem which arises when a developer has to create a non-English website or application that is based on the Zend Framework. How do we mark a field of a Zend_Form which is a Zend_Form_Element as invalid, showing one or more custom error messages? The problem is mainly caused by the native counter-intuitive methods of the Zend_Form_Element class which I'll explain in more details.

He's included a basic example showing the creation of a form and the setup of a text element and some validators to match. He makes a controller and view to handle the output and submission then shows how to use "setErrors" (and "setErrorMessages") of the Zend_Form elements to setup that custom error. This only lets you set one message, though, regardless of the point of failure. To stop things when there's an error, you have to set the "breakChainOnFailure" parameter on the validator to false - then the message will make more sense.

0 comments voice your opinion now!
zendframework1 zendform custom error message element tutorial


Juan Treminio:
Composer Namespaces in 5 Minutes
October 02, 2012 @ 15:47:32

Juan Treminio has a new post to his site today talking about Composer and namespacing and shows you how the two work together to make using 3rd party tools easy.

You've heard of Composer, right? The nifty new tool for PHP that aims to centralize and streamline package management? Do you also know of, but don't really understand how namespaces work in PHP? Then let's set you straight! In 5 minutes you'll learn how Composer's autoloader and namespaces work!

He's broken it up into a few sections:

  • Getting Composer up and running
  • Making a basic "composer.json" file
  • Going through what the "install" creates (including the "autoload_namespaces.php" file)
  • Using the vendor/ autoloader

As a bonus, he also shows how to implement your own namespacing in the "composer.json" file if you have a special case - just use the "autoload" section in the configuration (examples included).

0 comments voice your opinion now!
composer namespace introduction custom configure


PHPMaster.com:
Testing Error Conditions with PHPUnit
October 02, 2012 @ 11:57:40

Over on PHPMaster.com there's a new post for the unit testers in the audience (you all unit test, right?) from Matt Turland about testing error conditions in your applications.

Let's say you're maintaining code that uses PHP's native trigger_error() function to log error information. Let's also say that you're in the process of using PHPUnit to write unit tests for that code. If you refer to the PHPUnit manual, there's a section that deals with testing for error condition. [...] However, depending on what your code looks like, it's possible that you'll run into a problem with PHPUnit's approach to this. This article will detail what this problem is, how it impacts your ability to test your code, and how to go about solving it.

He points out that, since errors and exceptions handle differently, you have to work with them differently in your tests. PHPUnit has a feature that automatically turns errors into a specific type of exception when they're thrown and how, by using a simple custom error handler, you can more correctly tests error vs exception.

0 comments voice your opinion now!
unittest error exception phpunit tutorial handler custom



Community Events





Don't see your event here?
Let us know!


podcast code introduction series threedevsandamaybe install configure framework language wordpress release unittest interview testing list developer opinion community refactor laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework