PHP code example of jeph / frame

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

    

jeph / frame example snippets



me = new JEPH\Frame();

$frame->get( '/', function() {
    echo 'Hello World!';
} );

$frame->run();

$frame->get( '/resource', $handler );
$frame->post( '/resource', $handler );
$frame->put( '/resource', $handler );
$frame->delete( '/resource', $handler );
$frame->patch( '/resource', $handler );
$frame->options( '/resource', $handler );
$frame->head( '/resource', $handler );

$frame->any( '/api', function() {
    echo 'Handles any HTTP method';
} );

$frame->get( '/user/{id:\d+}', function( $vars ) {
    echo "User ID: {$vars['id']}";
} );

$frame->get( '/hello/{name:\w+}', function( $vars ) {
    echo "Hello {$vars['name']}!";
} );

$frame->get( '/page[/{slug:\w+}]', function( $vars ) {
    $slug = $vars['slug'] ?? 'home';
    echo "Page: $slug";
} );

$frame->get( '/hello', function( $vars ) {
    echo 'Hello!';
} );

$frame->get( '/dashboard', __DIR__ . '/routes/dashboard.php' );


$id = $_frame['id'] ?? null;
echo "ID: $id";

class ApiResource {
    public function get( $vars ) {
        echo "GET request";
    }
    public function post( $vars ) {
        echo "POST request";
    }
}

$frame->get( '/api/resource', [ 'ApiResource' ] );
$frame->post( '/api/resource', [ 'ApiResource' ] );

$frame = new JEPH\Frame();
$frame->set_cache_file( '/tmp/routes.cache' );

$frame->get( '/', function() {
    echo 'Hello World!';
} );

$frame->run();

$frame = new JEPH\Frame();

if ( getenv( 'APP_ENV' ) === 'production' ) {
    $frame->set_cache_file( '/tmp/routes.cache' );
}

$frame->get( '/', function() {
    echo 'Hello World!';
} );

$frame->run();

$frame->set_not_found_handler( function( $vars ) {
    echo "Page not found: {$vars['uri']}";
} );

$frame->set_method_not_allowed_handler( function( $vars ) {
    $allowed = implode( ', ', $vars['allowed'] );
    echo "Method not allowed. Try: $allowed";
} );

$frame->set_not_found_handler( __DIR__ . '/errors/404.php' );
$frame->set_method_not_allowed_handler( __DIR__ . '/errors/405.php' );


// errors/404.php
echo "Page not found: {$_frame['uri']}";