All Projects → ujamii → openimmo

ujamii / openimmo

Licence: GPL-3.0 license
OpenImmo library

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to openimmo

xgen
XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator
Stars: ✭ 153 (+325%)
Mutual labels:  code-generator, xsd
xsdata
Naive XML & JSON Bindings for python
Stars: ✭ 144 (+300%)
Mutual labels:  code-generator, xsd
Speedment
Speedment is a Stream ORM Java Toolkit and Runtime
Stars: ✭ 1,978 (+5394.44%)
Mutual labels:  code-generator
Kyaml2go
K8s Go client code generator from Kubernetes resource yamls
Stars: ✭ 226 (+527.78%)
Mutual labels:  code-generator
Php To Zephir
Convert PHP to Zephir
Stars: ✭ 186 (+416.67%)
Mutual labels:  code-generator
Evolutility Ui Jquery
Model-driven Web UI for CRUD using REST or localStorage.
Stars: ✭ 164 (+355.56%)
Mutual labels:  code-generator
Dbtool
数据库工具,根据表结构文档生成创建表sql,根据数据库表信息导出Model和表结构文档,根据文档生成数据库表,根据已有Model文件生成创建数据库表sql
Stars: ✭ 206 (+472.22%)
Mutual labels:  code-generator
Xcassetpacker
A command line tool for converting a folder of images into an .xcasset package for Xcode
Stars: ✭ 150 (+316.67%)
Mutual labels:  code-generator
Sketchtoswift
📲 Generate Swift from Sketch
Stars: ✭ 251 (+597.22%)
Mutual labels:  code-generator
Drupal Code Generator
A code generator for Drupal.
Stars: ✭ 184 (+411.11%)
Mutual labels:  code-generator
Crud Intellij Plugin
一个增删改查的idea插件,可以根据数据库表结构,帮助您快速生成model、dao、service、controller等相关代码。同时支持MyBatis、JPA、MybatisPlus。
Stars: ✭ 217 (+502.78%)
Mutual labels:  code-generator
Yii2 Gii
Yii 2 Gii Extension
Stars: ✭ 183 (+408.33%)
Mutual labels:  code-generator
Jeecg
JEECG是一款基于代码生成器的J2EE快速开发平台,开源界“小普元”超越传统商业企业级开发平台。引领新的开发模式(Online Coding模式(自定义表单) - > 代码生成器模式 - > 手工MERGE智能开发), 可以帮助解决Java项目90%的重复工作,让开发更多关注业务逻辑。既能快速提高开发效率,帮助公司节省人力成本,同时又不失灵活性。具备:表单配置能力(无需编码)、移动配置能力、工作流配置能力、报表配置能力(支持移动端)、插件开发能力(可插拔)
Stars: ✭ 2,027 (+5530.56%)
Mutual labels:  code-generator
Kvf Admin
kvf-admin是一套基于springboot、mybatis、shiro及layui的轻量级快速开发框架、脚手架、后台管理系统、权限系统、基于activiti6整合的工作流OA系统,上手简单,拿来即用。
Stars: ✭ 209 (+480.56%)
Mutual labels:  code-generator
Jennifer
Jennifer is a code generator for Go
Stars: ✭ 2,257 (+6169.44%)
Mutual labels:  code-generator
Laracrud
Laravel Code Generator based on MySQL Database
Stars: ✭ 238 (+561.11%)
Mutual labels:  code-generator
Swiftcolorgen
A tool that generate code for Swift projects, designed to improve the maintainability of UIColors
Stars: ✭ 152 (+322.22%)
Mutual labels:  code-generator
Id Generator
生成带校验码的卡号、19位的Long ID、不大于22位的短UUID、短卡号、激活码、数字加密、付款码。分布式、基于内存、安全可靠、性能高。
Stars: ✭ 180 (+400%)
Mutual labels:  code-generator
Ng Swagger Gen
A Swagger 2.0 codegen for Angular
Stars: ✭ 196 (+444.44%)
Mutual labels:  code-generator
Xo
Command line tool to generate idiomatic Go code for SQL databases supporting PostgreSQL, MySQL, SQLite, Oracle, and Microsoft SQL Server
Stars: ✭ 2,974 (+8161.11%)
Mutual labels:  code-generator

OpenImmo PHP library

Packagist Minimum PHP Version Continuous Integration codecov Mutation testing badge

OpenImmo and the OpenImmo logo are registered trademarks of the OpenImmo e.V. Neither is this package an official distribution nor am I associated with this organisation!

This library just wraps the OpenImmo XML format with some PHP7/8 classes.

There is an official library available at http://www.openimmo.de/go.php/p/22/support20.htm which costs 95 EUR excl. VAT and is PHP5 only. To completely convince you, you will only be allowed to see the code after you have paid and they have a no-refund policy.

Important note

I am not allowed to include real world xml examples into this distribution package due to license restrictions. Thus, some tests are automatically skipped, if the xml files are not found in the examples directory! Do not be fooled by "Open" in OpenImmo ;-)

TODOs

  • add test cases, especially for the example file provided with the official download package.

Installation

composer req ujamii/openimmo

Integrations

If you like to use this API as base for an integration into a CMS or Framework, feel free to contact me, I will link it here.

Usage

Writing OpenImmo XML

// 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');

will produce

<nutzungsart WOHNEN="true" GEWERBE="false" ANLAGE="false" WAZ="false" />

Nested elements are created just as easy. Classes, properties, constants and parameters are named as corresponding items in the xsd file. They are just converted to camelCase to comply with PHP standards.

$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');

will generate

<infrastruktur>
	<ausblick blick="BERGE" />
	<distanzen distanz_zu="HAUPTSCHULE" >22.0</distanzen>
	<distanzen_sport distanz_zu_sport="SEE" >15.0</distanzen_sport>
	<zulieferung>false</zulieferung>
</infrastruktur>

Reading OpenImmo XML

Reading data from xml into a easy-to-use object structure is also pretty straightforward. This example will generate a list of objects (addresses).

$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(),
            ]);
    }
}

Writing JSON (since v0.10)

Although the OpenImmo standard just describes an XML version, there may be cases when you want to generate JSON from the given data. Sadly, there is an issue with custom types, scalar values and JSON serialization in the JMS serializer. Nevertheless it is still possible to write JSON format with the Symfony serializer component.

composer require symfony/serializer

Generating JSON then works like this:

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);

Possible issues

DateTime format not working

Some tools may generate DateTime values in the xml, which cause errors like

Fatal error: Uncaught JMS\Serializer\Exception\RuntimeException: Invalid datetime "2020-08-07T11:56:39.1242974+02:00", expected one of the format "Y-m-d\TH:i:sP", "Y-m-d\TH:i:s".

This can be caused by a different precision for the microsecond part (1242974) of this value. As the default PHP precision may be lower that the one of the tool, which the xml was generated with. If this problem occurs with the data you use, you can add a handler, included in this package, to the serializer like this:

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();

Update API classes with a new OpenImmo version

  1. Install composer package.
  2. Download OpenImmo files from their website (extract into the example folder). Their license agreement denies redistribution of the xsd file.
  3. php -f generate-api.php will fill the src/API directory with new classes.
  4. composer dumpautoload to update the autoloading.
  5. Done.

Running tests

  1. composer run phpunit

License and Contribution

GPLv3

As this is OpenSource, you are very welcome to contribute by reporting bugs, improve the code, write tests or whatever you are able to do to improve the project.

If you want to do me a favour, buy me something from my Amazon wishlist.

Thank you!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].