PHP code example of equites / core

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

    

equites / core example snippets


$router = Core\Router::getInstance();
$router->loadRoutes('config/structure.xml');
$router->setNameSpace('Controllers');
$router->run();

use Core\\Controller;

class Users extends Controller\\Json
{
    public function GET()
    {
        // Will be encoded to {"ok":true,"time":1699999999}
        return ['ok' => true, 'time' => time()];
    }

    public function POST()
    {
        // You can also return a pre-encoded string if you need custom options
        return json_encode(['ok' => true], JSON_PRETTY_PRINT);
    }
}


// app/backend/config/config.php
return [
    'db' => [
        'dsn' => 'mysql:host=localhost;dbname=app',
        'user' => 'app',
        'pass' => 'secret',
    ],
    'env' => 'dev',
];


$config = new stdClass();
$config->env = 'prod';
$config->featureFlag = true;
return $config;

use Core\Config;

$cfg = Config::getAll();
$dsn = Config::getKey('db')['dsn']; // when using array format
$env = Config::getKey('env');

return [
  'db' => [
    // Option A: full DSN
    'dsn' => 'mysql:host=localhost;dbname=app;charset=utf8mb4',
    'user' => 'app',
    'pass' => 'secret',
    'options' => [\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC],
  ],
];

$config = new stdClass();
$config->db = (object) [
  // Option B: host/db parts
  'host' => 'localhost',
  'db' => 'app',
  'user' => 'app',
  'pass' => 'secret',
  'port' => 3306,
  'charset' => 'utf8mb4',
];
return $config;

use Core\\DB;

$pdo = DB::get();
$stmt = $pdo->prepare('SELECT * FROM users WHERE id = :id');
$stmt->execute(['id' => 1]);
$row = $stmt->fetch();

use Core\\Vault;

$vault = Vault::getInstance();
$vault->set('userId', 123);
$vault->set('traceId', bin2hex(random_bytes(8)));

// Later in the same request
$userId = $vault->get('userId');        // 123
$vault->unset('traceId');               // remove single key

// Optionally clear everything at end of request
$vault->clear();

<root>
    <api>
        <login/>
        <users child-ns="Users" params="userId">
            <settings/>
        </users>
    </api>
</root>