PHP code example of enicore / ravenapi

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

    

enicore / ravenapi example snippets


const API_DIR = __DIR__ . "/";
stance([
    "host" => "db_host",
    "port" => "db_port",
    "username" => "db_username",
    "password" => "db_password",
    "database" => "db_database",
    "options" => [],
]);

Enicore\RavenApi\App::instance()->run();

namespace Controllers;

class DashboardController extends \Enicore\RavenApi\Controller
{
    public function getPageAction(): array

$id = $this->request->get('id');
$id = $this->request->getDecodedId(); // retrieve and decode the encoded id
$all = $this->request->all();

public function getPageAction(): array
{
    return ["hello" => "world"];
}

$this->response->success(["hello" => "123"]);

$this->response->error("Cannot save record.");

#[NoAuth]
public function getPageAction(): array

class MyClass
{
    use Injection;

$this->auth     => Enicore\RavenApi\Auth;       // Auth service
$this->code     => Enicore\RavenApi\Code;       // Encoding and encryption
$this->db       => Enicore\RavenApi\Database;   // Database service
$this->request  => Enicore\RavenApi\Request;    // Request handling
$this->response => Enicore\RavenApi\Response;   // Response handling
$this->router   => Enicore\RavenApi\Router;     // Router service
$this->session  => Enicore\RavenApi\Session;    // Session management

class MyClass
{
    use Injection;
    
    public function __construct()
    {
        $this->injectDependencies();
    }
    
    public function __get(string $variable): string
    {
        return "something";
    }
}    

use Enicore\RavenApi\Database;
Database::instance()->getFirst("...");
index.php
APP_DIR

Controllers\DashboardController -> APP_DIR/controllers/DashboardController.php
Models\User -> APP_DIR/models/User.php 
$this->injectDependencies()