PHP Classes

File: examples/kernel/core/TObject/Properties.php

Recommend this page to a friend!
  Packages of Christos Drogidis   Ascoos OS   examples/kernel/core/TObject/Properties.php   Download  
File: examples/kernel/core/TObject/Properties.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Ascoos OS
A PHP Web 5.0 Kernel for decentralized web and IoT
Author: By
Last change: Update of examples/kernel/core/TObject/Properties.php
Date: 8 months ago
Size: 2,809 bytes
 

Contents

Class file image Download
<?php
/**
 * @ASCOOS-NAME : Ascoos OS
 * @ASCOOS-VERSION : 26.0.0
 * @ASCOOS-SUPPORT : support@ascoos.com
 * @ASCOOS-BUGS : https://issues.ascoos.com
 *
 * @desc <English> Demonstrates the initialization of a TObject instance, setting and retrieving properties, and converting the object to a string.
 * @desc <Greek> ??????????? ??? ???????????? ???? instance ??? TObject, ??? ???????? ??? ???????? ?????????, ??? ?? ????????? ??? ???????????? ?? ????????????.
 *
 * @since PHP 8.2.0
 */

use ASCOOS\OS\Kernel\Core\TObject;

// <English> Declare global AOS_LOGS_PATH for log directory
// <Greek> ??????? ?? global ????????? AOS_LOGS_PATH ??? ??? ???????? ??????????
global $AOS_LOGS_PATH;

// <English> Initialize properties array with configuration
// <Greek> ???????????? ?????? ????????? ?? ??????????
$properties = [
   
'name' => 'TestObject',
   
'version' => 260000,
   
'logs' => [
       
'dir' => $AOS_LOGS_PATH . '/',
       
'file' => 'test.log'
   
]
];

// <English> Create a new TObject instance with properties
// <Greek> ?????????? ???? instance ??? TObject ?? ?????????
$object = new TObject($properties);

// <English> Convert object to string using __toString
// <Greek> ????????? ??? ???????????? ?? ???????????? ?? ?? __toString
echo $object->__toString(); // Outputs: TObject

// <English> Set a single property
// <Greek> ???????? ???? ??????????? ?????????
$object->setProperty('author', 'Lead Developer');

// <English> Retrieve a single property
// <Greek> ???????? ???? ??????????? ?????????
$author = $object->getProperty('author');
// <English> Output the retrieved property
// <Greek> ???????? ??? ??????????? ?????????
echo $author; // Outputs: Lead Developer

// <English> Set multiple properties
// <Greek> ???????? ????????? ?????????
$object->setProperties(['config' => ['host' => 'localhost', 'port' => 3306]]);

// <English> Retrieve all properties
// <Greek> ???????? ???? ??? ?????????
$allProperties = $object->getProperties();
// <English> Output all properties
// <Greek> ???????? ???? ??? ?????????
print_r($allProperties); // Outputs: ['name' => 'TestObject', 'version' => 260000, 'logs' => [...], 'author' => 'Lead Developer', 'config' => [...]]

// <English> Free resources
// <Greek> ???????????? ?????
$object->Free($object);
?>