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


// public/index.php

define('ATOMIC_START', true);

// config/database.php
return [
    'default'     => 'mysql',
    'connections' => [
        'mysql' => [
            'driver'   => 'mysql',
            'host'     => '127.0.0.1',
            'database' => 'atomic',
            'username' => 'root',
            'password' => '',
            'charset'  => 'utf8mb4',
        ],
    ],
];

$application = App::instance($atomic);

\App\Event\Application::instance()->init();
\App\Hook\Application::instance()->init();

$application
    ->config_loaded($loader)
    ->register_logger()            // Initialize structured logging
    ->register_exception_handler()
    ->prefly()                     // Verify PHP version, extensions, directory permissions
    ->register_locales()           // Set up i18n
    ->register_locale_hrefs()      // Normalize prefixed locale path before route detection
    ->register_unload_handler()
    ->register_middleware()        // Load middleware aliases
    ->register_core_plugins()      // Register framework plugin providers
    ->register_plugins()           // Activate registered plugins
    ->register_routes()            // Load app and plugin route files by request type
    ->init_session()               // Start session (lazy: only if cookie exists)
    ->open_connections()           // Opens redis, memcached and db connections
    ->register_user_provider()     // Wire authentication backend
    ->app_bootstrapped();

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

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

// Usage with parameters
$middleware->for_route('/admin/*', ['auth', 'admin']);
$middleware->for_route('/store/*', ['store:banned']);  // Parameterized: Store('banned')

use Engine\Atomic\Core\Middleware\MiddlewareInterface;

class Authenticate implements MiddlewareInterface
{
    public function handle(\Base $atomic): bool
    {
        // Return true to continue, false to abort
        return Guard::is_authenticated();
    }
}

return [
    'plugins' => [
        Engine\Atomic\Plugins\WebSockets\WebSockets::class,
        App\Plugins\ExamplePlugin\ExamplePlugin::class,
    ],
];

use Engine\Atomic\App\Plugin;

final class ExamplePlugin extends Plugin
{
    protected function get_name(): string
    {
        return 'ExamplePlugin';
    }

    public function  ],
            ],
        ];
    }
}

use Engine\Atomic\App\Controller;

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

use Engine\Atomic\App\Model;

class User extends Model
{
    protected function get_rules(): array
    {
        return [
            'email'    => ['rule' => Rule::EMAIL, '
}

use Engine\Atomic\Auth\Auth;

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

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

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

// Auth throttling: use RateLimit middleware or app-specific policies.

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

use Engine\Atomic\Queue\Managers\Manager;

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

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

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;

// Store a value with TTL
Transient::set('stats', $data, 3600);
$cached = Transient::get('stats');

// Cache cascade: honors CACHE_CONFIG and falls back through Redis → Memcached → Folder
$cache = CacheManager::instance()->cascade();
$cache->set('stats', $data, 3600);
$cache->clear('stats');

// Long-running workers can refresh the cached generation after an external reset.
$cache->flush_local_cache();

// Transients use WordPress-like priority:
// Redis → Memcached → DB → Folder

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 init
php atomic init/key
text
plugins/
`-- ExamplePlugin/
    |-- ExamplePlugin.php
    |-- composer.json
    |-- vendor/autoload.php
    `-- routes/
        `-- api.php
bash
php atomic plugin/make ExamplePlugin
bash
php atomic plugin/deps install
php atomic plugin/deps install ExamplePlugin
bash
# Create a migration
php atomic migrations/create create_posts_table

# Run pending migrations
php atomic migrations/migrate

# Rollback last batch
php atomic migrations/rollback

# Check status
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