PHP code example of cloudframework-io / backend-core-php8

1. Go to this page and download the library: Download cloudframework-io/backend-core-php8 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/ */

    

cloudframework-io / backend-core-php8 example snippets



class API extends RESTful
{
    function main()
    {
        // Add data to the response
        $this->addReturnData('Hello World');
    }
}


class API extends RESTful
{
    function main()
    {
        // Restrict HTTP methods
        if(!$this->checkMethod('GET,POST,PUT,DELETE')) return;

        // Route to specific endpoint
        $endpoint = $this->params[0] ?? 'default';
        if(!$this->useFunction('ENDPOINT_'.$endpoint)) {
            return $this->setErrorFromCodelib('params-error', "Endpoint not found");
        }
    }

    public function ENDPOINT_default()
    {
        $this->addReturnData([
            "message" => "Welcome to the API",
            "endpoints" => ["/hello", "/users", "/data"]
        ]);
    }

    public function ENDPOINT_hello()
    {
        if(!$this->checkMethod('GET')) return;
        $this->addReturnData('Hello from endpoint');
    }
}


class Script extends Scripts2020
{
    function main()
    {
        $method = $this->params[0] ?? 'default';
        if (!$this->useFunction('METHOD_' . $method)) {
            return $this->setErrorFromCodelib('params-error', "Method not found");
        }
    }

    function METHOD_default()
    {
        $this->sendTerminal("Hello from script!");
    }
}
shell
php vendor/cloudframework-io/backend-core-php8/install.php