Sunday, February 19, 2012

if-ify, for-ify, foreach-ify and func-ify

A common question among developers is how to surround the current selection in the editor with a parent statement. For example if you start coding a statement that validates an expression and then want to iterate over an array of expressions and do the same to all its elements.

For this end Eclipse templates provide two variables "line_selection" and "word_selection" that help you build custom selection-based wrappers.

In this example three new templates were added to simplify this scenario:



You can import these templates (xml below) to your IDE via Preferences > PHP > Editor > Templates > Import...

Wednesday, February 01, 2012

How My Wife Drives the Technology World

ok, maybe a better name would be "My Cloud-based-Social-enabled-Service-oriented Mobile Apps Experience", but that's a long name for a post :)

It started last week as a small-talk between my wife and me about she attending so many shifts and medical sessions. According to my wife, she usually takes 4-5 shifts a month where the actual number is doubled (!). At that moment I had no tools to prove my point and here comes the requirements to build a small mobile app for her to report shifts and sessions while being able to write short notes about it (ok, she was asking this a long time ago). In addition she usually posts some info on Facebook during her shifts so I had to connect these reports somehow to her Facebook account. By the end of the month she hand a report about her shifts to the managers so this if the app could also print a summary it will be a big value for her.

Before sharing thoughts about my experience with this app development, here is how this app looks like on Android and iOS:


Mobile App
jQueryMobile (version 1.0) is really handy for creating cross-platform mobile interface, it provides easy to use APIs and is really covered well with lots of great examples. I had to use several other libraries like jQueryUrl, Moment.jsMustache, requireJS and jsPDF. With so many "out-of-the-box" libraries it is super easy to build robust solution for client side in minutes(!!!)

Social-enabled:
Facebook JavaScript SDK helped me with giving a more "social look and feel" after creating  a  Facebook application. I also used  Facebook's OAth service authentication and Open Graph integration so users notify their friends about their activities with the "My Doctor Shifts" application. That's super important to engage the application users to your application!

Service-oriented (and Data-centric)
Zend Framework provides nice (lightweight) models representation and the MVC was useful to create the HTML view and services.

Cloud-based
Using  phpCloud was easy as always with plenty of slick workflows helping me to easily deploy my application and push updates to staging and testing targets. This way I always kept two versions that represent my Work in Progress and Done apps. I also got packages ready for deployed in case I want to deploy it to another Zend Application Fabric instance.

The application is available on github.

Thursday, January 19, 2012

Getting Started with Facebook App Development

Last week I was playing with Facebook App development, getting ready to the Facebook announcement. It was quite pleasant experience, although things could be simpler. The Facebook Open Graph concept gives a nice overview on what and why this all about, so that part went very smooth. When things get technical, the Facebook Developers site turns messy. That is, all topics are covered in a 'tutorial' approach rather than an API approach like most developers are used to. Moreover, the layout of this page is definitely not intuitive as it mixes between reference and tutorial docs. That's said, the general experience was good.

To help other developers get started with Facebook app development I created a nice application which take the reader through the steps to develop applications with phpcloud.com. It was a nice exercise and it can really help with the development workflow.

The topic "Getting Started with Your Facebook App on phpcloud.com" covers :
  1. Create an account on phpcloud.com
  2. Create an app on Facebook
  3. Setting up development environment
  4. Deploy a sample Facebook app to phpcloud.com
  5. Push updates to your Facebook app


Wednesday, December 14, 2011

A (Big) Dot Release

Although dot releases don't get as much attention as major releases , this one should definitely get highlighted:

      "Zend is pleased to announce the release of Zend Studio 9.0.1!"

This new release focuses on improving source code editing experience, improving editor performance, smart indentation when pasting code. It also extends the code formatter so PHP comments are well structured. Working with PHPUnit made easier with the addition of smart configuration (and bootstrap)  detection. Community plugins updates provide advanced features with Git, ZenCoding and Symfony2.

The changes include:
  • Improved editor performance for multi-line statements and auto indentation scenarios
  • Adjust indentation when pasting code
  • New code formatter rules for PHP Comments
  • Disable/Enable Code formatter with special @formatter:off/on tags
  • Git history graph
  • PHPUnit auto-detection of configuration (and bootstrap) file
  • Improved PHP Class creation for namespace code generation
  • Easy installation of community plugins ZenCoding and Symfony2 and Twig 
  • Various bug fixes

Monday, December 05, 2011

Rewrite Rulez!!!

While common Web frameworks provide a set of mod_rewrite rules in their default application, it is left to the developer to align these rules according to the Apache host configuration. For example if you use an alias when setting up a Symfony application then a RewriteBase directive must be added to the application rules. This is a common change that is required to keep the original list (provided by the framework) as is.

To this end a post-deployment action can be added to fix the RewriteBase directive in the '.htaccess' file. In a previous post, application deployment scripts were used to help chmod application's resources. This time I am going to use deployment hooks to modify the RewriteBase directive automatically after deploying the Symfony2Cloud application.

In the deployment script you can find this code:

<?
// get application location
$appLocation = getenv('ZS_APPLICATION_BASE_DIR');
// modify htaccess
$htaccess_file = $appLocation . '/web/.htaccess';
$explode = explode ( '/', $appLocation );
$appname = $explode [sizeof ( $explode ) - 2];
$content = file_get_contents ( $htaccess_file );
$content = str_replace ( '<application-name>', $appname, $content );
file_put_contents ( $htaccess_file, $content );

In details: The application location is used to resolve its alias. Then the alias name is used to replace the .htaccess file content so instead of "RewriteBase /<application-name>" it will show up as "RewriteBase /Symfony2Cloud".

Assuming that you use Zend SDK and the following deploy command:

zend deploy application -r git://github.com/ganoro/Symfony2Cloud.git

Symfony2Cloud is now deployed and ready to use with this .htaccess:

<IfModule mod_rewrite.c>
 RewriteBase /Symfony2Cloud

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>

Wednesday, November 30, 2011

Github to Zend Developer Cloud - the fast way!

In previous posts I discussed several methods of building Web applications using Zend Developer Cloud and github, mainly with tools like Eclipse and Zend Studio. This time, I will show off with a new feature in Zend SDK v0.0.22 (and up) presented by Wojtek Galanciak.

With this feature only one command line is required to deploy applications from github to Zend Developer Cloud. Here is a simple example:

zend deploy application -r git://github.com/ganoro/Symfony2Cloud.git -t 0

"Symfony2Cloud" repository is hosted in my github account. Target id 0 is my Zend Developer Cloud container. This command makes sure that the applications is deployed into my Zend Developer Cloud container. As simple as that...


Read more about this command and similar use cases with the new Zend SDK. Release notes are available here.

In my next posts I am going to explain about the new repository management tools, so stay tuned.

Sunday, November 27, 2011

chmod() your phpCloud Web Apps

A common feedback from developers using Web Apps on Zend Developer Cloud is the ability to chmod() directories for deployed applications. For example in Joan Ging's post you can notice that one needs to use external tools (like WinSCP or Zend Studio) to chmod the logs and cache directories that are used by Symfony2, otherwise these directories are write-protected and the application fails to launch.

There are two methods to chmod application directories after the deployment stage and before launching.
So let's review the two alternatives, both of them result in the same state:
  1. Using Deployment Scripts (during deployment phases).
  2. Using Zend Studio (after the application is deployed)

Using Deployment Scripts

One of the new features in phpCloud is the ability to deliver hook scripts alongside the application. There are several types of scripts for each phase in the deployment process (i.e, Staging, Activation).
In the following example, chmod is executed on both logs and cache directories immediately after being executed on their parents.
First we define the "scripts" directory to contain all deployment triggers. This is done as part of the deployment descriptor file (named deployment.xml):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<package xmlns="http://www.zend.com/server/deployment-descriptor/1.0" version="1.0">
    <name>Symfony2Cloud</name>
    <version>
        <release>1.0.0</release>
    </version>
    <appdir>data</appdir>
    <docroot>data/web</docroot>
    <scriptsdir>scripts</scriptsdir>
</package>

Then we create a post_stage.php file under this directory with this content:
<?php
/* @var string holds the application (absolute) path */
$appLocation = getenv('ZS_APPLICATION_BASE_DIR');
/* chmod cache and logs */
chmod ( $appLocation, 0775 );
chmod ( $appLocation . '/app/',0775 );
chmod $appLocation . '/app/cache/', 0775 );
chmod ( $appLocation . '/app/logs/', 0775 );

The complete source code for this application is available in the Synfony2Cloud project on Github.

Using Zend Studio 9.0

Once you deploy your application in Zend Studio, a connection to your container is created under the hood. You can view this connection and modify the directories permissions in the Remote System view.

1. Start by showing (or "unhiding") hidden files. This allows you to browse the ".app" directory which holds all deployed applications.
Go to Preferences > Remote Systems > Files and make sure "Show hidden files" is marked.


2. Browse to the application you want to chmod() by expanding the file tree in the Remote Systems view



3. Right click on the directory and select Properties. 
4. Select the Permissions node, alter the permissions you want to allow and click Apply.



Although Alternative #2 is more flexible, I highly recommend Alternative #1 which streamlines the deployment phase and lets you adjust the code and create an automate deployment process.