PHP Classes

File: examples/case-studies/integration/laravel/autoload/laravel_autoload.php

Recommend this page to a friend!
  Classes of Christos Drogidis   Ascoos OS   examples/case-studies/integration/laravel/autoload/laravel_autoload.php   Download  
File: examples/case-studies/integration/laravel/autoload/laravel_autoload.php
Role: Example script
Content type: text/plain
Description: Laravel Integration in Ascoos OS
Class: Ascoos OS
A PHP Web 5.0 Kernel for decentralized web and IoT
Author: By
Last change:
Date: 3 months ago
Size: 4,952 bytes
 

Contents

Class file image Download
<?php
/**
 * @ASCOOS-NAME : Ascoos OS
 * @ASCOOS-VERSION : 26.0.0
 * @ASCOOS-SUPPORT : [email protected]
 * @ASCOOS-BUGS : https://issues.ascoos.com
 *
 * @CASE-STUDY : laravel_autoload.php
 * @fileNo : ASCOOS-OS-CASESTUDY-SEC00103
 *
 * @desc <English> Laravel Autoloader for Ascoos OS integration via LibIn.
 * @desc <Greek> Autoloader ??? Laravel ??? ?????????? ??? Ascoos OS ???? LibIn.
 *
 * @since PHP 8.2.0
 */
declare(strict_types=1);

use
ASCOOS\OS\Kernel\{
   
Arrays\Macros\TMacroHandler,
   
Arrays\Events\TEventHandler
};
use
Exception;

// <English> Loading via Ascoos OS autoloader
// <Greek> ??????? ???? Ascoos OS autoloader
global $conf, $AOS_LOGS_PATH, $AOS_LIBS_PATH;

// <English> Settings for logging, and events to manage logs, reports, and event triggers
// <Greek> ????????? ??? logging ??? ???????? ??? ?? ?????????? logs, ???????? ??? ???????? ?????????
$properties = [
   
'cache' => $conf['cache'],
   
'logs' => [
       
'useLogger' => true,
       
'dir' => $AOS_LOGS_PATH . '/',
       
'file' => 'laravel_loads.log'
   
]
];

// <English> Initialize Ascoos OS macro handler for Laravel tasks.
// <Greek> ???????????? ??? Ascoos OS macro handler ??? tasks ??? Laravel.
$macroHandler =& TMacroHandler::getInstance([], $properties);

// <English> Log event using Ascoos OS event handler.
// <Greek> ????????? ????????? ?? ??? Ascoos OS event handler.
$eventHandler =& TEventHandler::getInstance([], $properties);

try {
   
// <English> Define Laravel base path
    // <Greek> ??????? ??? ??????? ????????? ??? Laravel
   
define('LARAVEL_BASE_PATH', $AOS_LIBS_PATH . '/laravel');

   
// <English> If the Laravel vendors code autoload file does not exist
    // <Greek> ??? ?? ?????? ????????? ???????? ?????? ??? ??????????? Laravel ??? ???????
   
if (!file_exists(LARAVEL_BASE_PATH . '/vendor/autoload.php')) {
        throw new
Exception('Laravel vendor not found. Ensure archive is uploaded via LibIn.');
    }

   
// <English> Load Laravel vendor autoloader, included in the archive uploaded via LibIn.
    // <Greek> ??????? ??? Laravel vendor autoloader, ??? ?????????????? ??? archive ??? ??????? ???? LibIn.
   
require_once LARAVEL_BASE_PATH . '/vendor/autoload.php';

   
// <English> Bootstrap Laravel application
    // <Greek> ???????? ????????? Laravel
   
$laravel_app = require_once LARAVEL_BASE_PATH . '/bootstrap/app.php';

   
// <English> Optionally bind Laravel to global scope for mixed usage
    // <Greek> ???????? ??????????? ?? Laravel ??? ??????? ????? ??? ????? ?????
   
$GLOBALS['laravel_app'] = $laravel_app;

   
// <English> Initialize Ascoos OS macro handler for Laravel tasks.
    // <Greek> ???????????? ??? Ascoos OS macro handler ??? tasks ??? Laravel.
   
$macroHandler =& TMacroHandler::getInstance([], $properties);

   
// <English> Adds a macro with parameters, delay, and priority to the execution queue.
    // <Greek> ????????? ??? ??????????? ?? ???????????, ??????????? ??? ????????????? ???? ???? ?????????.
   
$macroHandler->addMacro(fn() => $laravel_app->make('log')->info('Laravel initialized with Ascoos OS'));

   
// <English> The result of the macro execution.
    // <Greek> ?? ?????????? ??? ????????? ??? ????????????.
   
$result = $macroHandler->runNext();

   
// <English> Log event using Ascoos OS event handler.
    // <Greek> ????????? ????????? ?? ??? Ascoos OS event handler.
   
$eventHandler =& TEventHandler::getInstance([], $properties);
   
$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');

   
// <English> You may also register Laravel services or facades here
    // <Greek> ???????? ?????? ?? ???????????? ??? ??? ????????? ? ?? facades ??? Laravel
} catch (Exception $e) {
   
error_log("Error: {$e->getMessage()}");
    echo
"Error: {$e->getMessage()}\n";
}

// <English> Resource cleanup and memory release.
// <Greek> ?????????? ????? ??? ???????????? ??????.
$macroHandler->Free($macroHandler);
$eventHandler->Free($eventHandler);
?>