Skip to content

Commit

Permalink
Updating README.md and removing bad examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
anandkunal committed Aug 14, 2012
1 parent 4116103 commit 865fef9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 166 deletions.
128 changes: 61 additions & 67 deletions README.md
@@ -1,8 +1,9 @@
# ToroPHP

Toro is a tiny framework for PHP that lets you prototype web applications quickly.
Toro is a tiny router that lets you develop PHP web applications quickly.

* [Official Website & Documentation](http://toroweb.org)

* [Toro Home Page](http://toroweb.org)

## The Primordial Application

Expand All @@ -11,114 +12,107 @@ The canonical "Hello, world" example:
```php
<?php

require_once 'toro.php';

class MainHandler extends ToroHandler {
public function get() {
echo 'Hello, world';
function get() {
echo "Hello, world";
}
}

$site = new ToroApplication(array(
array('/', 'MainHandler')
Toro::serve(array(
"/" => "MainHandler",
));

$site->serve();
```

## A Substantial Application

Here is a slightly more advanced application garnished with pseudocode:

require_once 'toro.php';

class BlogHandler extends ToroHandler {
public function get() {
echo 'This the front page of the blog. Load all articles.';
}
```php
<?php

public function get_mobile() {
// _mobile => fires if iPhone/Android/webOS is detected
echo 'Load a subset of the articles.';
}
class BlogHandler extends ToroHandler {
function get() {
echo "This the front page of the blog. Load all articles.";
}
}

class ArticleHandler extends ToroHandler {
public function get($slug) {
echo 'Load an article that matches the slug: ' . $slug;
}
class ArticleHandler extends ToroHandler {
function get($slug) {
echo "Load an article that matches the slug: $slug.";
}
}

class CommentHandler extends ToroHandler {
public function post($slug) {
echo 'Validate slug - redirect if not found.';
echo 'Peek into $_POST, save the comment, and redirect.';
}

public function post_xhr($slug) {
// _xhr => fires if XHR request is detected
echo 'Validate, save, and return a JSON blob.';
}
class CommentHandler extends ToroHandler {
function post($slug) {
echo "Peek into the POST, save the comment, and redirect.";
}

class SyndicationHandler extends ToroHandler {
public function get() {
echo 'Display some recent entries in RSS/Atom.';
}
function post_xhr($slug) {
echo "Validate, save, and return a JSON blob.";
}
}

$site = new ToroApplication(array(
array('/', 'BlogHandler'),
array('article/([a-zA-Z0-9_]+)', 'ArticleHandler'),
array('comment/([a-zA-Z0-9_]+)', 'CommentHandler'),
array('feed', 'SyndicationHandler')
));

$site->serve();
Toro::serve(array(
"/" => "BlogHandler",
"/article/:alpha", "ArticleHandler",
"/article/:alpha/comment", "CommentHandler"),
));
```


## Toro Hooks

There are 4 possible hooks (callbacks).
There are 5 possible hooks (callbacks).

ToroHook::add('before_request', function() {});
ToroHook::add('before_handler', function() {});
ToroHook::add('after_handler', function() {});
ToroHook::add('after_request', function() {});
```php
<?php

ToroHook::add("404", function() {});

ToroHook::add("before_request", function() {});
ToroHook::add("before_handler", function() {});
ToroHook::add("after_handler", function() {});
ToroHook::add("after_request", function() {});
```

While you can hook before\_handler and after\_handler anywhere, like index.php, most people will probably want to use it in a handler's constructor:

class SomeHandler extends ToroHandler {
public function __construct() {
ToroHook::add('before_handler', function() { echo 'before'; });
ToroHook::add('after_handler', function() { echo 'after'; });
}
```php
<?php

class SomeHandler extends ToroHandler {
function __construct() {
ToroHook::add("before_handler", function() { echo "Before"; });
ToroHook::add("after_handler", function() { echo "After"; });
}

public function get() {
echo 'I am some handler.';
}
function get() {
echo "I am some handler.";
}
}
```

Adding a hook pushes the function into an array. When a particular hook is fired, all of the functions are fired in the appropriate order.

ToroHook was provided by [Danillo César de O. Melo](https://github.com/danillos/fire_event/blob/master/Event.php). ToroHook will be the foundation for the future plugin system.

## Installation

Grab the source and copy toro.php to your htdocs or lib directory directory.
Grab the source and copy toro.php to your htdocs or lib directory.

Couch the following in your Apache configuration or .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]

## Roadmap

The immediate plan is to complete the following:
## Credits

ToroHook was provided by [Danillo César de O. Melo](https://github.com/danillos/fire_event/blob/master/Event.php). ToroHook will be the foundation for the future plugin system.

Special thanks to [Jason Mooberry](http://jasonmooberry.com) for code optimizations.


* Add more example projects.
* Add more documentation.
* Setup a mailing list.
## License

Toro is intended to be a minimal framework to help you organize and prototype your next PHP application. One of the project's goals is to make sure the source stays lean.
ToroPHP is open-source software licensed under the MIT License.
29 changes: 0 additions & 29 deletions examples/01_hello_world.php

This file was deleted.

70 changes: 0 additions & 70 deletions examples/02_blog_sketch.php

This file was deleted.

0 comments on commit 865fef9

Please sign in to comment.