<?php
/*
dobu {
file:id(`example-00000100`),name(`laravelAutoload`) {
ascoos {
logo {`
__ _ ___ ___ ___ ___ ___ ___ ___
/ _' |/ / / __/ _ \ / _ \ / / / _ \ / /
| (_| |\ \| (_| (_) | (_) |\ \ | (_) |\ \
\__,_|/__/ \___\___/ \___/ /__/ \___/ /__/
`},
name {`ASCOOS OS`},
version {`1.0.0`},
category {`Web OS`},
subcategory {`Web5 / WebAI`},
description {`A Web 5.0 and Web AI Kernel for decentralized web and IoT applications`},
creator {`Drogidis Christos`},
website {`https://www.ascoos.com`},
issues {`https://support.ascoos.com`},
support {`support@ascoos.com`},
license {`[Commercial] http://docs.ascoos.com/lics/ascoos/AGL.html`},
copyright {`Copyright (c) 2007 - 2026, AlexSoft Software.`},
},
example {
case-study {`SEC00100`},
source {`libs/laravel/autoload.php`},
category:langs {
en {`Framework Integration`},
el {`?????????? Framework`}
},
subcategory:langs {
en {`Laravel Autoloading & Kernel Bootstrapping`},
el {`??????? Laravel & ???????? Kernel`}
},
summary:langs {
en {`Autoloading, bootstrapping and diagnostic integration of Laravel inside Ascoos OS Web5 Kernel.`},
el {`???????, ???????? ??? ??????????? ?????????? ??? Laravel ???? ??? Ascoos OS Web5 Kernel.`}
},
desc:langs {
en {`This example demonstrates the advanced integration of the Laravel framework into Ascoos OS using the LibIn autoloader.
It initializes the framework, binds the application globally, executes diagnostic macros, validates core services,
tests database connectivity, and emits structured events through TMacroHandler and TEventHandler.
The implementation ensures seamless coexistence between Laravel and the Web5 Kernel, enabling mixed usage scenarios
and unified logging across both environments.
`},
el {`?? ?????????? ??????????? ??? ??????????? ?????????? ??? Laravel ??? Ascoos OS ???? ??? LibIn autoloader.
??????????? ?? framework, ?? ???????? ??? global scope, ??????? ??????????? macros,
?????????? ??????? ?????????, ????????? ?? ??????? ??? ???? ????????? ??? ???????? ???????? ????????
???? ??? TMacroHandler ??? TEventHandler.
? ????????? ??????????? ????? ????????? ??? Laravel ?? ?? Web5 Kernel, ???????????? ????? ?????
??? ??????????? logging ??? ??? ??? ????????????.
`}
},
keywords:langs {
en {`Laravel, Ascoos OS, Web5 Kernel, LibIn, autoload, macros, events, diagnostics, integration`},
el {`Laravel, Ascoos OS, Web5 Kernel, LibIn, autoload, macros, events, diagnostics, ??????????`}
},
created {`2025-10-20 07:00:00`},
updated {`2026-05-22 14:27:00`}
author {`Christos Drogidis`},
since {`1.0.0`},
sincePHP {`8.4.0`}
}
}
}
*/
declare(strict_types=1);
use ASCOOS\OS\Kernel\{
Core\TError,
Arrays\Macros\TMacroHandler,
Arrays\Events\TEventHandler
};
// <EN> Loading via Ascoos OS autoloader
// <EL> ??????? ???? Ascoos OS autoloader
global $conf, $AOS_LOGS_PATH, $AOS_LIBS_PATH;
// <EN> Settings for logging and events to manage logs, reports, and event triggers
// <EL> ????????? ??? logging ??? ???????? ??? ?? ?????????? logs, ???????? ??? ???????? ?????????
$properties = [
'cache' => $conf['cache'],
'logs' => [
'useLogger' => true,
'dir' => $AOS_LOGS_PATH . '/',
'file' => 'laravel_loads.log'
]
];
// <EN> Initialize Ascoos OS macro handler for Laravel tasks
// <EL> ???????????? ??? Ascoos OS macro handler ??? tasks ??? Laravel
$macroHandler =& TMacroHandler::getInstance([], $properties);
// <EN> Initialize Ascoos OS event handler for logging
// <EL> ???????????? ??? Ascoos OS event handler ??? logging
$eventHandler =& TEventHandler::getInstance([], $properties);
try {
// <EN> Define Laravel base path
// <EL> ??????? ??? ??????? ????????? ??? Laravel
define('LARAVEL_BASE_PATH', $AOS_LIBS_PATH . '/laravel');
// <EN> If the Laravel vendors code autoload file does not exist
// <EL> ??? ?? ?????? ????????? ???????? ?????? ??? ??????????? Laravel ??? ???????
if (!file_exists(LARAVEL_BASE_PATH . '/vendor/autoload.php')) {
new TError('Laravel vendor not found. Ensure archive is uploaded via LibIn.');
}
// <EN> Load Laravel vendor autoloader, included in the archive uploaded via LibIn
// <EL> ??????? ??? Laravel vendor autoloader, ??? ?????????????? ??? archive ??? ??????? ???? LibIn
require_once LARAVEL_BASE_PATH . '/vendor/autoload.php';
// <EN> Bootstrap Laravel application
// <EL> ???????? ????????? Laravel
$laravel_app = require_once LARAVEL_BASE_PATH . '/bootstrap/app.php';
// <EN> Optionally bind Laravel to global scope for mixed usage
// <EL> ??????????? ???????? ??? ????????? Laravel ??? global scope ??? ????? ?????
$GLOBALS['laravel_app'] = $laravel_app;
// <EN> Log successful initialization using Laravel logger
// <EL> ????????? ????????? ????????????? ??????????????? ?? logger ??? Laravel
$macroHandler->addMacro(fn() => $laravel_app->make('log')->info('Laravel initialized with Ascoos OS'));
// <EN> Diagnostic macro to check core services and DB connection
// <EL> ??????????? macro ??? ?????? ??????? ????????? ??? ???????? DB
$macroHandler->addMacro(function () use ($laravel_app, $eventHandler) {
global $utf8;
try {
// <EN> Verify Laravel app instance
// <EL> ?????????? instance ??? Laravel app
if (!($laravel_app instanceof \Illuminate\Contracts\Foundation\Application)) {
new TError('Laravel app is not a valid instance of \Illuminate\Contracts\Foundation\Application');
}
// <EN> Check core services
// <EL> ??????? ??????? ?????????
$services = ['log', 'auth', 'db', 'router'];
$missing = [];
foreach ($services as $service) {
if (!$laravel_app->bound($service)) {
$missing[] = $service;
}
}
if (empty($missing)) {
$eventHandler->logger->log("Laravel diagnostic passed: all core services are available", $eventHandler::DEBUG_LEVEL_INFO);
$laravel_app->make('log')->info('Laravel diagnostic passed: all core services available');
} else {
$eventHandler->logger->log("Laravel diagnostic warning: missing services ? " . $utf8->implode(', ', $missing), $eventHandler::DEBUG_LEVEL_WARNING);
$laravel_app->make('log')->warning('Laravel diagnostic warning: missing services ? ' . $utf8->implode(', ', $missing));
}
// <EN> Test DB connection if configured
// <EL> ?????? ???????? DB ?? ???? ?????????
if ($laravel_app->bound('db')) {
$laravel_app->make('db')->connection()->getPdo();
$eventHandler->logger->log("Laravel DB connection test successful", $eventHandler::DEBUG_LEVEL_INFO);
$laravel_app->make('log')->info('Laravel DB connection test successful');
}
} catch (Exception $e) {
// <EN> Log diagnostic failure
// <EL> ????????? ????????? ???????????? ???????
$eventHandler->logger->log("Laravel diagnostic failed: " . $e->getMessage(), $eventHandler::DEBUG_LEVEL_ERROR);
$laravel_app->make('log')->error('Laravel diagnostic failed: ' . $e->getMessage());
}
});
// <EN> Execute all macros in queue
// <EL> ???????? ???? ??? ???????????? ???? ????
$macroHandler->runAll();
// <EN> Register and trigger Laravel integration event
// <EL> ?????????? ??? ???????????? ????????? ??????????? Laravel
$eventHandler->setTargets(['laravel_init']);
$eventHandler->register('laravel_init', 'framework', fn() =>
$eventHandler->logger->log("Laravel integration successful at " . date('Y-m-d H:i:s'), $eventHandler::DEBUG_LEVEL_INFO)
);
$eventHandler->trigger('laravel_init', 'framework');
// <EN> You may also register Laravel services or facades here
// <EL> ???????? ?????? ?? ???????????? ??? ??? ????????? ? ?? facades ??? Laravel
} catch (Exception $e) {
// <EN> Handle and log the exception
// <EL> ?????????? ??? ????????? ??? ?????????
$macroHandler->Free();
$eventHandler->Free();
new TError("Error: {$e->getMessage()}");
}
// <EN> Resource cleanup and memory release
// <EL> ?????????? ????? ??? ???????????? ??????
$macroHandler->Free();
$eventHandler->Free();
?>
|