PHP code example of nervsys / ns

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

    

nervsys / ns example snippets



$ns = new Nervsys\NS();

$ns->setApiDir('myApiPath')
    ->setDebugMode(true)
    ->setContentType('application/json')
    ->addPreHooks('/', [\app\hook\ApiCheck::new(), 'userToken'])
    ->addAutoloadPath($ns->app->root_path . DIRECTORY_SEPARATOR . 'library');

$ns->go();

namespace api;

class user
{
    public function login($name, $passwd)
    {
        //your code

        return $name . ' is online!';
    }
}

namespace api;

class user
{
    public function login($name, $passwd, int $age)
    {
        //your code

        return $name . ' is ' . $age . ' years old.';
    }
}
text
ROOT path based: /namespace/class_name/public_method_name

examples:
URL: NOT support.

CLI: php index.php /app/user/login => calling "login" method in "\app\user" class.
CLI: php index.php -c"/app/user/login" => calling "login" method in "\app\user" class.

GET: http://your_domain/index.php?c=/app/user/login
POST: pass directly "/app/user/login" in "c" parameter, both support FormData or request Payload.
text
parameters in any order:
URL: http://your_domain/index.php/user/login?name=admin&passwd=admin&age=30&type=client
URL: http://your_domain/index.php/user/login?passwd=admin&age=30&name=admin&type=client