PHP code example of globus-studio / atomic-framework

1. Go to this page and download the library: Download globus-studio/atomic-framework 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/ */

    

globus-studio / atomic-framework example snippets


return \Engine\Atomic\Core\Bootstrap::boot();

// routes/web.php
$this->route('GET /dashboard', 'App\Http\Controllers\DashboardController->index');
$this->route('POST /contact', 'App\Http\Controllers\ContactController->submit', ['auth']);

// config/middleware.php
return [
    'auth'  => App\Http\Middleware\Authenticate::class,
    'admin' => App\Http\Middleware\RequireAdmin::class,
];

// routes/web.php
$this->route('GET /admin/*', 'AdminController->index', ['auth', 'admin']);

use Engine\Atomic\Core\Middleware\MiddlewareInterface;

class Authenticate implements MiddlewareInterface
{
    public function handle(\Base $atomic): bool
    {
        return Guard::is_authenticated();
    }

    public function process(mixed $request, callable $next): \Engine\Atomic\Http\Response
    {
        if (Guard::is_authenticated()) {
            return $next($request);
        }
        return \Engine\Atomic\Http\Response::json(['error' => 'Unauthorized'], 401);
    }
}

use Engine\Atomic\App\Controller;

class DashboardController extends Controller
{
    public function index(\Base $f3): void
    {
        $this->display('dashboard/index.html');
    }
}

use Engine\Atomic\App\Model;

class User extends Model
{
    protected $fieldConf = [
        'email'    => ['type' => \DB\SQL\Schema::DT_VARCHAR256, 'nullable' => false],
        'password' => ['type' => \DB\SQL\Schema::DT_VARCHAR256, 'nullable' => false],
    ];
}

use Engine\Atomic\Auth\Auth;
use Engine\Atomic\Auth\GoogleAuth;

// Password-based login
$user = Auth::instance()->login_with_secret(
    ['email' => $email],
    $password
);

// OAuth login
$url = GoogleAuth::instance()->get_login_url();
$userId = GoogleAuth::instance()->handle_callback($code, $state);

// Session management
$currentUser = Auth::instance()->get_current_user();
Auth::instance()->logout();
Auth::kill_all_sessions($userId);

// Admin impersonation
Auth::instance()->impersonate_user($targetUuid);
Auth::instance()->stop_impersonation();

// database/migrations/20260101000000_create_posts_table.php
return [
    'table' => 'posts',
    'columns' => [
        'id'    => ['type' => 'BIGINT UNSIGNED', 'auto_increment' => true],
        'title' => ['type' => 'VARCHAR', 'length' => 256, 'nullable' => false],
        'body'  => ['type' => 'TEXT', 'nullable' => true],
        'uuid'  => ['type' => 'VARCHAR', 'length' => 128, 'nullable' => false],
    ],
];

use Engine\Atomic\Queue\Managers\Manager;

Manager::instance()->push('email', [
    'to'      => '[email protected]',
    'subject' => 'Welcome',
]);

// routes/schedule.php
$scheduler->call(function () {
    Log::info('Cleanup executed');
})->daily()->at('03:00')->timezone('UTC');

// config/providers.php
return [
    'plugins' => [
        Engine\Atomic\Plugins\WebSockets\WebSockets::class,
        App\Plugins\ExamplePlugin\ExamplePlugin::class,
    ],
];

use Engine\Atomic\Event\Event;

Event::instance()->on('user.created', function ($data) {
    // Send welcome email
}, priority: 10);

Event::instance()->emit('user.created', ['user' => $user]);

use Engine\Atomic\Hook\Hook;

Hook::instance()->add_action('after_login', function ($user) {
    // Track login
});

$title = Hook::instance()->apply_filters('page_title', $rawTitle);

use Engine\Atomic\Tools\Transient;
use Engine\Atomic\Core\CacheManager;

// Transient storage (WordPress-like priority: Redis → Memcached → DB → Folder)
Transient::set('stats', $data, 3600);
$cached = Transient::get('stats');

// Cache cascade
$cache = CacheManager::instance()->cascade();
$cache->set('stats', $data, 3600);
$cache->clear('stats');

// Refresh cached generation in long-running workers
$cache->flush_local_cache();

use Engine\Atomic\Lang\I18n;

$i18n = I18n::instance();
echo $i18n->t('welcome_message');                // Simple translation
echo $i18n->tn('item', 'items', $count);         // Pluralization
echo $i18n->tx('menu', 'navigation');            // Contextual translation
echo $i18n->url('/about', 'fr');                 // Localized URL: /fr/about
bash
php atomic migrations/create create_posts_table
php atomic migrations/migrate
php atomic migrations/rollback
php atomic migrations/status
bash
php atomic queue/worker         # Start worker
php atomic queue/monitor        # View queue status
php atomic queue/retry          # Retry failed jobs
bash
php atomic schedule/run          # Execute due tasks
php atomic schedule/work         # Continuous scheduler loop
php atomic schedule/list         # List scheduled tasks

plugins/
`-- ExamplePlugin/
    |-- ExamplePlugin.php
    |-- composer.json
    |-- vendor/autoload.php
    `-- routes/
        `-- api.php
bash
php atomic plugin/make ExamplePlugin
php atomic plugin/deps install