Adobe Wave

Posted in Flash, General at 8:50 am by Madarco

Another cool product form Adobe: Adobe Wave

Adobe® Wave™ is an Adobe AIR® application and Adobe hosted service that work together to enable desktop notifications for web publishers, large and small.

Simply speaking it is an Air application that receive notifications from the Adobe free Publisher Service.
With Wave site owners can use a simple REST api to send notifications, while desktop users can use a single application to receive notifications from multiple sources.

Wave flowchart

Wave flowchart

How to make your own Zend Framework Resource Plugin

Posted in PHP at 4:36 pm by Madarco

A recent release of Zend Framework intruduced Zend_Application: an organized way to bootstrap the framework without the need of an ugly boostrap.php file.
It comes with plugins support too, so let's see how to create one.

With Zend_Application you can not only setup all the components required (Zend_Table, Zend_View, Zend_Navigation, ecc) but you can also setup your own custom plugin, called Resource.

In the Zend lingo a Resource is a plugin loaded by the Zend_Application and configured through the application.ini file or in the Bootstrap.php class.

A Resource can be used to setup a standard Zend component, routes, controller plugins or your custom component.

Lets see how.

Use the Bootstrap class

When you create an empty Zend Framework project with the zf create project command, you'll find a Bootstrap.php file in your application folder.

In this file there is a Bootstrap class that you can use to define your own resources by simply creating a method with the _init prefix.

For example:

PHP:
  1. class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
  2. {
  3.     protected function _initDoctype()
  4.     {
  5.         $this->bootstrap('view');
  6.         $view = $this->getResource('view');
  7.         $view->doctype('XHTML1_STRICT');
  8.     }
  9. }

This setup a resource called Doctype.
This resource simply set the doctype property in the view (which is a resource too).

With the $this->bootstrap('view'); line, the Doctype resource requires the initialization of another resource: the View. In this way you can define dependencies in your resources.

You can even override the definition of a standard resource with your own, for example:

PHP:
  1. protected function _initView()   
  2. {
  3.      $view = new Zend_View();
  4.      return $view;
  5. }

In this way Zend_Application will use the view resource defined in your _initView method instead of the standard one.

With this method you can customize your Zend Framework with ease, but when you need to configure a standard component, like the db connection, there is a better approach: using the application.ini.

Use the application.ini file

Another gift of the zf create project command is the application/configs/application.ini file.

It contains all the configurations options of your application.
You can for example use it to configure your db:

INI:
  1. resources.db.adapter = "pdo_mysql"
  2. resources.db.params.host = "localhost"
  3. resources.db.params.username = "root"
  4. resources.db.params.password = ""
  5. resources.db.params.dbname = "test"
  6. resources.db.isDefaultTableAdapter = true

You could use either the Bootrap or the application.ini method for this task, however I personally prefer this method when configuring parameters that changes across the servers (development, testing, production) like the include paths or the db connection options.

A better approach: Create a custom resource class

To improve reusability, you can create a custom resource class, that can be easily distributed and configured through your application.ini.

Its simple: in your library create a MyResource folder and a Custom class:

PHP:
  1. //In library/MyResource/Custom.php:
  2. class MyResource_Custom extends Zend_Application_Resource_ResourceAbstract
  3. {
  4.     public function init() {
  5.         $this->getBootstrap()->bootstrap('view');
  6.         $view = $this->getBootstrap()->getResource('view');
  7.         $view->doctype('XHTML1_STRICT');
  8.         return $view;
  9.     }
  10. }

In the init method, you can initialize your resource, and return it.
The object returned will go in the resources repository, and it will be accessible with the $bootstrap->getResource('custom') call in the other resources. (hint: is case insensitive)

To use your newly created resource, you can simply put that in your application.ini:

INI:
  1. ;Add the libray/MyResource folder to the plugin search path:
  2. pluginPaths.MyResource = "MyResource"
  3. ;enable your Custom resource:
  4. resources.custom = true

That's all.

A resource can take configuration options too, for example:

INI:
  1. ;Add the libray/MyResource folder to the plugin search path:
  2. pluginPaths.MyResource = "MyResource"
  3. ;enable your Custom resource while setting the "doctype" option:
  4. resources.custom.doctype = "XHTML1_STRICT"

Zend_Application will automatically initialize a resource when you set a configuration option in it.
If our resource doesn't expect a parameter, you can simply write resources.*resourcename* = true, like in the previous example.

You can access the options from within the resource through the $this->options variable. You can also define a setter method for the option:

PHP:
  1. //In library/MyResource/Custom.php:
  2. class MyResource_Custom extends Zend_Application_Resource_ResourceAbstract
  3. {
  4.     var $doctype = 'XHTML1_STRICT';
  5.     //Setter method for the doctype option:
  6.     public function setDoctype($value) {
  7.         $this->doctype = $value;
  8.     }
  9.  
  10.     public function init() {
  11.         $this->getBootstrap()->bootstrap('view');
  12.         $view = $this->getBootstrap()->getResource('view');
  13.         $view->doctype($this->doctype);
  14.         return $view;
  15.     }

You are now ready to build your distributable plugin for Zend Framework, for other examples see the Zend/Application/Resource folder in the framework distribution or my MadaConsole resource.

MadaConsole – A debug console for Zend Framework

Posted in PHP at 11:32 am by Madarco

Update: See my guide on How to make your own Zend Framework Resource Plugin

Building Facebook applications with Zend Framework, I've needed a debug console that can shows messages even in a Facebook canvas page, through an ajax request or a redirect.

For this purpose I've build a custom plugin for ZF that fits the need: it will sit under your pages and shows all your dumped object, messages and queries.

MadaConsole debug console

MadaConsole debug console

Usage is really simple: copy in your library and add the plugin in your Boostrap or application.ini.
For a detailed guide see below.

Features

  • Trace custom messages easily: debug("A debug message");
  • Dump variables easily in your code with the pass-through function:
    Before: array_count_values($arr); After: array_count_values(debug($arr));
  • Shows the queries executed by your Zend_Table
  • Shows debug messages even through redirects or ajax requests

Install

Installing the plugin is simple:

  1. Download the archive: MadaConsole
  2. Unzip the library folder of the archive in the library folder of your Zend Framework application

Then you can configure it with two methods: through your application.ini or in the Bootsrap class.

Method1: application.ini

Add those lines after [development : production]:

pluginPaths.MadaConsole = "MadaConsole"
resources.console = true

Method 2: Bootstrap class

Add this method:

PHP:
  1. public function _initConsole() {
  2.      return MadaConsole_Console::initialize($this);
  3. }

Usage

Now in your code you can do:

PHP:
  1. debug("A debug message");
  2. debug($myArray);
  3.  
  4. $data = debug($myModel->findAll());
  5. //It will recognize Zend_Db_* objects

With the pass-through functionality you can simply add the debug() function in your existing statements with ease: $var = debug(my_func($foo));

To see the debug output when you do an ajax request, you can open a page of your choice in another browser window: the debug console will show all the messages site-wide.

Downloads

MadaConsole plugin
MadaConsole example Zend Framework project

How the debug console looks like

How the debug console looks like

Opera’s response to Google Weave: Opera Unite

Posted in General at 11:44 am by Madarco

Opera ha just announced Opera Unite: a web server that run inside the browser and that will offer functionalities similar to Google Weave. Who will win the real-time web war?

Read the rest of this entry »

Wonderfl – Collaboratively build flash demos

Posted in Flash at 5:49 pm by Madarco

Simply Wonderfl, that site allows to write as3 code directly from the browser and compile the result, while other users are able to see it and fork it to create a new version. Like a flash demo scene on steroid. Inestimable for finding nice effects for flash. Some interesting examples: Clouds rendering "Dune" like desert [...]

Read the rest of this entry »

First Flash10 P2P application unveiled

Posted in Flash at 12:34 pm by Madarco

Today I've found FilesOverMiles: a website that allows the exchange of files between two users with a P2P connection using Flash. This is possible thanks to the new Flash 10 P2P capability. However, this P2P feature needs an initial handshake between the clients to start the connection, and it is done through a "rendezvous service". [...]

Read the rest of this entry »

RegExr – Write and share regular expressions

Posted in Flash, General at 9:55 am by Madarco

Grant Skinner has just released RegExr: a wonderful tool for writing and sharing regular expressions. Its main features are: show results as you type, contextual help, save and share your regexps. It also runs as an Air application or directly from the website.

Read the rest of this entry »

Using Zend_Tool in Eclipse

Posted in General at 9:29 pm by Madarco

Zend_Tool is a command line tool released with the latest version of Zend Framework. It will jump-start the development automating some tasks like the creation of an empty project or of a controller class. Other than from the command line, its possible to use Zend_Tool directly from Eclipse, lets see how. First, download the framework [...]

Read the rest of this entry »

Haxe on the iPhone

Posted in Flash at 11:15 am by Madarco

Great news for all the Haxe enthusiasts! Haxe is powerful language similar to ActionScript 2, that can compile itself to Flash6/7/8/9/10 and translated to other languages like JavaScript, Php, NekoVM, C++. This allows it to run virtually in every environment and client. And now the good news: from today its possible to run Haxe programs [...]

Read the rest of this entry »

Build a Facebook application with Zend Framework

Posted in PHP at 4:56 pm by Madarco

I've just finished a Facebook game, so here a quick tutorial on how to use Zend Framework to build a Facebook Application. Facebook basics You can integrate your application with facebook in two way: with an IFRAME (using XFBML) or with FBML. (If you are already familiar with how a Facebook application work you can [...]

Read the rest of this entry »