Archive for the ‘php’ Category

taskman: yet another Ant alternative

Wednesday, October 13th, 2010

I created a small PHP library taskman for writing project related tasks in a similar with Ant and rake fashion.

There is a lib-taskman project on the google code hosting where you can find the full documentation, sources and latest releases.

It’s probably not that elegant as rake but if you want to stick to PHP and have Ant-alike functionality without any XML programming then taskman may turn out to be handy. taskman is very simple to use, it requires only one include, all its code resides in one PHP file, and it has no external dependencies.

Here is the simplest usage example. Download and unpack the archive. Put taskman.inc.php to some place where you can include it from(I personally tend to bundle this script with every project). Create a task.php script with the following contents:

<?php
require('taskman.inc.php');
 
taskman_run($argv);
 
function task_hello()
{
  echo "Hello\n";
}
 
function task_comma()
{
  echo ",\n";
}
 
/**
 * @deps comma
 */
function task_world()
{
  echo "World\n";
}
 
/**
 * @deps hello,world
 */
function task_say($args = array())
{
  if(isset($args[0]))
    echo $args[0] . "\n";
}

You can run this script now in the command line as follows:

>php task.php say Whatever
************************ Running task 'hello' ************************
Hello
************************* 'hello' done (0 sec.)*************************
************************ Running task 'comma' ************************
,
************************* 'comma' done (0 sec.)*************************
************************ Running task 'world' ************************
World
************************* 'world' done (0 sec.)*************************
************************ Running task 'say' ************************
Whatever
************************* 'say' done (0 sec.)*************************
************************ All done (0 sec.)************************

You might be wondering what these “project related tasks” are. There can be lot of them: build the sources, bootstrap database, auto-generate code, migrate database schema, deploy project onto remote servers, etc. Maintenance of such tasks can become pretty tedious at some moment. Furthermore, some tasks may depend on other task, e.g. you can not build the sources without running code auto-generation task first.

P.S. Looks like there is a similar PHP solution called pake. The biggest difference between taskman and pake is the way tasks are specified. In case of taskman one has to prefix task functions with task_ keyword while in pake one has to register tasks explicitly using pake_task(..) function. Furthermore, in taskman one attaches task meta information using a PHPDoc block while in pake one should use separate functions, e.g. pake_desc(..).

P.P.S As David noted in comments there is also a Phake project which has, I believe, the strongest resemblance with rake thanks to new PHP-5.3 only features(e.g closures). Some of its ideas I’m going to borrow for taskman2 which will be PHP-5.3 only as well.

fla2swf - command line utility for publishing .fla files to .swf

Monday, October 4th, 2010

Continuing my flash automation saga this time I’m going to blog about a fla2swf utility, as I promised in the previous post about fcshd. You can grab it in the downloads section of the flash-automation project.

fla2swf is a command line utility written in PHP which can be used in a batch mode for publishing .fla files to .swf. It consists of the client and server parts. The cool thing behind this utility is the fact the client can be run on the box without Flash IDE installed(even on the *nix box). Of course, you will need the server to be run on the workstation with the Flash authoring environment installed.
(more…)

Cross-platform convenience wrapper around fcsh (for fast incremental Flex builds)

Tuesday, September 28th, 2010

For the impatient

fcshd is a convenient command line PHP based wrapper around fcsh shell. It works both in *nix and Windows. You can grab it from the downloads section of the flash-automation project. Just unzip it, enter the directory and run “php fcshc.php” in the shell to get the basic usage help.
(more…)

{{macro}} online usage examples

Monday, March 3rd, 2008

Sergey Yudin(syfisher) did really great job by making {{macro}} template engine examples available on-line.

If you are wondering who in the world in his sane mind might need yet another PHP templating engine, well…I blogged about {{macro}} some time ago where, I hope, I presented some unique arguments in its favour. Here’s the quote from that post which, probably, most nicely and concisely describes the main idea behind {{macro}}:

To be short, the main idea behind {{macro}} is to use C/C++ alike(but way more sophisticated) macro tags to simplify usage of raw PHP in templates.

Ok, going back to the subject of this post, the mentioned page has runnable examples for mostly all core {{macro}} tags. You can browse the template rendering result page, template sources and PHP code which actually works behind the scene.

You can also download the source code of these examples from projects page(where, by the way, you can find some other real life Limb3 usage samples).

We are going to update examples on the regular basis presenting other interesting {{macro}} usage patterns in the future, so, if you are interested, stay tuned.

Update: Sergey also made a “Generated PHP code” link for each example, so it’s possible to view what PHP code is generated for each case. Cool stuff ;)

Limb3 2007.4(Frozzy) Released!

Monday, January 14th, 2008

Actually Limb3 2007.4 was released on the 31st of the December 2007 but we(here in Russia) have 10 days of official holidays and I simply was too lazy to blog anything during those crazy days of champagne-with-vodka-fest-and-early-morning-hangovers ;)

If you are wondering what Limb3 actually is and why world needs another PHP…er…framework(btw I hate this word too!), here’s a brief introduction. Limb3 is just a bunch of relatively independent packages, it is not a monolithic framework. Some packages are pretty unique(e.g {{macro}}) while others were inspired by cool stuff available for other than PHP platforms(e.g. active_record inspired by Rails’ ActiveRecord). And no, Limb3 was never intended to be “the one and the only one true PHP framework”. I personally believe in well thought code re-usability, thus the end application may contain bits of ezComponents, ZendFramework, PEAR, Limb3 and name-your-favorite-PHP-libraries-here.

Anyway, it’s better late than never, so here’s the list of the most notable changes made during past 6 months:

* ACTIVE_RECORD package: better invalid fields handling using
exceptions, support for different names of the primary key added
* CORE package: cruft cleanup, refactoring and misc. code
optimizations
* CACHE package: cleanup and better implementation, added
initial APC and Memcached support
* DATETIME package: major refactoring, renaming lmbDate into
lmbDateTime, etc
* {{macro}} alternative to WACT templating engine added with almost
all WACT alike functionality(and even more!)
* IMAGEKIT package: complete redesign using filters and fluent interfaces
* TESTS_RUNNER package: test groups and methods filters, better
coverage support
* JS package: upgraded jQuery to 1.2.1
* MAIL package: upgraded phpmailer to 1.73
* WEB_APP package: major cleanup, removed all commands and obsolete
controllers
* VIEW package: support for view selection based on template extension
added(currently MACRO and WACT)
* TREE package: ArrayAccess and ArrayIterator interfaces compatibility fixes
* FS package: more generic file system iterators added

Please note, this is rather a general changelog above, see the specific package changelog for more details.

The bundled release of all packages is available in the SourceForge downloads section of Limb3-2007.4

(more…)

A reliable way to serialize/unserialize objects in PHP

Monday, December 10th, 2007

An experienced PHP developer might be wondering why posting this topic in a blog if PHP already has universal and almost transparent tools for this job, specifically serialize and unserialize built-in functions.

The key statement here is “almost transparent” which means you have to include all class definitions before invoking unserialize or use some __autoload schema. Otherwise you are going to face the dreaded “The script tried to execute a method or access a property of an incomplete object” fatal error.

The whole problem is due to the fact a serialized object has no idea about its class definition except the class name(the reason behind that is absolutely valid).

(more…)

My “AOP in PHP” slides from secon-2007.11 conference

Monday, November 19th, 2007

AOPman Here are my Russian “AOP in PHP” slides from secon conference which took place on the 13th of the November 2007 in Penza, Russia.

Go grab it if you are interested in Aspect Oriented Programming in PHP or simply want to practice your Russian ;)

Automating packages upload for PEAR channels running Chiara_PEAR_Server

Monday, November 19th, 2007

Setting up Chiara_PEAR_Server with Crtx front end is a little bit confusing(even if you follow the official guide) but at least it happens just once ;)

Another important matter is maintaining your lovely PEAR channel up-to-date which, of course, assumes nice and easy way of uploading new packages. Actually Crtx’s web interface provides such a way and it works just fine for a couple of packages but if you have more than a dozen of them uploading new packages quickly becomes a boring process(e.g. we have 20+ packages at Limb3 PEAR channel)

That’s why I hacked up a script which automates this process quite a bit ;)

(more…)

Bug in Crtx_PEAR_Channel_Frontend?

Saturday, November 17th, 2007

I’m using Crtx_PEAR_Channel_Frontend-0.3.1-alpha as a PEAR channel front end and I’m pretty happy about it. However there seems to be a bug in the Crtx_PEAR_Channel_Frontend :: getPackageLatestReleases() method at line 500.

It reads:

unset($release[$states[$i+1]]);

While it should read:

unset($release[$states[$i]]);

I tried to email the original author Davey Shafik some time ago to no avail but at least now you are warned ;)

limb/tests_runner-0.8.7 released!

Saturday, November 10th, 2007

I’m glad to announce the new release of the limb/tests_runner package which reached 0.8.7-beta version! This package ships with limb_unit - a SimpleTest tests “swiss army knife” console based runner. If you’d like to know more about limb_unit utility I would highly recommend reading its documentation since it provides quite unique features like nested fixtures, code coverage and so on(documentation it’s actual for 0.8.5-beta as of this writing, but that’s ok).

This release introduces some unique filtering features which can be quite useful for large sets of tests. Now it’s possible to use filters for the following entities:

  • test classes
  • test classes’ methods
  • test classes’ PHPDoc @group annotation tags

In the rest of this post I’ll describe these new features in detail.
(more…)