Reporting with Zend_Tool and Zend_

Jon Lebensold posts a continuation to his screencast on Zend_tool; Reporting with Zend_Tool and Zend_Log

This video uses a collection of powerful PHP libraries in order to illustrate how easy it really is to build a command-line tool for reporting against XML files. We start off by logging visitor statistics in the controller into a log file with Zend_Log. Once data has been collected, we’re then able to utilize SimpleXML, Zend_Date and the Zend_Tool component to build out a very simple reporting tool. This is of course just an example of what’s possible. What comes to mind for me is building a cron job for generating reports based on the zf.sh executable, or even just doing backups at the command-line with the help of a fully integrated Zend Framework installation.

I’ve noticed that configuration information isn’t properly loaded into Zend_Tool and am still trying to figure out the design decisions there. You’ll notice that I was having some timezone issues with regards to Zend_Date and it seems that specifying a timezone in my application.ini file didn’t resolve the issue.

Grab a copy of the project or browse the repository.

via Zendcasts.

Zend Framework 1.10.4 Released – Notably Zend_Amf 200-300% faster

On behalf of the Zend Framework community, I’m pleased to announce the immediate availability of Zend Framework 1.10.4, our fourth maintenance release in the 1.10 series. You can download it from our downloads page:

http://framework.zend.com/download/latest

This release includes approximately 50 bugfixes, the majority of which were contributed during our Bug Hunt Days two weeks ago. The fixes contributed help stabilize and improve the 1.10 series.

Three fixes in particular are worth noting:

* ZF-7493: an important serialization improvement in Zend_Amf that has
been benchmarked as providing 200-300% faster serialization of large
datasets.

* ZF-9263: a fix to Zend_Loader::isReadable() to fix a regression found
on Windows platforms. This fix should eliminate most if not all
raised warnings that occurred during resource and plugin loading.

* ZF-9504: a patch was applied to Zend_XmlRpc_Value to make value
generation more efficient. Benchmarks and profiling show enormous
changes on large datasets: in one example, memory usage drops from
>1GB to 20MB, while dropping from execution times of >60s to around
10s.

We’d like to thank everyone who committed time, code, and translations since the 1.10.3 release — the community has been quite productive!


Matthew Weier O’Phinney

Integrating Zend_Tool Into Your Application

Jon Lebensold shows you how to use the Zend Tool in useful ways; This screencast should help you setup Zend_Tool in your Zend Framework application. Zend_Tool is a command line entry point into your application. Currently, Zend_Tool is used to scaffold (build generic files) the Zend Framework project structure, modules, controllers, database table classes and other tedious processes. The goal of this video is to start looking at how we can generate our own Manifest and Provider classes so that custom command line tools can be integrated into the Zend Framework application.

The advantage of such integration is far reaching: deployable web applications using the Zend Framework can have “installers” and other frameworks, like Doctrine, can easily become first class citizens within the Zend Framework eco-system.

Grab a copy of the project or browse the repository.

via Zendcasts.

Ajaxify Your Zend_Form Validation with jQuery

Jon Lebensold posts an update to his excellent screencast; We’re going to take what was put together in the last 3 videos and now include some server-side validation that will appear asynchronously. This is an example of using Zend_Form as a validation tool via JSON.

Grab a copy of the project or browse the repository.

UPDATE: as a couple people have mentioned, you can cut down your IndexController even more by using the Zend_Json view helper:

public function validateformAction()
{
$f = new Form_Registration();
$f->isValid($this->_getAllParams());
$this->_helper->json($f->getMessages());
}

Enjoy!

See it at Zendcasts.

An Illustrated Guide to Git on Windows

This document is designed to show that using git on Windows is not a difficult process. In this guide, I will create a repository, make several commits, create a branch, merge a branch, search the commit history, push to a remote server, and pull from a remote server. The majority of this will be done using GUI tools.

Although this guide is targeted for use on Windows, the git gui tool works the same on all platforms. Because of this, git users on other platforms may find useful information here as well.

via An Illustrated Guide to Git on Windows.

Zend Framework: Module Specific Layout Plugin

Graham Anderson posted an useful workaround for the module specific layout problem;
The default layout plugin will accept a stack of paths in LIFO order.
This allows a very simple hack to always ensure that any module can have it’s own default layout which will automatically override the default module layout.


class App_Controller_Plugin_Layout extends Zend_Controller_Plugin_Layout {

public function __construct ($layout = null)
{
parent::__construct ($layout);
}

public function preDispatch(Zend_Controller_Request_Abstract $request)
{
// Insert current module layout dir to to overide any default layouts
if ( $request->getModuleName() != 'default' ) {

$layoutPath = APPLICATION_PATH . '/modules/' .
$request->getModuleName() . '/views/layouts';

$paths = array();
$paths[] = $this->getLayout()->getViewScriptPath();
$paths[] = $layoutPath;

$this->getLayout()->setViewScriptPath($paths);
}
}
}

Asssuming you set the following application config value:


resources.layout.layout = "default"

Now any module with a default.phtml layout will override the default module layout.

e.g APPLICATION_PATH/modules/foobar/views/layouts/default.phtml

Cheers the noo,
Graham

Better Zend Framework Documentation

Chris Morrell comes with a very nice intermediate solution to ZF documentation hassles, he writes;

If you’ve every tried to navigate the Zend Framework documentation’s longer pages you’ve probably looked everywhere for a table of contents. Sure, there’s a TOC for the major sections of the component, but if you’re looking for a specific part of a page (or an overview of what that page covers) you’re out of luck. For example, take a look at the Zend_Validate list of standard validation classes. Now try to find the documentation on the URI validator. Can’t find it? That’s ’cause it doesn’t exist. Too bad you had to scroll down through 39 page-lengths’ worth of documentation to find that out.

Wouldn’t it be nice if you’d had something like this:…

Read on “Better Zend Framework Documentation” by Chris Morrell.

Zend Framework: Passing objects to Partial Views

Hector Virgen gave some hints about how to pass object into partial views and partial loops;

You can pass objects to partials, just pass them in an array:

<?= $this->partial('mypartial.phtml', array('topic' => $topic')) ?>

The partial helper will take the keys of that array and create view vars out of them, so you can access it like this from within the partial:

<?= $this->topic->getDescription() ?>

If you want to use objects with a partial loop, you can call setObjectKey() on the partialLoop helper and pass in an array of objects:

<?= $this-partialLoop()->setObjectKey('topic')
->partialLoop('mypartial.phtml', $topics) ?>

Editors remark: Easy once you seen it done 🙂

PHP 5.3 namespaces for the rest of us

According to the official documentation, PHP namespaces have been designed to prevent name collisions between classes from different packages and to avoid the use of very long names in the code to refer to classes or functions—nobody really wants to have to deal with something called Zend_Db_Adapter_Mysqli or PHPUnit_Framework_Constraint_IsInstanceOf, after all. This means that namespaces help a developer write code that is both more concise and clearer—a direction which is always an improvement towards expressiveness.

Within the PHP implementation of namespaces, these names will be ideally refactored to Zend\Db\Adapter\Mysqli and PHPUnit\Framework\Constraint\IsInstanceOf, where \ is the namespace separator. In the codebase, however, there will typically be very few references to these classes with their fully qualified name, because it is possible to import entire namespaces in a script and then use the class names directly, making the code easier to follow and unambiguous to write.

In fact, the definition of a namespace class itself does not contain its fully qualified name. For example, this would be the source file of an hypothetical MyLibrary\TypeOfComponents\MyClass class:

<?PHP
namespace MyLibrary\TypeOfComponents;
class MyClass
{
// ...
}

The convention when writing namespace-enabled code is that of creating a folder structure that reflects the individual components of a namespace (for example, MyClass would be in the MyLibrary/TypeOfComponents directory. This helps standardizing the autoloading process.

Read the full story PHP 5.3 namespaces for the rest of us | php|architect.

Introducing a Tool for Namespacing PHP5 Prefixed codebases

Ralph Schindler writes;
Hey All-

Over the past few days, I’ve been working on a tool that I think might help expedite the task of converting all of our code into a Namespaced codebase.  Currently, it’s been tested on simple components like Zend_Acl and Zend_Filter and over the course of the next few days, we’ll be applying it to some of the more complex components.

What it does..

This tool is a command line tool.  First, you may get it from my GitHub repository:

http://github.com/ralphschindler/PHPTools

git clone http://github.com/ralphschindler/PHPTools.git

-OR-

Just download the tar/gz/zip via the github interface.

Inside here you’ll find a bin/ library/ and test/ directory, the namespacer tool is located in this library.  To get the basic help screen, simply run ‘php bin/php-namespacer.php -h’.  This will give you a couple of available options to understand what the various command line switches do.  Personally, I create a link from somewhere in my path, usually $HOME/bin/php-namespacer to path/to/PHPTools/bin/php-namespacer.php, this makes it easier to run the command from anywhere in your filesystem.

To be able to get up and running with it quickly, I suggest running to tool in the following manner to get an idea of what it will produce:

bash> php-namespacer -l=../library/ -d=Zend/Acl -p=Zend -o=./tmp/ -m=./tmp/

Here are is what the above is going to do:

  • with the -l switch, you are telling it the location of a library this is typically the same directory you’d add to an include_path
  • with the -d switch, you are telling the tool that of all the classes it comes across in the library, only work on this particular directory
  • -p is the prefix we want to work on, in our case Zend/
  • -o is the directory where you want your new files written to
  • -m is the directory where an XML file will be produced of all the name translations that have taken place.

The full library is supplied so that the tool can iterate all files for class names that might be present inside the working directory’s files.

This is so that it knows what those translations will be once those components are eventually converted (assuming they are part of the same effort).

This tool will OPTIONALLY convert names in docblock ONLY if you have the pecl ext/docblock extension compiled and enabled (http://pecl.php.net/package/docblock).  Otherwise it will not touch the docblocks.

I have to admit that even though we are seeing some great results so far, this tool is still in it’s infancy.  We are opening it up to you for feedback and if you find it useful, to run it over your own code to see if it does the job of converting prefixed PHP5 code into namespaced PHP 5.3 code.

I’ll let everyone get a chance to run the tool and produce some output first before we start discussing the actual output and file contents.

For discussion purposes, we’ve been heavily looking at simpler components like Zend_Acl, Zend_Filter and Zend_Config- but don’t let that stop you from running it over other components or even your own code.

Let me know what you think!

Ralph Schindler