Created
December 6, 2010 04:09
-
-
Save anandkunal/729843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'toro.php'; | |
$blog_posts = array( | |
array('title' => 'Evening Plans', 'body' => "I'm staying in to work on my law blog."), | |
array('title' => "You don't need double talk; you need Bob Loblaw", 'body' => 'True.'), | |
array('title' => "Why should you go to jail for a crime someone else noticed?", 'body' => "You shouldn't."), | |
); | |
function display_snippet($pos) { | |
echo '<a href="article/"' . $blog_post[$pos]['id'] . '</a>' . $blog_post[$pos]['title'] . '</a><br/>'; | |
} | |
function display_blog_post($pos) { | |
echo '<h1>' . $blog_post[$pos]['title'] . '</h1><p>' . $blog_post[$pos]['body'] . '</p>'; | |
} | |
function is_valid_post($pos) { | |
$pos = intval($pos); | |
return ($pos >= 0 && $pos < count($blog_posts)); | |
} | |
class BlogHandler extends ToroHandler { | |
public function get() { | |
// Splash page, display all entries. | |
for ($i=0; $i<count($blog_posts); $i++) { | |
display_snippet($i); | |
} | |
} | |
public function get_mobile() { | |
// Only display the last entry for mobile (Loblaw cares). | |
display_snippet(0); | |
} | |
} | |
class ArticleHandler extends ToroHandler { | |
public function get($post_id) { | |
// Display the post if it exists | |
if (is_valid_post($post_id)) { | |
display_blog_post($post); | |
} | |
else { | |
header('HTTP/1.0 404 Not Found'); | |
echo 'Post does not exist'; | |
exit; | |
} | |
} | |
} | |
class CommentHandler extends ToroHandler { | |
public function post_xhr($post_id) { | |
// Bob Loblaw never got around to implementing this, here is pseudo PHP | |
if (is_valid_post($post_id)) { | |
// Assuming you save this comment, just return JSON if the post exists | |
echo json_encode(array( | |
'commentor' => $_POST['commentor'], | |
'comment_body' => $_POST['comment_body'] | |
)); | |
} | |
} | |
} | |
$site = new ToroApplication(array( | |
array('/', 'BlogHandler'), | |
array('article/([a-zA-Z0-9_]+)', 'ArticleHandler'), | |
array('comment/([a-zA-Z0-9_]+)', 'CommentHandler'), | |
)); | |
$site->serve(); |
Hey Justin - I already have a project: http://toroweb.org/ - between this and all the other stuff I'm up to, I don't know how much time I'll be able to commit. I'm happy to contribute code and ideas - just don't think I'd make a good full time maintainer :)
I saw that actually.. didn't realize toro was a framework. Sorry about that!! Right now I'm still learning the ins and outs of Silex and OO style. I really like it. I'm tempted to git Toro and see what I can do with it.. but Silex has the built in Twig, Doctrine, Memcached, Session management functionality which I'm not sure I want to recreate in Toro.. unless you've already got it? How would I work all that with Toro?
…-----Original Message-----
From: Kunal Anand [mailto:reply@reply.github.com]
Sent: Wednesday, October 12, 2011 5:54 PM
To: Justin Pfister
Subject: Re: gist gist: 729843
Hey Justin - I already have a project: http://toroweb.org/ - between this and all the other stuff I'm up to, I don't know how much time I'll be able to commit. I'm happy to contribute code and ideas - just don't think I'd make a good full time maintainer :)
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/729843
hey - I forked you. http://toro.kyotist.com/article/Evening%20Plans -- what URL structure are you going for?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lets get a public project going on .. MAtt and I have been doing a lot with Php-OO and Silex on Ngin-x