Accessing Bootstrap Resources from Anywhere

Aleksey V. Zapparov posts a very nice solution to a very common question when dealing with Bootstrap resources;

Hello,
You can either register precious resources in registry, e.g.:


protected function _initMyResource()
{
$res = 'foobar';
Zend_Registry::set('myResource', $res);
return $res;
}

Or you can register the whole bootstrap, so you can place in it’s constructor, something like this:


public function __construct($application) {
parent::contstruct($application);
Zend_Registry::set('Bootstrap', $this);
}

So later you’ll be able to access resources via:

$res = Zend_Registry::get('myResource');

or:

$res = Zend_Registry::get('Bootstrap')->getResource('MyResource');

And there is another way to get your bootstrapper from almost
everywhere:

$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
$resource = $bootstrap->getResource('MyResource');

Sincerely yours,
Aleksey V. Zapparov A.K.A. ixti

Zend Framework Class to retreive your RSS feeds used in Google Reader

Rémi Goyard wrote a nice little class to access your Google Reader Feeds take a peek below, he says;

I finally wrote my own class to retreive data from my Google reader Account (stared items, shared items, …)
The class needs some more work.
Regards
Rémi

< ?php /** * Class to retreive your rss feeds used in Google Reader * thanks to : * @see http://www.niallkennedy.com/blog/2005/12/google-reader-api.html * @see http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI * * @author Rémi Goyard * @category Core * @package Core_Gdata * @subpackage Gdata * @copyright Rémi Goyard * @license http://framework.zend.com/license/new-bsd New BSD License * @version 0.1 */ /** * Zend_Gdata_HttpClient */ require_once 'Zend/Http/Client.php'; /** * Zend_Version */ require_once 'Zend/Version.php'; class Core_Gdata_Reader{ /** * The Google client login URI */ const CLIENTLOGIN_URI = 'https://www.google.com/accounts/ClientLogin'; /** * The default 'source' parameter to send to Google */ const DEFAULT_SOURCE = 'Zend-ZendFramework-Google-Reader 1.0/Zend'; /** * The Google reader Base URI */ const GOOGLE_READER_BASE_URI = "http://www.google.com/reader/"; /** * Default Google Reader Actions */ private $GOOGLE_READER_ACTIONS = array( "subscriptions" =>"atom/user/[USERID]/pref/com.google/subscriptions",
"starred" =>"atom/user/[USERID]/state/com.google/starred",
"shared" => "atom/user/[USERID]/state/com.google/broadcast",
"broadcast" => "atom/user/[USERID]/state/com.google/broadcast",
"read" => "atom/user/[USERID]/state/com.google/read",
"reading-list" => "atom/user/[USERID]/state/com.google/reading-list",
"tag" => "atom/user/[USERID]/label/[TAG]"
);

/**
* Default Params
*/
private $_defaultParams = array("n"=>20);

const SERVICE_NAME = "reader";

private $_userID = "";
private $_email = "";
private $_password = "";

/**
* @var Zend_Http_Client
*/
private $_client = null;

/**
*
* @param string $email
* @param string $password
* @param string $userID
*/
public function __construct($email, $password, $userID){
if (! ($email && $password && $userID)) {
require_once 'Zend/Exception.php';
throw new Zend_Exception(
'Please set your Google credentials before trying to ' .
'authenticate');
}
$this->_email = $email;
$this->_password = $password;
$this->_userID = $userID;
$this->_setHttpClient();

}
private function _setHttpClient()
{
if (! ($this->_email && $this->_password)) {
require_once 'Zend/Exception.php';
throw new Zend_Exception(
'Please set your Google credentials before trying to ' .
'authenticate');
}
$this->_client = new Zend_Http_Client();
$this->_client->setParameterPost("Email", $this->_email);
$this->_client->setParameterPost("Passwd", $this->_password);
$this->_client->setParameterPost("Service", self::SERVICE_NAME);
$this->_client->setConfig(array(
'maxredirects' => 0,
'strictredirects' => true,
'useragent' => self::DEFAULT_SOURCE.Zend_Version::VERSION
)
);
$this->_client->setUri(self::CLIENTLOGIN_URI);
$this->_client->setMethod("POST");
$response = $this->_client->request();
if($response->getStatus() == 200){
foreach (explode("\n", $response->getBody()) as $l) {
$l = chop($l);
if ($l) {
list($key, $val) = explode('=', chop($l), 2);
$this->_client->setCookie($key,$val );
}
}
return true;
}else{
$this->_client = null;
require_once 'Zend/Exception.php';
throw new Zend_Exception('Authentication Error got Response Code : '.$response->getStatus());
}
}

/**
* Import Atom Feed
*
* @param String $type request type
* @param Array $params request params
* @return Zend_Feed_Abstract
*/
public function import($type, $params = array())
{
if(array_key_exists($type, $this->GOOGLE_READER_ACTIONS)){
if(! empty($params)){$this->_defaultParams = $params;}
// TODO : TAG ...
// TODO : manage POST actions
$urlId = str_replace("[USERID]", $this->_userID, $this->GOOGLE_READER_ACTIONS[$type] );
$url = self::GOOGLE_READER_BASE_URI.$urlId;
$this->_client->resetParameters();
$this->_client->setMethod("GET");
require_once 'Zend/Feed.php';
Zend_Feed::setHttpClient($this->_client);
return Zend_Feed::import($url);
}else{
require_once 'Zend/Exception.php';
throw new Zend_Exception('The action '.$type.' does not exists or is not yet implemented');
}
}
}

MySQL does support preparing some DDL statements, However…

Bill Karwin gives some insight into some work arounds when creating functions, triggers and procedures using Zend Framework;

MySQL does support preparing some DDL statements, even in older versions. See http://dev.mysql.com/doc/refman/5.1/en/sql-syntax-prepared-statements.html
for lists of what statements can be prepared.

However, some DDL statements are still not supported as prepared statements, for example CREATE FUNCTION, CREATE TRIGGER, CREATE PROCEDURE.

DELIMITER is not supported as an executable statement at all, whether you prepare it or whether you do an immediate execute. Statements like DELIMITER, PAGER, SOURCE, CONNECT, and QUIT and others are builtins of the mysql command-line client. These commands are not recognized by the MySQL server.

You need to set the DELIMITER only if you’re running the CREATE FUNCTION statement in an SQL script. The default API for SQL statements does not support multiple statements per call. So you don’t have to delimit statements and you don’t have to change the delimiter.

So Nils’s solution should be the following:

1. Don’t worry about DELIMITER, you don’t need it.

2. You must DROP and CREATE in two separate statements.

3. Bypass the default ZF query method. Go directly to the
PDO::query() method when you execute a statement that isn’t preparable. You can access the PDO object using the getConnection() method of your ZF Db adapter:

$db->getConnection()->query( $drop_function_statement );
$db->getConnection()->query( $create_function_statement );

Regards,
Bill Karwin

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

FastCopy – Moving / Copying files Lightning fast on Windows

Anyone that has been working on a Windows based system (Regardless of what version) groans everytime you have to copy or move many files from a drive to another…

I did however find this little gem that takes most of the pain out of it;

FastCopy is the Fastest Copy/Delete Software on Windows.

It supports UNICODE and over MAX_PATH 260 byte pathname files. It automatically selects different method according to whether Source and DestDir are in the same or different HDD.

  • Diff HDD Reading and writing are processed respectively in parallel by another thread.
  • Same HDD Reading are processed until the big buffer fills.

When the big buffer filled, writing are started and processed in bulk.Because Reading/Writing are processed with no OS cache at all, other applications aren’t easy to become heavy.

It can bring out Reading/Writing performance that is close to device limit.Include/Exclude Filter UNIX Wildcard style can be specified. It runs lightly, because MFC is not used. made by Win32 API and C Runtime only

You can modify this software, because all source codes have been opened to the public in the BSD license.

Editors note: And no it’s not an April Fools joke 🙂
Get it via FastCopy.