Files
BiveEngine/engine/Main/trait.datatypes.php
2025-12-24 19:19:01 +03:00

54 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// Работа с типами данных
defined('ROOT_DIR') || exit;
trait Datatypes {
public array $datatypes = array();
// Загрузка типов данных
public function datatype_load(): bool
{
$datatypes_dir = PLAYAREA_DIR_NAME . SLASH . "datatypes";
$datatypes = scandir($datatypes_dir, SCANDIR_SORT_DESCENDING);
if(!count($datatypes)) return false;
foreach ($datatypes as $key => $value) {
$name = $this->datatype_convert_name($value);
if(!$name) continue;
require_once $datatypes_dir . SLASH . $value;
$classes = get_declared_classes();
$class_name = end($classes);
$this->datatypes[] = $class_name;
}
return true;
}
private function datatype_convert_name($name): string
{
$parts = explode('.', $name);
if($parts[0] != "datatype" || !isset($parts[1])) return false;
return trim($parts[1]);
}
// Получить Объект по ID
public function get_item_by_id($item_id)
{
$search = new Search(array(
"limit" => 1,
"terms" => array("item_id" => $item_id)
));
$items = $search->collect();
if(!count($items)) return false;
list($item) = $items;
return $item;
}
// Получить Class объекта по ID
public function get_item_class_by_id($item_id)
{
$item = $this->get_item_by_id($item_id);
if($item === false) return false;
return $item->get_class_name();
}
}