What a great week! So many things have been going on. If you live in Nashville especially, you have a lot to be excited about. The official releases of symfony 1.3 and 1.4 provide a lot of exciting new functionality in the framework, which you can read about here. But even more exciting is this year’s advent calendar, a large part of with being contributed by Nashville’s own Ryan Weaver! Be sure to check it out, and consider purchasing the book from amazon to support the community.
Also, my personal project Symplist is now launched, and in Alpha. Please check it out and provide feedback. Symplist is a plugin site that exists for the community. Its greatest asset will come with individuals like you rating and commenting on plugins. Another section of the site, which I’ve dubbed “Community Lists”, is something I hope will be a great help to the community. This section will function as a repository for dense information. An example of this is a list I’m putting together of Symfony Best Practices. The highest-rated items in each list sort to the top, as do the lists themselves. Check them out, rate and add items, and leave some feedback!
On a separate note, Jon Wage (Nashville native) has recently been pushing PHP Interoperability Standards with PHP 5.3’s namespacing support. I would recommend checking it out! If you personally have any PHP projects, or are currently developing one, consider incorporating these standards.
If you want to get involved, consider joining the Nashville Symfony User’s Group, which meets at Centre{source} the first Tuesday of every month! Symfony is taking off, and Nashville is right on board!
After skimming through Fabien’s very interesting slideshare presentation on PHP 5.3 (no, I can’t read French), and playing with Jon Wage’s PHP Interactive Terminal, I whipped up a fun little object-oriented array-wrapper class to do some neat ruby-esque things. It should be noted this code is for fun, and probably not sufficient for production use.
Using my array class, the following functions are now possible:
// Instantiate the object
$test = new A(1, 2, 3, 4, 5, 6, 8, 10, 20);
// return an array containing the multiples of 4
$test->reduce(function($i) { return $i%4==0; });
// Sum up all even values
$x = 0;
$test->each(function($i) use (&$x) {
if($i % 2 != 0)
continue;
$x+=$i;
});
echo $i; // outputs "42";
// return the index of the first item evaluated true
$isGreaterThan = function($x, $y) { return $x > $y; };
$test->match(function($i) use ($isGreaterThan) { return $isGreaterThan($i, 15); });
// returns an array of all values multiplied by two
$test->map(function($i) { return $i*2; });
// until the function evaluates true, execute the block on all variables
$test->until(function($i) { return $i > 15; })->do(function($i) {
echo "This number ($i) is less than or equal to 15";
});
Although we really gain nothing here we don’t already have with functions such as array_walk, array_map, array_filter, and so on, I personally get slightly aroused at this ruby-esque PHP implementation. While not quite as pretty as ruby blocks, anonymous functions (aka “closures”) offer similar functionality. To make it more rubyesque, I’ve overloaded my class’s __call, and __invoke methods:
// Instantiate an existing array
$test = new A($fortunes);
// return an array with "in bed" appended to all fortunes
$test->map(function($i, $key) { return $i." in bed."; });
// mutate the array object in place (similar to ruby's exclamation mark convention)
$test->_map(function($i, $key) { return $i." in bed."; });
// the underscore convention works for all functions that return an array
$test->_reduce(function($i, $key) { return strpos($i, 'happiness') !== false; });
// Ruby-like array access
$test = new A(10, 900, 5, 30);
echo $test(1, 2) // returns array [900, 5] (starts at index 1, length is 2)
// maybe supported someday, if I have time:
echo $test['0..2'] // returns array [10, 900, 5] (starts at index 0, up to index 2)
echo $test['1..,-1'] // returns array [10, 900, 5] (starts at index 0, up to last index, excludes ending index)
$test['2...3'] = new A(2, 2); //inserts array as the given indexes, to produce array [10, 900, 2, 2, 2, 20]
You can check out my half-baked class here. Any other fun ideas??
*** Update ***
Jwage did something similar by wrapping primitive types in php classes. Check out his code here!
Over the last week, I have developed several plugins for CentreSource and the symfony community. The plugins have been used in several of our internal projects and client web applications, and are finally deemed worthy for public use. These plugins can be found here.
- csDoctrineActAsAttachablePlugin – associates various uploads with multiple models, and includes an AJAX uploading client interface.
- csDoctrineActAsCategorizablePlugin – associates models into nestable categories and category groups.
- csDoctrineActAsGeolocatablePlugin – integrate your model with the Google Maps API to pull in geocodes based on record fields. Supports radius and proximity searches.
- csDoctrineSlideshowPlugin – add and configure slideshows in your project.
- csFormTransformPlugin – give your forms a web 2.0 look within a few easy steps.
- csGlossaryPlugin – group your models alphabetically in glossary/directory format
- csSEOToolkitPlugin – A toolkit to improve your website’s search engine optimization.
- sfSympalSlideshowPlugin – An advanced slideshow used for the Sympal Content Management Framework. (Ported by Jonathan Wage)
You can check out my plugin list here. If you are interested in using these plugins, or have any suggestions for addition useful symfony plugins, please contact me or any of the developers at CentreSource.


RSS Feed