Chris Tankersley

  • Home
  • About
  • Portfolio
  • Projects
Twitter RSS
Monthly Archives: November 2010

Playing with Lithium

Posted on November 25, 2010 by Chris
4 Comments

Since my day job was generous enough to give me the entire week off (as a reward, thankfully not a “Don’t bother coming into work next week, or ever” kind of thing), I decided that I would spend some time looking at a new framework. I haven’t looked hard a new framework since I really started working with Zend Framework a few years ago. I decided to take a look at Lithium, an up-and-coming 5.3 only PHP framework.

Why Lithium (li3)?

li3 was designed from the ground up to take advantage of PHP 5.3′s new features and, at least coming from Zend Framework, has a much different workflow. It represented the biggest change in working with code compared to what I looked at as mostly syntax changes that frameworks like Kohana or CodeIgniter presented.

Filtering System

The filtering system allows for code to be modified on the fly without having to go in and modify the base class. The example on the Filters example page illustrates this: (modified below to what I ended up using):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Dispatcher::applyFilter('run', function($self, $params, $chain) {
    // First, define our list of protected actions
    $blacklist = array(
        '/lithium/users',
        '/lithium/users/add',
        '/lithium/home',
    );
 
    // Inspect the request to get the URL for the route the request matches
    $matches = in_array(Router::match($params['request']->url, $params['request']), $blacklist);
 
    // If this is a match, check it against an Auth configuration.
    if($matches && !Auth::check('user', $params['request'])) {
        // If the Auth check can't verify the user, redirect.
        Session::write('LoginRedirect', $params['request']->url);
        return new Response(array('location' => '/lithium/auth/login'));
    }
 
    // Important: return the results of the next filter in the chain.
    return $chain->next($self, $params, $chain);
});

The idea is that you have a base class, you apply an additional function to a method, and let the system handle it from there. The above filter will run when the Dispatcher::run() function gets called. It will take the current URL, compare it to a blacklist, and either redirect to the login page or allow the user through. Most of the core code is filterable so extending it to fit a developer’s need is easy.

It Really is a rad Framework

li3 is designed as a rad (Rapid Application Development) framework that just gets out of the way. For the most part, it did. The MVC structure is easy to pick up and there is a lot of magic that happens under the covers. Initially I had more trouble getting li3 and MongoDB to talk to each other (which ended up being a problem with the pecl extension), but once I did it was pretty easy from there. It wasn’t much more complicated than Zend Framework and Zend_Application.

5.3 Makes it Nice

li3 uses many of the new 5.3 features that were introduced to PHP. Closures, lambdas, and namespaces are a bit part of li3. This will make it somewhat hard for new programmers to pick up, but li3 doesn’t look like its targeting newbie developers (that’s not a bad thing). You really have to know what you are doing and what the code is doing. That said, if a developer understands the new 5.3 features, they are all set.

MongoDB is Easy to Work With

Once I got my pecl problem worked out, interacting with MongoDB was a breeze. A quick read-up on how MongoDB works, and a download of MongoHub really helped to work with MongoDB. I had more issues understanding how MongoDB worked than how to get it to work with li3. They did an excellent job lowering the entry bar to work with non-SQL databases.

Downsides

As with everything, there are some downsides. These aren’t enough to get me to not want to use li3, but it makes it hard for me to want to use in day-in-and-day-out.

It’s Evolving Rapidly

My biggest complaint is the lack of tutorials. The Blog Tutorial is nice, but leaves out of a lot of what goes on under the hood. The overall Drafts project will attempt to cover all the aspects of li3, but I did find some of the code already out of date. A good example is the Dispatcher filter example that I highlighted above; as it turns out, the example code doesn’t even work with the last release (0.9.9). @gwoo did have a point that IRC is always up to date, but getting answers on IRC isn’t always the quickest.

Technical documentation is helpful, but tutorials really help speed up the learning process. This is a big thing that the Zend Framework guys are striving to fix with Zend Framework 2, so it’s not just li3. This leads too…

Lack of Community Documentation (Or Maybe It’s Hard To Find)

The website lacks in tutorials, so the next logical thing is to move to Google. Finding user generated tutorials or example code was very hard. Lithium is a pretty common term on the web, and searching for things like ‘Lithium authentication tutorial’ brought up things not related to li3 at all. I found some code, but there was still an overall lack of community chatter. li3 is young, but it is still discouraging.

Relational Databases are a Second Class Citizen

I got working with MongoDB very quickly, but my sample application (a basic Twitter clone) fell apart with the database structure pretty quickly. I decided to switch to MySQL. That switch was easy (changed a config file and created the database), but then found out there was no support for table joins natively in li3 (though it is coming soon).

@jperras pointed me to the li3_doctrine project. That worked pretty well… until I tried to authenticate to my test website. li3_doctrine doesn’t seem to have code that supports the built in Form authentication in li3, and the one tutorial I found for using Doctrine 2 and li3 was out of date. That was discouraging.

Conclusion – li3 Has Its Place

If you want to use a NoSQL database like MongoDB, li3 gets you up and running very quickly. The overall code structure easy to use and a breath of fresh air. The IRC channel is helpful (they got me past the pecl problem) and is easy to talk to. The technical documentation is top notch as far as I’m concerned. Its actively developed and well designed.

If the relational database support was better and there were more code examples, I’d be more apt to use it more often. I’ll probably pick it up again when the next release comes out, but for right now li3 will be regulated to just the times I need a NoSQL database.

Categories: PHP, Programming | Tags: li3, lithium, PHP

ZendCon 2010 – Day 2

Posted on November 3, 2010 by Chris
No Comments

Opening Keynote – Andi Gutmans

The keynote was, well, it was what most enterprise keynotes are – a massive sales pitch. Yeah, I get that this is ZendCon, but I don’t think any of the devs here need to be sold on PHP and scaling. Most of them have figured it out. The keynote focused mostly on Zend in the grand scheme of things, and this cloud thing that everyone keeps taking about.

Zend did announce the new management stuffs for Zend Cluster Manager. What I didn’t get was why they had to come up with their own packaging system. If you wanted to use PEAR, just use PEAR. Or use phar. There are already standards. Don’t come up with something new that doesn’t add any benefits.

Advanced Date/Time Handling with PHP – Derick Rethans

I was worried a bit after studying last night, so I decided to hit up Derick’s talk on DateTime. It really made more sense that the php.net documentation. He presented something incredibly complex in a straight-forward manner with some great examples. DateTime is way more easy than doing date manipulation the old way.

Reusable Bootstrap Resources with Zend_Application – Hector Virgen

Attending this session was a bit of a quick decision on my part. I was originally going to attend the PHP 5.3 talk, but figured I wouldn’t get much out of that. I use Zend Framework all day almost every day and have never really looked at bootstrap resources. I made them out to be much more complicated than I figured.

Hector not only showed how they work, but one of the best ways to get them set up for unit testing. I now plan on moving all my Bootstrap _init* functions to resources for maintainability.

Taking the Zend CE 5.3

One of the new things on the website is the Zend 5.3 Certified Engineer badge – I passed! I’m not sure how, but I took the test and at the end they printed a piece of paper that said ‘Passed’ and I got a ticket to a special breakfast tomorrow. Apparently I’m a better developer than I thought. I ended up leaving right after lunch started to take it, so I had celebratory wings afterwards. (On a side note, the Hyatt has excellent hot wings.)

Best Practices in Deploying PHP Applications – Shahar Evron

Yeah. It didn’t click until I went into the room that Zend had announced at the keynote a new deployment method. Once I realized Zend was giving the presentation, I basically sat through it because I felt it rude to leave once he started talking. I don’t want to be mean, but this was a worthless talk. It amounted to every deployment method has ups and downs, but Zend’s has no downs. The conference manual should have really tagged this as a vendor presentation.

And please, can someone actually prove to me that using RPM/DEB as a deployment method is actually done in the real world?

Technical Debt – Elizabeth Naramore

Best. Talk. Yet. Elizabeth described technical debt wonderfully as well as ways to help combat it. Despite there almost being a fight over whether or not ‘declaring bankruptcy’ (throwing out code and starting over) is a good or bad thing, she presented ways to recognize, evaluate, and deal with debt. Again, this, so far, has been my favorite talk (followed closely by Ed’s, but Ed didn’t curse near as much). I would have liked to talk to her more about technical debt, but didn’t have the chance.

High Performance PHP – Maurice Kherlakian

I feared that this would be a another sales pitch, but it really wasn’t. Maurice went over some viable ways to find out what is causing performance issues, and some ways to combat it. Load balancers, query profiling, system profiling, etc. It wasn’t a revolutionary talk, but at the same time it had some nice pointers.

Afterwards

Right after the last session, Adobe had a get-together in the vendor hall. I got my swag, got to talk to some great people. It was a pretty standard vendor get-together. After that I had been invited to a private IBM party since I run Zend Server on the IBM i. Again, I had a great time talking with other devs and made some good connections. Doing PHP on the IBM i sometimes seems like developing in a vacuum, but there are real people facing the same problems. We just need a better community. Hell, the PHP on Windows has a better, more vocal community than PHP on the i.

Categories: IBM i, PHP, Programming, ZendCon 2010 | Tags: PHP

ZendCon 2010 – Day 1

Posted on November 1, 2010 by Chris
No Comments

Let’s see if I’ll be able to keep my own promise to blog each day after ZendCon. *crosses fingers* I won’t guarantee that they will be filled to the brim with details, but I’ll do my best.

Javascript for PHP Developers – Ed Finkler

The first session that I attended today was Ed Finkler’s talk about Javascript from a PHP developer’s perspective. I had grabbed his slides and sample code from when he gave this talk during Tek-X earlier this year, but hearing him actually give the presentation was much nicer.

He gave a great overview of how base Javascript works and explained how it works compared to PHP. A while ago I attempted to work on an Appcelerator version of Spaz and it fell apart, partially due to my inability to grasp some of the basic functionality of Javascript. (After the session I spoke a bit with Ed, and he did say that his code was sub-par in some areas, but I couldn’t tell :) ) I might pick it back up after the conference.

I use jQuery in many of my projects, but after this session I feel a bit more confident if I need to work outside jQuery, and I understand a bit more about what is going on under the hood.

Blending PHP & MySQL with Your RPG Universe – Susan Gantner

After lunch I attended a session about integrating PHP and RPG code together. Like Ed’s talk, Susan’s was a good overview of PHP, MySQL, and RPG. I wished that her talk went over MySQL a bit more, but she has another session for that. Overall it was good to see that I am doing some things right.

I got a few tips for how to do things, but most of what she covered I had gone through within the last six months or so myself. I managed to meet a few people who were doing pretty heavy work with the iSeries and PHP, and I look forward to speaking with them later in the conference.

The Q&A ended up being mostly with the Zend folks (not Susan’s fault at all, everyone just kind of turned on poor Mike Pavlak with their Zend Server problems). If this session was any indication, the IBM i track this year should be good.

And Mike, if you read this, I promise to submit a support ticket for Zend Monitor.

Looking Forward to Day 2

Day 2 (for me) is the first day of the conference itself. I’ve also got a ZCE 5.3 test scheduled for the afternoon, so I’ve spent part of tonight studying for it. Tomorrow afternoon, I’ll either be at the hotel bar drinking my sorrows away at failing or celebrating. Plus I heard there are some good sessions and I’m sure that I’ll meet some great people.

Categories: IBM i, PHP, Programming, ZendCon 2010 | Tags: PHP, ZendCon
  • Search

  • Archives

    • February 2012
    • January 2012
    • September 2011
    • August 2011
    • April 2011
    • December 2010
    • November 2010
    • September 2010
    • August 2010
    • May 2010
    • April 2010
    • February 2010
    • January 2010
    • November 2009
    • October 2009
    • September 2009
    • June 2009
    • May 2009
    • February 2009
    • January 2009
    • November 2008
    • October 2008
    • July 2008
    • May 2008
    • February 2008
    • December 2007
    • October 2007
    • August 2007
    • July 2007
    • June 2007
    • May 2007
  • Categories

    • Code Releases
    • Doing Development
    • Hardware
    • IBM i
    • JavaScript
    • Joomla!
    • MySQL
    • Non-Programming
    • Operating Systems
    • Personal
    • PHP
    • Programming
    • Project Management
    • Reviews
    • Servers
    • Software
    • This Site
    • Tutorials
    • TWS Software
    • Uncategorized
    • ZendCon 2010
© Chris Tankersley. Proudly Powered by WordPress | Nest Theme by YChong