PHP code example of tcdev / macaw

1. Go to this page and download the library: Download tcdev/macaw 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/ */

    

tcdev / macaw example snippets


use \marcfowler\macaw\Macaw;

Macaw::get('/', function() {
  echo 'Hello world!';
});

Macaw::dispatch();

Macaw::setPrefix('/subfolder/somewhere-else/');
Macaw::get('/', function() {
  echo 'Hello!';
});

Macaw::get('/(:any)', function($slug) {
  echo 'The slug is: ' . $slug;
});

Macaw::dispatch();

Macaw::get('/', function() {
  echo 'I <3 GET commands!';
});

Macaw::post('/', function() {
  echo 'I <3 POST commands!';
});

Macaw::dispatch();

Macaw::haltOnMatch(true); // This will prevent further execution once a match is found

Macaw::get('/', function() {
  echo 'Hello world!';
});

Macaw::dispatch();

echo 'I am further execution...';

Macaw::setMethod('POST');

Macaw::error(function() {
  echo '404 :: Not Found';
});