Tag Archives: PHP

Belated Zendcon 2011 Recap

Image representing Zend Technologies as depict...

Image via CrunchBase

I started writing a Zendcon recap post as soon as I got back. And then mis-timed a couple projects. Note to freelancers, make sure your new gig starts AFTER your old gig is over. Or you’ll be working an insane schedule. Hence the lateness….

First the good part. What made Zendcon special.

I listen to many podcasts while on the LA freeways (aka parking lots), read a lot of blog posts by the pros, and connect with the #ZF community on twitter. It was great to finally meet so many “online friends” in person.

Even if you’re not a Zend Framework or PHP Developer, I recommend following these folks, as you will gain something from each of them.

First of all, many thanks to Kevin Schroeder (joind.in) for inviting me to be on

The PHP logo displaying the Handel Gothic font.

Image via Wikipedia

the advisory board for Zendcon 2011. It was a wonderful experience.

Juozas Kaziukėnas proves that even if you’re circa ~7’9″ tall, you can be a better programmer than basketball player. Back when he was still trying to get accepted to speak at conferences, I could tell that this fellow had chops. Glad the last couple of years he’s been getting the recognition he deserves. His talks included sessions on Doctrine and Azure.

I wish I’d have managed to catch some sessions by Daniel Cousineau. Besides having a really neat beard, this is one smart feller.

Wayne's World

Wayne's World (Image via RottenTomatoes.com)

If there’s one event I will remember about Zendcon2011, other than Kevin wearing a cape for two days, it will be 4 of us, David Zulke, Juozas, Paul Jones and yours truly in David’s car, singing Bohemian Rhapsody like in Wayne’s World. Anyone (ie David) who gets REST right and yells at those getting it wrong in conference talks has my props.

Paul Jones is one cool Marine. He’ll kick your ass physically and in code. I think anyone coming from OmniTI must be really smart, because between him and Elizabeth Marie Smith, you can spend a day chatting about hardcore programming and not get bored.

Image representing OmniTI as depicted in Crunc...

Image via CrunchBase

I missed Paul’s talks unfortunately and only caught one of Elizabeth’s, but it was great. If you don’t know SPL, you should try to catch her SPL talk. Actually, I want to hear all of them when they’re released.

Hanging out with Dr. Keith Casey is always a blast. One of the most unique individuals you’ll come across. He has so many great stories. And we’re very much of the same mind about connecting people who would mesh well together.

I hung out a lot with @jsundquist and @jcarouth. Promising young talent. When you meet good kids like them, you have hope for the future.

English: Zend Framework logo. Português: Logot...

Image via Wikipedia

I really enjoyed meeting one of our #LAMySQL speakers in person. @billkarwin. He’s so humble for someone who’s done so much. This guy headed up Zend Framework V1.0, wrote the groundbreaking SQL Antipatterns book and has had quite a career so far. Now at Percona. We chatted quite a bit and I’m honored to call him a friend.

Bill and I also hung out with another gentleman and scholar, Bradley Holt. These two guys forgot more about Databases than most of us have ever learned.

English: Zeev Suraski, significant contributor...

Image via Wikipedia

I’m kind of losing steam in telling these stories, because there’s one name I want to cover at the end, and life kind of sucks, it’s hard to focus on the good when I’ve got his story in the back of my mind…so if I miss anyone please accept my apologies.

Shout outs to @DragonBe & DASPRiD. Enjoyed IHOP with you guys!

Also nice to meet fellow Canuck @afilina who manages to get the PHP community out to the Frozen Tundras of Canada with her mega conference organizing skills.

Andi Gutmans

Image via Wikipedia

Too bad @skoop wasn’t there the whole conference as I was hoping to chat with him more. However I was very pleased to chat with the names behind Zend, Zeev Suraski and Andi Gutmans.

One of my favorite talks, which was in the uncon came from @iliaa. He always has so much to say about performance. If you’ve never had to worry about performance, it might be hard to tell who’s good. But trust me, he is.

And I’m going to wrap up with the dynamic duo behind Zend Framework. Ralph Schindler and MWOP. Ralph is hilarious! And I learned some interesting things chatting about the history of PHP with Matthew.

Running a project like Zend Framework has its positive sides to be sure, but also its thankless side. The public out there can be pretty mean and demanding at times. Especially with stuff they get for free. These guys really handle the community with class.

Sorry if this post is too positive, but it’s one of the few things I love. Meeting wicked smart people, often they are nice too, and just learning. If you focus on the good people, you can gain so much from conferences…

Now last, but not least I will mention Jeroen Keppens. We sat together during the opening Keynote, live tweeted the conference, and every time the live demo showed top tweets, one of us was on the screen. It was real fun. And I really enjoyed hangin’ with him and chatting. Having lived in Belgium for awhile, it’s easy to connect with people on that side of the world.

And this brings me to something that bothers me a lot about twitter. The world gets smaller. Because I run meetups, I follow a lot of people on Twitter and many are not just strangers. A good chunk are community members.

And almost every day something really sad happens to someone. I’m still kind of shocked from when Jeroen tweeted that his wife passed away from an accident. The original version of this post had more details, but now I see that his tweets are protected, so I will respect his privacy. I wish there was something we could do, but what can you do?

Jeroen is such a good guy. Why does he have to go through this? I don’t know. A week earlier, someone from the cloud community announced that his 2 year old daughter pulled a pot of boiling water onto herself and went to the hospital. Thank God she seems OK.

A couple of people have gotten cancer. Another Twitter friend had a relative commit suicide.

It’s hard to tweet as though it’s a normal day when someone you are fond of one way or another are going through such a hard time. Like a Doctor you have to get “used” to this because of the frequency. But it is hard and the downside of these tools that bring the world closer.

Enhanced by Zemanta

I wrote a new ACL module for Lithium: li3_simple_acl

Lithium hydride

This Image via Wikipedia, is a test of focus. Is it related? Perhaps not, but it looks better than a naked post.

I tried to work with the existing Lithium ACL module called li3_access, as several folks have done some really good work there. It has a lot of flexibility, including the ability to let you create your own Adapters. Which I tried at first.

The reason I chose to roll my own, at 4am no less, was that I was looking for something simple, that still lets you protect the resource.

A principle in making a good ACL layer is that you don’t want a bunch of if statements in your code. If($user == ‘admin’){ //do ‘A’ }. Because if you change your ACL rules, you have to find every instance of that and change it. Breaking your code.

If you thought you improved that situation by moving to an ACL but find yourself writing code like: if($acl->isAdmin($user, $request, $resource)){ // do something }, you’ll realize that you just abstracted away the same exact code, and did not solve your problem.

In my opinion, you should be calling your ACL with code that looks something like this: if($acl->isAllowed($user, $resource) { // do something }.

The $user array/object should contain the info needed to validate the $resource/$perms array. Then all you have to think about is how to make sure you can pass the needed info from your resource.

Image representing GitHub as depicted in Crunc...

Image via CrunchBase. Did you know that research scientists in Freedonia have proven that programmers improve their standard of living by opening up a github account?

For example, if you have a database row with a forum post and want to provide the author of that post permission, the user array has the userid and the row has the author’s userid. Simple to match.

Naturally, it still needs a bit more work. Like the ability to Deny users in the event that certain conditions match. Or allow some IP ADDRESSES access. Basically, it needs a little more flexibility. So please take a look at li3_simple_acl on my github account and give me feedback. Thanks.

Enhanced by Zemanta

Using ‘VC’ portion of ‘MVC’ in Zend Framework vs Lithium

Although I’ve been playing with Lithium for a few weeks, I haven’t needed to touch the view at all and barely looked at the Controller, so I didn’t really pay attention to this difference until just now…

In Zend, you set the vars in the controller for the view thusly.

Whereas in Lithium, you do it thusly.

Then in the view, to access those vars, here’s how Zend Framework does it.

With Lithium, if you use the same notation as the PHP short open tag, it will automatically escape the output. Which is great, although keep in mind that when you don’t want an htmlspecialchars escape, be sure to escape the var yourself as appropriate. Here’s the Lithium example.

I’m not sure how Zend Framework 2.0 will work yet. Been too busy to keep up to date.

I think the Lithium way is quite elegant. It’s a lot easier to explain to front end people who are mostly but not 100% in the view. There’s a variable, it’s the same in the controller and the view and you just access it.

It’s always good to check out different frameworks and learn what you can from each of them.

Aside: I love how people in the PHP community are for the most part really good about listening to the good and less good with an open mind and not making it personal. Matthew Weierophinney’s recent article about Filters and Nate Abele’s response is a classic example of the class acts in our community. I’ve learned much from all of you.

Setting up first Lithium project

I’m now starting my first Lithium project. So I thought I’d jot down notes while playing with it. Just random stuff. I’m not trying to accomplish anything in particular with this post. It might be interesting to you if you’re planning to try it out. Especially, if like me, you’re used to Zend Framework.

So far the docs are a little better than I expected, as we aren’t yet at release 1.0. But we should expect some speed bumps.

The first thing I noticed is the suggestion to install the whole framework under the docroot. To see the homepage you go to http://localhost/lithium . I’m sure that will change though so that your application code doesn’t live under your docroot. If you’re doing anything other than development, obviously you can and should fix this in production.

Something I like about the Zend Framework coding standards is the lack of an end php tag ?>. Having been bitten by that spacing after the endtag “bug” before, it now looks weird to me to see the end tag closing up a file. Hopefully #LI3 will follow Zend’s lead on that.

If you’d like to peruse the #LI3 coding standards, they are here. Overall I really like them.

Not sure what’s wrong with casting using shortcuts. Is it really ambiguous to say (int) $var rather than (integer) $var? (not a big deal in the scheme of things though)

Side note, I wish the PHP community would come to a consensus with the underscore thing before _protected methods.

I got used to it with Zend Framework. Now there’s a poll about removing it or not and last I looked it seemed that it was going away.

I just hope everyone keeps it…or removes it…but we make a community decision so that we don’t have another of these tabs vs spaces debates for the next 10 years. Which leads me to my next point. Kudos to #LI3 for choosing correctly with tabs ;) I thought I was in the minority about that. Certainly seems that way in the Open Source community.

One more thing. Just installed the Lithium Documentation Tool. This is so cool. Really excited to learn more.

I’m going to end this post with a little list of #LI3 RSS feeds that I started to follow. It may be updated periodically and do let me know if you know of any others:



How to integrate HtmlPurifier with Zend Framework

It looks like I’m inadvertently starting a series on how to integrate some external libraries with Zend Framework. So be it. Next on the list is HTMLPurifier.

Like with the Amazon AWS SDK, I’m just starting the process as I write this. I have no idea how hard it will be. So let’s start with a Unit Test again and try to make it pass.

The Unit test is located at /project/tests/application/models/PurifyTest.php and contains this.

Obviously, the test will fail at this point

phpunit –configuration phpunit_local.xml –group purify

So let’s do a couple things. First, download the latest version (my link might be stale by the time you read this. So just find the latest release).

Next, if you set it up the same way I do, you’ll have a share folder in your filesystem, where you’ll put the htmlpurifier-4.2.0 folder. Then in your project/library/ folder, you’ll symlink this folder: Htmlpurifier to the location of that directory. Now if you upgrade to a later version of the purifier, you just change the symlink. Then if there’s a problem, you downgrade in two seconds…

Now open the INSTALL file in purifier. What’s this?

These optional extensions can enhance the capabilities of HTML Purifier:

* iconv : Converts text to and from non-UTF-8 encodings
* bcmath : Used for unit conversion and imagecrash protection
* tidy : Used for pretty-printing HTML

OK, well that would be nice. As I recall, tidy these days comes with PHP so if you have a recent version, you should be OK. But just in case, I’m going to fire up phpinfo.

Whew. I’ve got all three, so I’m good to go. If you don’t, then I’d suggest you install it. If you don’t know how, no better time to learn than now. Don’t be scared. It’s a breeze after the first time and you will have learned a very valuable skill that you can use in project after project.

OK let’s continue.

Having read an article or two from Juozas and Paddy, I suspect we won’t need a model or anything, but let’s not get bogged down in details. We just want to see if we can talk to HTMLPurifier, not architect an application.

So without further ado, let’s create a model called Purify.php (in the /project/applications/models/Purify.php file). Here are the contents.

Running the Unit test shows an error…ah I pointed to the wrong location. This is the correct include file:

require_once APPLICATION_PATH . ‘/../library/Htmlpurifier/library/HTMLPurifier.auto.php’;

OK, now there’s no error on the Unit Test, but we still need to make sure we can purify something.

In my case I’ve got APC opcode cache installed, so I’m going to add this include as well:

require_once APPLICATION_PATH . ‘/../library/Htmlpurifier/library/HTMLPurifier.includes.php’;

Then I’m going to create some evil html, and try to purify it. Here’s the new code:

Now let’s run the unit test:

phpunit –configuration phpunit_local.xml –group purify
OK (1 test, 1 assertion)

So it looks like we’re good. However, I’m still not satisfied. There are small differences between running PHPUnit and running code on the webserver. What concerns me is that HTMLPurifier has an autoloader and I want to be sure it won’t clash with Zend Framework’s autoloader.

So this will be easy to test. It’s very similar to the PHP Unit test. We’ll just create a test controller…skip the view and just see if it errors out or not. Here’s the code.

And Bingo! Job done. Easier than I expected it. But I still hope someone finds it helpful.

P.S. From past experience, I want to add a comment. Before you nitpick about details like requiring a file in a constructor or other practices, don’t forget it’s just an attempt to prove we have no errors. I’m not trying to paint the Mona Lisa here.