PHP code example of innobraingmbh / onoffice-structure

1. Go to this page and download the library: Download innobraingmbh/onoffice-structure library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

innobraingmbh / onoffice-structure example snippets


use Innobrain\OnOfficeAdapter\Dtos\OnOfficeApiCredentials;
use Innobrain\Structure\Enums\FieldConfigurationModule;
use Innobrain\Structure\Enums\Language;
use Innobrain\Structure\Facades\Structure;

$credentials = new OnOfficeApiCredentials('your-token', 'your-secret');

// Fetch all modules (defaults to German labels)
$modules = Structure::forClient($credentials)->getModules();

// Fetch specific modules in a specific language
$modules = Structure::forClient($credentials)->getModules(
    only: [FieldConfigurationModule::Address->value, FieldConfigurationModule::Estate->value],
    language: Language::English,
);

// Iterate over modules and fields
foreach ($modules as $moduleKey => $module) {
    echo "Module: {$module->label} ({$module->key->value})\n";
    foreach ($module->fields as $fieldKey => $field) {
        echo "  Field: {$field->label} ({$field->key}) - Type: {$field->type->value}\n";
    }
}

$addressModule = $modules->get(FieldConfigurationModule::Address->value);

$filteredFields = $addressModule->fields
    ->whereMatchesFilters()
    ->where('Art', '2')       // only fields visible when Art = 2
    ->when($someCondition, fn ($builder) => $builder->where('ArtDaten', '1'))
    ->get();

$sanitized = $addressModule->fields->sanitize(collect([
    'Email' => '[email protected]',
    'unknownField' => 'value',      // removed: not in field collection
    'Beziehung' => '999',           // removed: not a permitted value
]));

use Innobrain\Structure\Converters\Array\ArrayConvertStrategy;

$strategy = new ArrayConvertStrategy(dropEmpty: true); // remove null/empty values

$allModulesArray = $modules->convert($strategy);
$moduleArray = $addressModule->convert($strategy);
$fieldArray = $addressModule->fields->get('Email')->convert($strategy);

use Innobrain\Structure\Converters\LaravelRules\LaravelRulesConvertStrategy;

// Pipe-separated strings with nullable (default)
$strategy = new LaravelRulesConvertStrategy(pipeSyntax: true, rtStrategy(pipeSyntax: false, iehung.*' => 'in:0,1,2,3'

use Innobrain\Structure\Converters\PrismSchema\PrismSchemaConvertStrategy;

$strategy = new PrismSchemaConvertStrategy(
    turns an ObjectSchema usable with Prism's structured output

use Innobrain\Structure\Converters\JsonSchema\JsonSchemaConvertStrategy;

$strategy = new JsonSchemaConvertStrategy(
    

use Innobrain\Structure\Converters\Concerns\BaseConvertStrategy;
use Innobrain\Structure\Dtos\Field;
use Innobrain\Structure\Dtos\Module;

final readonly class MyConvertStrategy extends BaseConvertStrategy
{
    public function convertModule(Module $module): mixed { /* ... */ }
    public function convertField(Field $field): mixed { /* ... */ }
}

$result = $module->convert(new MyConvertStrategy());
bash
php artisan vendor:publish --provider="Innobrain\Structure\StructureServiceProvider" --tag="onoffice-structure-config"