PHP code example of david-solus / reo-openimmo

1. Go to this page and download the library: Download david-solus/reo-openimmo 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/ */

    

david-solus / reo-openimmo example snippets


// just create the elements you need in your xml and use the set-methods to fill in values.
$nutzungsart = new Nutzungsart();
$nutzungsart
    ->setWohnen(true)
    ->setGewerbe(false)
    ->setAnlage(false)
    ->setWaz(false);

$serializer = \JMS\Serializer\SerializerBuilder::create()->build();
echo $serializer->serialize($nutzungsart, 'xml');

$infrastrktur = new Infrastruktur();
$infrastrktur
    ->setZulieferung(false)
    ->setAusblick((new Ausblick())->setBlick(Ausblick::BLICK_BERGE))
    ->setDistanzenSport([
        new DistanzenSport(DistanzenSport::DISTANZ_ZU_SPORT_SEE, 15)
    ])
    ->setDistanzen([
        new Distanzen(Distanzen::DISTANZ_ZU_HAUPTSCHULE, 22)
    ]);
    
$serializer = \JMS\Serializer\SerializerBuilder::create()->build();
echo $serializer->serialize($infrastrktur, 'xml');

$xmlString = file_get_contents('./example/foobar.xml');
/* @var $openImmo \Ujamii\OpenImmo\API\Openimmo */
$openImmo = $serializer->deserialize($xmlString, \Ujamii\OpenImmo\API\Openimmo::class, 'xml');

/* @var $anbieter \Ujamii\OpenImmo\API\Anbieter */
foreach ($openImmo->getAnbieter() as $anbieter) {
    /* @var $immobilie \Ujamii\OpenImmo\API\Immobilie */
    foreach ($anbieter->getImmobilie() as $immobilie) {
        echo PHP_EOL . vsprintf('%s %s, %s %s', [
                $immobilie->getGeo()->getStrasse(),
                $immobilie->getGeo()->getHausnummer(),
                $immobilie->getGeo()->getPlz(),
                $immobilie->getGeo()->getOrt(),
            ]);
    }
}

use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
use Symfony\Component\Serializer\Serializer;

$openImmoObject = null; // this may be any object of one of the API classes from this package
$encoders    = [new JsonEncoder()];
$normalizers = [
    new DateTimeNormalizer(),
    new GetSetMethodNormalizer()
];
$serializerContext = [
    AbstractObjectNormalizer::SKIP_NULL_VALUES       => true,
    AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => false,
    'json_encode_options'                            => \JSON_PRESERVE_ZERO_FRACTION
];

$serializer = new Serializer($normalizers, $encoders);
$jsonContent = $this->serializer->serialize($openImmoObject, JsonEncoder::FORMAT, $serializerContext);

use JMS\Serializer\Handler\HandlerRegistryInterface;
use Ujamii\OpenImmo\Handler\DateTimeHandler;

$builder = \JMS\Serializer\SerializerBuilder::create();
$builder
    ->configureHandlers(function(HandlerRegistryInterface $registry) {
        $registry->registerSubscribingHandler(new DateTimeHandler());
    })
;
$serializer = $builder->build();
xml
<nutzungsart WOHNEN="true" GEWERBE="false" ANLAGE="false" WAZ="false" />