Skip to content

A simple PHP framework to explain the concepts of requests, responses and how a router works

Notifications You must be signed in to change notification settings

rbgadotti/TinyFramework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tiny Framework

A simple PHP framework to explain the concepts of requests, responses and how a router works, using regex and single responsibility principles

What I Learned

  • Single responsibility principle
  • Regex
  • How a router works
  • Http Verbs

Usage

$app = new Tiny\App;

// Example 1;
$app->route(['GET', 'POST'], '/json', function($request, $response){
	// echo 'hello route';
	$response->json(array('status' => 'not found'), 404);
});

// Example 2; Same as Example 1;
$app->get('/hello', function($request, $response){
	$response->write('hello route');
});

$app->post('/hello', function($request, $response){
	$response->write('hello route');
});

// Example 3; Set route to all methods;
$app->any('/foo', function($request, $response){
	$response->write('hello route');
});

// Example 4; Route to Ajax;
$app->ajax('GET', '/hello', function($request, $response){
	$response->write('hello route');
});

// Example 5; Group
$app->group('/teste', function() use ($app){

	$app->get('/oi', function($request, $response){ $response->write('Teste->Oi Works!'); });
	$app->get('/hi', function($request, $response){ $response->write('Teste->hi Works!'); });

});

// Example 6; Controller;
Class ExampleController {
	public function sayHello($request, $response){
		$response->write('Hello from exampleController!');	
	}
}
$app->get('/controller', 'ExampleController@sayHello');

$app->run();

About

A simple PHP framework to explain the concepts of requests, responses and how a router works

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages