-
Notifications
You must be signed in to change notification settings - Fork 4
Using Application as a Router
← "IntegrationInterface" Implementation | Using Interfaces →
This kind of implementation is a use-case for creating quick Slytherin application without specifying anything. Since it is based on the Application
class, the previously discussed implementations like the ContainerInterface and IntegrationInterface can still be applied in this implementation.
The example code below can also be found from the The First "Hello World" page:
// app/web/index.php
use Rougin\Slytherin\Application;
// Load the Composer autoloader ----
$root = dirname(dirname(__DIR__));
require "$root/vendor/autoload.php";
// ---------------------------------
// Create a new application instance ---
$app = new Application;
// -------------------------------------
// Create a new HTTP route ---
$app->get('/', function ()
{
return 'Hello world!';
});
// ---------------------------
// Run the application ---
echo $app->run();
// -----------------------
Then check the Running the web server section on how to run the example code.
Note
As the Application
class is utilizing the Router
class from Routing
component, the defined methods of the latter can be used in the former.
As using IntegrationInterface
is an alternative for setting Slytherin's components, its important part is defining third-party custom implementations using Slytherin's defined interfaces. A guide for the list of Slytherin's interfaces can be found in the Using Interfaces page.
← "IntegrationInterface" Implementation | Using Interfaces →