Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 32b5afd3bf
Fetching contributors…

Cannot retrieve contributors at this time

662 lines (412 sloc) 10.211 kB

Function Reference

after()

- void after( callback $function )

Synopsis:

Defines a new filter.

Callback $function will be called after routing takes place.

Note:

If you call after() multiple times, each callback will be called in the order it was defined.

Example:

<?php

after(function(){
// Put your shutdown routines here.
});

any()

- void any( string $route, callback $function )

Synopsis:

Defines a new route.

Callback $function will be called if any request is made for a URI that matches $route.

Example:

<?php

any('/', function(){
display('index');
});

- void any( array $methods, string $route, callback $function )

Synopsis:

Defines a new route.

Callback $function will be called if a request is made where the request method is defined in $methods and the URI matches $route

Example:

<?php

any(array('GET','PUT'), '/', function(){
    display('index');
});

before()

- void before( callback $function )

Synopsis:

Defines a new filter.

Callback $function will be called before routing takes place.

Note:

If you call before() multiple times, each callback will be called in the order it was defined.

Example:

<?php

before(function(){
    layout('index');
});

condition()

- void condition( string $name [, mixed $... ] )

Synopsis:

Dispatches a condition.

Condition specified by $name will be called. If the condition returns false, pass() is called which skips the current route and continues routing.

Note:

Additional arguments are sent to the callback function specified by $name.

Example:

<?php

get('/', function(){
    condition('user_is_jeff');
    display('jeff');
});

get('/', function(){
    condition('user_agent_matches', '/iphone/i');
    display('iphone');
});

- void condition( string $name, callback $function )

Synopsis:

Defines a condition.

The callback $function can be dispatched by $name after this function has been called. Remember that the callback should return a boolean which indicates if the condition was met or not.

Example:

<?php

condition('user_is_jeff', function($user){
    return $user-getUserName() == 'jeff';
});

get('/', function(){
    condition('user_is_jeff', $user);
    display('jeff');
});

config()

- mixed config( string $name )

Synopsis:

Gets the configuration value identified by $name.

Example:

<?php

$template_engine = config('template_engine');

- void config( string $name, mixed $value )

Synopsis:

Sets a configuration value.

Example:

<?php

config('template_engine', 'Smarty');

- void config( array $values )

Synopsis:

Sets multiple configuration values in a single statement.

Example:

<?php

config(array(
    'template_engine' ='Smarty',
    'template_extension' ='.tpl'
));

delete()

- void delete( string $route, callback $function )

Synopsis:

Defines a new route.

Callback $function will be called if a DELETE request is made for a URI that matches $route.

Example:

<?php

delete('/route', function(){
    display('template');
});

display()

- void display( string $path [, array $variables] )

Synopsis:

Renders a template at $path and displays it to the end-user.

Example:

<?php

get('/', function(){
    display('index');
});

get('/hello', function(){
    display('hello', array('name'='Jeff'));
});

error()

- void error( string $message )

Synopsis:

Dispatches a generic error.

Example:

<?php

get('/', function(){
    if (!$user-logged_in) {
        error('You must be logged in to view this page.');
    }
});

- void error( integer $error_code [, string $message = 'An Error Occurred.'] )

Synopsis:

Dispatches an HTTP error.

If the $error_code corresponds to a standard HTTP error, an HTTP status header will be dispatched with the appropriate code.

Note:

If a standard HTTP $error_code is provided with no message, the corresponding error message will be used.

See:

List of HTTP status codes.

Example:

<?php

get('/', function(){
    if (!$user-logged_in) {
        error(403); // 403 Forbidden
    }
});

get('/', function(){
    if (!$user-logged_in) {
        error(403, 'Forbidden'); // 403 Forbidden
    }
});

- void error( callback $function )

Synopsis:

Adds a default error handler.

Callback $function gets called for errors that have no defined handler.

Example:

<?php

error(function(){
    display('default_error');
});

- void error( mixed $error, callback $function )

Synopsis:

Adds an error handler.

Callback $function gets called for errors that are associated with the provided $error.

  • If $error is an integer, the callback is associated with the corresponding error code.
  • If $error is a string, the callback is associated with the corresponding exception.
  • If $error is an array, the callback is associated with all exceptions and codes defined in the array.

Example:

<?php

error(500, function(){
    display('server_error');
});

error('ForbiddenException', function(){
    display('forbidden');
});

error(array(403,404), function(){
    display('http_error');
});

fetch()

- string fetch( string $path [, array $variables] )

Synopsis:

Renders a template at $path and returns it.

Example:

<?php

$contents = fetch('path/to/template');
$contents = fetch('path/to/template', array('name'='Jeff'));

get()

- void get( string $route, callback $function )

Synopsis:

Defines a new route.

Callback $function will be called if a GET request is made for a URI that matches $route.

Example:

<?php

get('/route', function(){
    display('template');
});

helper()

- void helper( string $name, callback $function )

Synopsis:

Defines a new helper.

Callback $function will be declared as a standard PHP function identified by $name.

Example:

<?php

helper('add_numbers', function($num1, $num2){
    return $num1 + $num2;
});

echo add_numbers(5, 10); // 15

layout()

- void layout( string $path )

Synopsis:

Sets the layout.

Example:

<?php

layout('path/to/layout');

partial()

- string partial( string $path [, array $variables] )

Synopsis:

Renders a template at $path without a layout and returns it.

Example:

<?php

$contents = partial('path/to/template');
$contents = partial('path/to/template', array('name'='Jeff'));

pass()

- void pass( void )

Synopsis:

Exits out of the current route and continues routing.

Example:

<?php

get(';/posts.*;', function(){
    layout('posts');
    pass();
});

get('/posts', function(){
    display('list_posts');
});

get(';/posts/(\d+);', function(){
    display('view_post');
});

post()

- void post( string $route, callback $function )

Synopsis:

Defines a new route.

Callback $function will be called if a POST request is made for a URI that matches $route.

Example:

<?php

post('/route', function(){
    display('template');
});

put()

- void put( string $route, callback $function )

Synopsis:

Defines a new route.

Callback $function will be called if a PUT request is made for a URI that matches $route.

Example:

<?php

put('/route', function(){
    display('template');
});

redirect()

- void redirect( string $url [, integer $status_code = 302 [, boolean $exit = true]] )

Synopsis:

Redirects the end-user to a new url.

Note:

If $exit is set to false, the application will not terminate after the location header is sent. This is only appropriate for testing.

Example:

<?php

redirect('http://www.breezephp.com/');
redirect('http://www.breezephp.com/', 301); // Issues a 301 status header

register()

- void Breeze\Application::register( string $name, callback $function )

Synopsis:

Registers a new plugin.

Callback $function will be called each time Breeze\Application is instantiated.

Example:

<?php

namespace Breeze\Plugins\Auth {
    use Breeze\Application;
    require_once 'Breeze/Application.php';

    Application::register('Auth', function($app){
        $app-helper('auth', function($user, $redirect_url) use ($app){
            if($user-name != 'admin') {
                $app-redirect($redirect_url);
            }
        });
    });
}

run()

- void run( [string $request_method [, string $uri]] )

Synopsis:

Starts the routing process.

Note:

You may coerce the request method and request URI by providing the $request_method and $uri arguments respectively. This is useful for testing.

Example:

<?php

run('GET', '/posts/2');

status()

- string status( void )

Synopsis:

Gets the current HTTP status.

Example:

<?php

status() // HTTP/1.1 200 OK

- string status( integer $statusCode [, string $httpVersion] )

Synopsis:

Sets the current HTTP status.

Example:

<?php

status(204); // header('HTTP/1.1 204 No Content');
status(204, '1.0'); // header('HTTP/1.0 204 No Content');

template()

- mixed template( string $name )

Synopsis:

Gets the template value identified by $name.

Example:

<?php

$title = template('page_title');

- void template( string $name, mixed $value )

Synopsis:

Sets a template value.

Example:

<?php

template('page_title', 'Welcome to my website');

- void template( array $values )

Synopsis:

Sets multiple template values in a single statement.

Example:

<?php

template(array(
    'page_title' ='Welcome to my website',
    'user_name' ='Jeff'
));
Jump to Line
Something went wrong with that request. Please try again.