Sinatra clone in PHP
github.com
github.com
Documentation: http://slim.joshlockhart.com/
GitHub (with Download): http://github.com/codeguy/Slim
Still very much a work in progress, but thought I'd go ahead and get the word out.
Enjoy! Josh
It is easy to implement the query API in any language that supports anonymous functions, but that doesn't make it Sinatra.
This one is not even a good example of a clone: its really bare, only implements the minimal set to "look like sinatra". It doesn't even have a good request or response object.
Check it out:
http://github.com/dhotson/kelpie
http://github.com/dhotson/kelpie/blob/master/demoapp.php
It's got its own Rack style web server built in ... kinda crazy huh? ;-)
My problem in the PHP world is: you have your Rack-style server. Another project has a different style. In Ruby, every framework nowadays is on Rack.
It's a real challenge to make nice looking mini languages in PHP. At least Ruby gives you a bit more rope to make clever little languages. /envy
But yeah, I really wish PHP had a web server interface like Rack that was more widely accepted. The two that look the most promising are:
http://github.com/indeyets/appserver-in-php
Also, the downside of implementing your own web server is that basically zero existing PHP code will work with it. It's because you have to re-implement all the usual superglobal stuff $_GET $_POST $_SESSION etc..
.. I consider that a plus. ;-)
It really depends, frameworks like Agavi do not use $_GET etc. and explicitly disallow their use.
I can't claim much credit for the design of Kelpie, it's mostly a direct port of Ruby's Thin web server. I guess there's a couple of notes I'd make:
- I'd recommend using the mongrel http parser rather than implementing your own. I wrote a PHP extension for it - http://github.com/dhotson/httpparser-php
Also, some cosmetic stuff (feel free to ignore):
- I prefer camelCase for methods
- public/private access control on methods
- PHP namespaces look and act weird to me so I don't use them
- I prefer using underscores in names and a classloader to avoid require statements
Also, I've pretty much developed my own PHP style. I don't follow PEAR conventions.. I go with what looks clearest to me. So obviously you'll want to take my advice with a grain of salt.
For those (like me) that had no clue what sinatra was before this.
http://github.com/leftnode/Hoboken
My personal site uses it: http://leftnode.com
I'll have to check this out to see how it competes :).
http://github.com/sofadesign/limonade
http://github.com/jim/fitzgerald
http://github.com/fabpot/Silex (based on Symfony 2)
Update: Done.
The same effect is in Clojure, but it is a little bit more difficult to explain.
They're lost the beauty of Lisp (especially Scheme) when they broke the clarity and unambiguity of the syntax pushing all those foreign symbols into it. Moreover, they also renamed and broke most of common idioms, using words that could be better as a variable names instead of keywords.
So, it is not a Lisp dialect, even not so-called Lisp-1. It is just yet another JVM-targeted pseudo-functional language, which, OK, looks like lisp to those who never seen a Lisp before.
But, its cool (and ugly), I must admit. ^_^
i think "those php guys" are well aware that their language is not ruby and care more about getting work done than whether they have to type dollar signs and brackets.
PHP makes it very hard to write "beautiful" frameworks like Sinatra. There's a whole bunch of crufty looking stuff in PHP that is unavoidable.
That doesn't stop me from writing PHP and getting-shit-done. That's an entirely different argument though.