1. Go to this page and download the library: Download elephox/miniphox-framework 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/ */
elephox / miniphox-framework example snippets
declare(strict_types=1);
// this is the default namespace; can be specified in build()
namespace App;
index(): string {
return "Hello, World!";
}
#[Get('/greet/[name]')] // using route params
function greet(string $name): string {
return "Hello, $name!";
}
// This creates a new Miniphox app.
MiniphoxBase::build()
// index() and greet() are mounted at '/api'.
// This maps '/api' -> index() and '/api/greet/[name]' -> greet() according to their attributes above.
//
// You can pass first-class-callables or just the method name to the mount method.
->mount('/api', index(...), 'greet')
// This will start the HTTP server on http://0.0.0.0:8008.
// Pass a string uri to bind to a specific ip address or a different port.
->run();
// [...]
#[Get('/count')]
function counter(stdClass $counter): string {
// $counter will get injected from the service specified below
return "The current count is $counter->i";
}
$app = Miniphox::build()->mount('/api', counter(...));
// transient services get created every time they are requested (unlike singletons)
$app->services->addTransient(stdClass::class, stdClass::class, function () {
static $i; // this keeps track of how many times this services was created
$counter = new stdClass();
$counter->i = ++$i;
return $counter;
});
$app->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.