PHP code example of peterhorne / elmer

1. Go to this page and download the library: Download peterhorne/elmer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

peterhorne / elmer example snippets




use Elmer\Environment;
use Elmer\Response;
use Elmer\Routes;


		return new Response(200, 'Hello, world!');
	}
});

$response = $app(Environment::initFromGlobals());
$response->send();



$app->post();
$app->delete();
$app->brew(); // Custom methods are supported


$app->get('/users/:int', function($app, $id) {
	return "You are user #$id";
});

:any // Anything (alpha, num, underscore, or dash)
:int // Any integer
:alpha // Any alphabetic character
:alphanum // Any alphanumeric character
:year // 4 digits
:month // 1 - 12
:day // 1 - 31


$app->patterns['names'] = '(peter|simon|john)';


$app->get('/articles/:year?', function($app, $year = 2012) { .. });


$app->filter(function($app, $route)) {
	$response = $route();
	$response['body'] .= 'Bar';
	
	return $response;
}

$app->get('/', function() {
	return 'Foo';
}


$app->group(function($app) {
	
	// Declare filters here
	// Declare routes here
}


$app->group(function($app) {
	$app->filter(function($route) { .. }); // Filter A
	$app->get('/foo', function() { .. });
	
	$app->group(function($app) {
		$app->filter($route) { .. }); // Filter B
		$app->get('/bar', function() { .. });
	});
});


$app->group('/user', function($app) {
	$app->get('/profile', function() { .. });
}