 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Michael Nitschinger's Blog: A primer on PHP exceptions
by Chris Cornutt May 23, 2012 @ 09:17:41
Michael Nitschinger has a new post focusing on one of the more commonly used, but maybe just as commonly misunderstood, part of PHP - exceptions and their handling. His latest post looks at what Exceptions in PHP have to offer and provides some "best practices" in their use.
Exceptions are and should be an integral part of any general purpose programming language. PHP introduced them long ago (with the release of PHP 5 or 5.1), but it still seems that many of the concepts are not fully understood or ignored by the community. This post aims to be a solid introduction to exception architecture, handling and testing. At the end of the post you should be able to know when to raise an exception and how it should look like.
He talks about situations when (and when not) to use exceptions, normalizing them for easier try/catch-ing and includes the exception class hierarchy, including the types pulled from the SPL. He shows examples (based on the Lithium framework's namespacing) how to create "namespaced exceptions" and how to use these in a bit of sample code. He also mentions the use of the custom error handling with the ErrorException as well as a quick look at testing these basic and custom exceptions correctly (PHPUnit-based tests).
voice your opinion now!
exception custom namespace tutorial primer unittest lithium
Michael Nitschinger's Blog: Introducing Relationships in Lithium
by Chris Cornutt March 05, 2012 @ 11:21:39
In this new post to his blog Michael Nitschinger introduces relationships in using the Lithium framework - functionality to link your models to each other to create dependencies.
The model relationship support in Lithium is one of the hottest topics on IRC lately, so I thought it would be a good idea to blog about it. Currently, Lithium supports 1:1 and 1:n relationships for relational databases. [...] This post gives you a little background on relationship types and their database representations before we implement a simple example in PHP.
He gives some code (and schema) examples of creating these relationships between tables for the two types - one to one and one to many. He also touches on the zero-to-zero relationships as well, nothing that they can be some of the most tricky to work with. He includes the SQL and the code you'll need to produce a blog example with models for Authors, Posts and Groups. Using the belongsTo/hasMany/hasOne variables he defines the relationships and uses the "with" keyword in the find calls to pull in those relations.
voice your opinion now!
relationship lithium framework model database introduction
Michael Nitschinger's Blog: Playing with Composer and Lithium
by Chris Cornutt January 24, 2012 @ 10:20:51
Michael Nitschinger has a new post to his blog looking at using the popular Composer tool for package management together with Lithium to make dependency management simpler.
Composer is a command-line tool that helps you manage your application dependencies. It automatically fetches packages, resolves dependencies and is easy to configure. [...] Currently, Lithium doesn't provide Composer packages out of the box, but it's easy to write one.
He starts the post with an introduction to using Composer for those new to the tool, then moves quickly into setting up your "composer.json" file to pull in the Lithium updates from their github account. Additionally, he shows how to add a dependency for twig in the "require" section and pull it down at the same time (with dependencies).
voice your opinion now!
lithium framework composer packagist package dependency tutorial
Michael Nitschinger's Blog: Session Encryption with Lithium
by Chris Cornutt January 20, 2012 @ 12:09:08
Michael Nitschinger has a new post for the Lithium framework users out there - a quick tutorial about encrypting your session information with the new built in "Encrypt" strategy feature.
If you check out the master branch, you can use the new Encrypt strategy to encrypt your session data automatically. This means that you can read and write session data in cleartext and they will be encrypted on the fly before getting stored (in a cookie, for example).
You'll need the mcrypt extension installed for it to work correctly, but it makes storing the encrypted version of your data more or less automatic. Just set up your Session configuration to use it as a strategy and any time you call a "read" or "write" the hard work is handled for you. For those more interests in what's "under the hood" he goes on to talk about how the strategy works, what cipher it uses by default, how to change it and the default string to use in hashing.
voice your opinion now!
lithium framework session encryption strategy configuration secret hash
Paul Reinheimer's Blog: The Danger of Hooks
by Chris Cornutt January 12, 2012 @ 09:12:18
Paul Reinheimer has a recent post to his blog talking about the danger of "hooks" in your development - the functionality several frameworks and other tools come with to allow you to add functionality to the core without having to change the main source.
I ran into hooks rather simultaneously with two very different frameworks: Code Igniter and Lithium. In both cases I was using a rather nifty hook to handle ensuring that users were properly authenticated and authorized before accessing a page. [...] One day, while messing around, I accidentally turned off the hook configuration within Code Igniter (actually I clobbered a file, and restored the wrong one). Then, things came crashing down in a horrible cacophony of... actually they didn't. Everything kept working: that was the problem.
He shows two solutions he came up with to be sure that his hooks were executed - one for Lithium and the other for CodeIgniter. The Lithium one uses a "_remap" method and the CodeIgniter example uses the magic "__invoke" method to check for an "AUTH_CHECKED" constant that's only defined as a part of his hooks.
I'm no longer entirely dependent on one configuration option or file for my security to function. Should it fail, I've got a secondary check in place; this example of defence in depth allows me to be comfortable with the hooks security system once more.
voice your opinion now!
danger hook framework codeigniter lithium failure
Richard McIntyre's Blog: Using OAuth in Lithium
by Chris Cornutt December 30, 2011 @ 13:11:34
Richard McIntyre has a new post to his blog showing how he set up OAuth support in a Lithium-based application with the help of a handy plugin (li3_oath).
The OAuth protocol is a fantastic way to login to remote services and websites. Unfortunately the spec is different in OAuth 1.0 and the yet un-solidified 2.0, the implementation is also different across different services. At the moment this is a bit of a goose chase, but libraries like li3_oauth can help! [...] I like to be in control and calling the shots! I also want to have users have the option to login to other services under the same umbrella. Working directly with OAuth is what I wanted to do. Of course I was doing this in Lithium because it is clearly the best PHP Framework!
His process is broken up into four steps:
- Grab the latest version of the li3_oauth plugin
- Fork and refactor the plugin
- Create the Tweet and Facebook controllers
- Refactor a bit more to turn it into a service
The code changes are pretty minimal and are included in the post.
voice your opinion now!
lithium framework oauth tutorial refactor plugin
Lukas Smith's Blog: My PHP framework winner predictions
by Chris Cornutt September 20, 2011 @ 12:53:38
Lukas Smith has posted some of his thoughts on who the framework winners are right now and which might pull ahead in the future including Symfony and Zend Framework.
I have not been that active on the conference scene in the past few years, but the ones where I did attend I also tried to take a peek at what others are doing. Also this post is kind of exploratory to see what other people think, hopefully without inviting a flame fest upon myself. So with this disclaimer out of the way, I think the big 3 frameworks for the next few years will be Lithium, Zend Framework 2 and Symfony2.
He looks at each of his "winners" and explains his rationale behind their selection including community support, features offered and the overall structure and feel of the framework. He mentions two other interesting frameworks of note that have come out of other projects - Flow3 and Nooku. Comments on the post suggest even more frameworks to look to in the future including Yii and mentions of Nette and CodeIgniter.
voice your opinion now!
framework winner opinion zendframework2 lithium symfony2
Michael Nitschinger's Blog: Quick Tip Lithium Redirect
by Chris Cornutt September 16, 2011 @ 10:02:21
Michael Nitschinger has a "quick tip" posted in this new entry to his blog - how to handle a redirect in a Lithium-framework based application.
While migrating pastium over to MongoDB (from CouchDB), I found [a] snippet in the routes.php file [that makes it so] when the user enters the application via the root url (/), he instantly gets redirected to /pastes/add (or a different URL if you have custom routes configured). This may seem ok at first, but there's a problem. It doesn't take URLs into account that don't live directly under the document root.
The snippet he references and others showing how to correct the issue are included - replacing the location array controller/action information with the static class information for the route in a match() call. For more information on the routing in Lithium, see these manual pages.
voice your opinion now!
lithium framework tip redirect method
|
Community Events
Don't see your event here? Let us know!
|