PHP code example of phonetworks / pho-server-rest

1. Go to this page and download the library: Download phonetworks/pho-server-rest 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/ */

    

phonetworks / pho-server-rest example snippets



de("PATH/TO/YOUR/KERNEL");
$server = new \Pho\Server\Rest\Server($kernel);
$server->port(8080);
$server->serve();



/**
 * Returns the routes object to manipulate the behaviour of the server
 * @return self
 */
$server->routes();

/**
 * Returns all existing routes
 * @return self
 */
$server->routes()->all();

/**
 * Adds a new route:
 * @param string $method HTTP Method, like GET, PUT, DELETE
 * @param string $path HTTP Path like /some_path
 * @param callable $func Function to call with arguments; $request (\Psr\Http\Message\ServerRequestInterface), $response (\React\Http\Response)
 * @return void
 */
$server->routes()->add("GET", "/path/{arg:[0-9]+}", function($request, $response, $arg) {

});

/**
 * Select no route
 * @return self
 */
$server->routes()->none()

/**
 * Select all routes, minus the defined ones.
 * @return self
 */
$server->routes()->all()->but(...)

/**
 * Select only the defined ones.
 */
$server->routes()->only(...)

/**
 * Only admins can access the selected routes
 * The opposite is: `unlock()`
 * @return void
 */
$server->routes()->only(...)->lock()

/**
 * No one can access the selected routes
 * The opposite is: `enable()`
 * @return void
 */
$server->routes()->only(...)->disable()




Session::depend();
Session::destroy();
Session::begin();