[SOLVED] Importing exported classes (json) by php code to deployment


#1

hello all,
i have to create my own classes on plugin initialization.
i export my own classes to json files and i want to import them by php code. is it possible??
any suggestion to create a classes by php code plugin initialization?


#2

function createClass($pClassName,$pFilePath)
{
$class = \Pimcore\Model\Object\ClassDefinition::getByName($pClassName);
if (!$class) {
$class = new \Pimcore\Model\Object\ClassDefinition();
$class->setName($pClassName);
}

    $json = file_get_contents($pFilePath);
    $success = \Pimcore\Model\Object\ClassDefinition\Service::importClassDefinitionFromJson($class, $json);
    if (!$success) {
    return false;
    }
    return true;
}