This commit is contained in:
cutemeli
2025-12-22 10:35:30 +00:00
parent 0bfc6c8425
commit 5ce7ca2c5d
38927 changed files with 0 additions and 4594700 deletions

View File

@@ -1,10 +0,0 @@
tools:
external_code_coverage:
timeout: 600
checks:
php:
code_rating: true
duplication: true
filter:
paths:
- src/*

View File

@@ -1,31 +0,0 @@
language: php
sudo: false
cache:
directories:
- vendor
- $HOME/.composer/cache
php:
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
matrix:
include:
- php: 7.1
dist: trusty
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable'
before_script:
- if [[ $TRAVIS_PHP_VERSION = '7.1' ]]; then PHPUNIT_FLAGS="--coverage-clover=coverage.clover"; else PHPUNIT_FLAGS=""; fi
- if [[ $TRAVIS_PHP_VERSION != '7.1' ]]; then phpenv config-rm xdebug.ini; fi
- composer self-update
- composer update $COMPOSER_FLAGS
script: vendor/phpunit/phpunit/phpunit $PHPUNIT_FLAGS
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- if [[ $TRAVIS_PHP_VERSION = '7.1' ]]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi

View File

@@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2016 Asmir Mustafic
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,17 +0,0 @@
# xsd2php-runtime
[![Build Status](https://travis-ci.org/goetas-webservices/xsd2php-runtime.svg?branch=master)](https://travis-ci.org/goetas-webservices/xsd2php-runtime)
[![Code Coverage](https://scrutinizer-ci.com/g/goetas-webservices/xsd2php-runtime/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/goetas-webservices/xsd2php-runtime/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/goetas-webservices/xsd2php-runtime/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/goetas-webservices/xsd2php-runtime/?branch=master)
Runtime libs for https://github.com/goetas-webservices/xsd2php
## Note
The code in this project is provided under the
[MIT](https://opensource.org/licenses/MIT) license.
For professional support
contact [goetas@gmail.com](mailto:goetas@gmail.com)
or visit [https://www.goetas.com](https://www.goetas.com)

View File

@@ -1,45 +0,0 @@
{
"name": "goetas-webservices/xsd2php-runtime",
"description": "Convert XSD (XML Schema) definitions into PHP classes",
"type": "library",
"authors": [
{
"name": "Asmir Mustafic"
}
],
"keywords": [
"converter",
"xml",
"xsd",
"php",
"jms",
"serializer"
],
"license": "MIT",
"require": {
"php": ">=7.1",
"jms/serializer": "^1.2|^2.0|^3.0",
"symfony/yaml": "^2.2|^3.0|^4.0|^5.0|^6.0|^7.0"
},
"conflict": {
"jms/serializer": "1.4.1|1.6.1|1.6.2"
},
"require-dev": {
"phpunit/phpunit": "^7.0|^8.0|^9.0"
},
"autoload": {
"psr-4": {
"GoetasWebservices\\Xsd\\XsdToPhpRuntime\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"GoetasWebservices\\Xsd\\XsdToPhpRuntime\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "0.2-dev"
}
}
}

View File

@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="true"
backupStaticAttributes="false"
bootstrap="./vendor/autoload.php"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="false"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false">
<testsuites>
<testsuite name="Goetas XSD to PHP Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -1,91 +0,0 @@
<?php
namespace GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler;
use JMS\Serializer\Context;
use JMS\Serializer\GraphNavigator;
use JMS\Serializer\Handler\SubscribingHandlerInterface;
use JMS\Serializer\XmlDeserializationVisitor;
use JMS\Serializer\XmlSerializationVisitor;
class BaseTypesHandler implements SubscribingHandlerInterface
{
/**
* @return array
*/
public static function getSubscribingMethods()
{
return array(
array(
'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
'format' => 'xml',
'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\SimpleListOf',
'method' => 'simpleListOfToXml'
),
array(
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
'format' => 'xml',
'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\SimpleListOf',
'method' => 'simpleListOfFromXML'
),
array(
'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
'format' => 'xml',
'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\Base64Encoded',
'method' => 'base64EncodedToXml'
),
array(
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
'format' => 'xml',
'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\Base64Encoded',
'method' => 'base64EncodedFromXml'
)
);
}
public function base64EncodedToXml(XmlSerializationVisitor $visitor, $data, array $type, Context $context)
{
return $visitor->visitSimpleString(base64_encode($data), $type, $context);
}
public function base64EncodedFromXml(XmlDeserializationVisitor $visitor, $data, array $type)
{
$attributes = $data->attributes('xsi', true);
if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') {
return null;
}
return base64_decode((string)$data);
}
public function simpleListOfToXml(XmlSerializationVisitor $visitor, $object, array $type, Context $context)
{
$newType = array(
'name' => $type["params"][0]["name"],
'params' => array()
);
$navigator = $context->getNavigator();
$ret = array();
foreach ($object as $v) {
$ret[] = $navigator->accept($v, $newType, $context)->data;
}
return $visitor->getDocument()->createTextNode(implode(" ", $ret));
}
public function simpleListOfFromXml(XmlDeserializationVisitor $visitor, $node, array $type, Context $context)
{
$newType = array(
'name' => $type["params"][0]["name"],
'params' => array()
);
$ret = array();
$navigator = $context->getNavigator();
foreach (explode(" ", (string)$node) as $v) {
$ret[] = $navigator->accept($v, $newType, $context);
}
return $ret;
}
}

View File

@@ -1,168 +0,0 @@
<?php
namespace GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler;
use JMS\Serializer\Context;
use JMS\Serializer\GraphNavigator;
use JMS\Serializer\Handler\SubscribingHandlerInterface;
use JMS\Serializer\XmlDeserializationVisitor;
use JMS\Serializer\XmlSerializationVisitor;
use RuntimeException;
class XmlSchemaDateHandler implements SubscribingHandlerInterface
{
protected $defaultTimezone;
/**
* @return array
*/
public static function getSubscribingMethods()
{
return array(
array(
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
'format' => 'xml',
'type' => 'GoetasWebservices\Xsd\XsdToPhp\XMLSchema\Date',
'method' => 'deserializeDate'
),
array(
'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
'format' => 'xml',
'type' => 'GoetasWebservices\Xsd\XsdToPhp\XMLSchema\Date',
'method' => 'serializeDate'
),
array(
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
'format' => 'xml',
'type' => 'GoetasWebservices\Xsd\XsdToPhp\XMLSchema\DateTime',
'method' => 'deserializeDateTime'
),
array(
'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
'format' => 'xml',
'type' => 'GoetasWebservices\Xsd\XsdToPhp\XMLSchema\DateTime',
'method' => 'serializeDateTime'
),
array(
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
'format' => 'xml',
'type' => 'GoetasWebservices\Xsd\XsdToPhp\XMLSchema\Time',
'method' => 'deserializeTime'
),
array(
'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
'format' => 'xml',
'type' => 'GoetasWebservices\Xsd\XsdToPhp\XMLSchema\Time',
'method' => 'serializeTime'
),
array(
'type' => 'DateInterval',
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
'format' => 'xml',
'method' => 'deserializeDateIntervalXml',
),
);
}
public function __construct($defaultTimezone = 'UTC')
{
$this->defaultTimezone = new \DateTimeZone($defaultTimezone);
}
public function deserializeDateIntervalXml(XmlDeserializationVisitor $visitor, $data, array $type){
$attributes = $data->attributes('xsi', true);
if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') {
return null;
}
return $this->createDateInterval((string)$data);
}
public function serializeDate(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context)
{
$v = $date->format('Y-m-d');
return $visitor->visitSimpleString($v, $type, $context);
}
public function deserializeDate(XmlDeserializationVisitor $visitor, $data, array $type)
{
$attributes = $data->attributes('xsi', true);
if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') {
return null;
}
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})(Z|([+-]\d{2}:\d{2}))?$/', $data)) {
throw new RuntimeException(sprintf('Invalid date "%s", expected valid XML Schema date string.', $data));
}
return $this->parseDateTime($data, $type);
}
public function serializeDateTime(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context)
{
$v = $date->format(\DateTime::W3C);
return $visitor->visitSimpleString($v, $type, $context);
}
public function deserializeDateTime(XmlDeserializationVisitor $visitor, $data, array $type)
{
$attributes = $data->attributes('xsi', true);
if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') {
return null;
}
return $this->parseDateTime($data, $type);
}
public function serializeTime(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context)
{
$v = $date->format('H:i:s');
if ($date->getTimezone()->getOffset($date) !== $this->defaultTimezone->getOffset($date)) {
$v .= $date->format('P');
}
return $visitor->visitSimpleString($v, $type, $context);
}
public function deserializeTime(XmlDeserializationVisitor $visitor, $data, array $type)
{
$attributes = $data->attributes('xsi', true);
if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') {
return null;
}
$data = (string)$data;
return new \DateTime($data, $this->defaultTimezone);
}
private function parseDateTime($data, array $type)
{
$timezone = isset($type['params'][1]) ? new \DateTimeZone($type['params'][1]) : $this->defaultTimezone;
$datetime = new \DateTime((string)$data, $timezone);
if (false === $datetime) {
throw new RuntimeException(sprintf('Invalid datetime "%s", expected valid XML Schema dateTime string.', $data));
}
return $datetime;
}
private function createDateInterval($interval){
$f = 0.0;
if (preg_match('~\.\d+~',$interval,$match)) {
$interval = str_replace($match[0], "", $interval);
$f = (float)$match[0];
}
$di = new \DateInterval($interval);
// milliseconds are only available from >=7.1
if(isset($di->f)){
$di->f= $f;
}
return $di;
}
}

View File

@@ -1,120 +0,0 @@
<?php
namespace GoetasWebservices\Xsd\XsdToPhpRuntime\Tests\Jms\Handler;
use Doctrine\Common\Annotations\AnnotationReader;
use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\XmlSchemaDateHandler;
use JMS\Serializer\Accessor\DefaultAccessorStrategy;
use JMS\Serializer\Construction\UnserializeObjectConstructor;
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\EventDispatcher\EventDispatcher;
use JMS\Serializer\GraphNavigator;
use JMS\Serializer\Handler\HandlerRegistry;
use JMS\Serializer\Metadata\Driver\AnnotationDriver;
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
use JMS\Serializer\XmlDeserializationVisitor;
use JMS\Serializer\XmlSerializationVisitor;
use Metadata\MetadataFactory;
use PHPUnit\Framework\TestCase;
class XmlSchemaDateHandlerDeserializationTest extends TestCase
{
/**
* @var XmlSchemaDateHandler
*/
protected $handler;
/**
* @var DeserializationContext
*/
protected $context;
/**
* @var XmlDeserializationVisitor
*/
protected $visitor;
public function setUp(): void
{
$this->handler = new XmlSchemaDateHandler();
$this->context = DeserializationContext::create();
$naming = new IdenticalPropertyNamingStrategy();
$dispatcher = new EventDispatcher();
$handlerRegistry= new HandlerRegistry();
$cons = new UnserializeObjectConstructor();
$navigator = class_exists('JMS\Serializer\GraphNavigator\DeserializationGraphNavigator')
? $this->initJmsv2($naming, $handlerRegistry, $cons, $dispatcher)
: $this->initJmsv1($naming, $handlerRegistry, $cons, $dispatcher)
;
$this->visitor->setNavigator($navigator);
}
private function initJmsv2($naming, $handlerRegistry, $cons, $dispatcher)
{
$accessor = new DefaultAccessorStrategy();
$this->visitor = new XmlDeserializationVisitor();
$metadataFactory = new MetadataFactory(new AnnotationDriver(new AnnotationReader(), $naming));
return new GraphNavigator\DeserializationGraphNavigator($metadataFactory, $handlerRegistry, $cons, $accessor, $dispatcher);
}
private function initJmsv1($naming, $handlerRegistry, $cons, $dispatcher)
{
$this->visitor = new XmlDeserializationVisitor($naming);
$metadataFactory = new MetadataFactory(new AnnotationDriver(new AnnotationReader()));
return new GraphNavigator($metadataFactory, $handlerRegistry, $cons, $dispatcher);
}
/**
* @dataProvider getDeserializeDate
* @param string $date
* @param \DateTime $expected
*/
public function testDeserializeDate($date, \DateTime $expected)
{
$element = new \SimpleXMLElement("<Date>$date</Date>");
$deserialized = $this->handler->deserializeDate($this->visitor, $element, [], $this->context);
$this->assertEquals($expected, $deserialized);
}
/**
* @dataProvider getDeserializeDateInterval
* @param string $dateInterval
* @param \DateTime $expected
*/
public function testDeserializeDateInterval($dateInterval, $expected)
{
$element = new \SimpleXMLElement("<DateInterval>$dateInterval</DateInterval>");
$deserialized = $this->handler->deserializeDateIntervalXml($this->visitor, $element, [], $this->context);
if (isset($deserialized->f)) {
$this->assertEquals($expected['f'], $deserialized->f);
}
$this->assertEquals($expected['s'], $deserialized->s);
}
public function getDeserializeDateInterval()
{
return [
['P0Y0M0DT3H5M7.520S', ['s' => 7, 'f' => 0.52]],
['P0Y0M0DT3H5M7S', ['s' => 7, 'f' => 0]]
];
}
public function getDeserializeDate()
{
return [
['2015-01-01', new \DateTime('2015-01-01')],
['2015-01-01Z', new \DateTime('2015-01-01', new \DateTimeZone("UTC"))],
['2015-01-01+06:00', new \DateTime('2015-01-01', new \DateTimeZone("+06:00"))],
['2015-01-01-20:00', new \DateTime('2015-01-01', new \DateTimeZone("-20:00"))],
];
}
public function testDeserializeInvalidDate()
{
$this->expectException(\RuntimeException::class);
$element = new \SimpleXMLElement("<Date>2015-01-01T</Date>");
$this->handler->deserializeDate($this->visitor, $element, [], $this->context);
}
}

View File

@@ -1,114 +0,0 @@
<?php
namespace GoetasWebservices\Xsd\XsdToPhpRuntime\Tests\Jms\Handler;
use Doctrine\Common\Annotations\AnnotationReader;
use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\XmlSchemaDateHandler;
use JMS\Serializer\Accessor\DefaultAccessorStrategy;
use JMS\Serializer\Construction\UnserializeObjectConstructor;
use JMS\Serializer\EventDispatcher\EventDispatcher;
use JMS\Serializer\GraphNavigator;
use JMS\Serializer\Handler\HandlerRegistry;
use JMS\Serializer\Metadata\Driver\AnnotationDriver;
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\XmlSerializationVisitor;
use Metadata\MetadataFactory;
use PHPUnit\Framework\TestCase;
class XmlSchemaDateHandlerSerializationTest extends TestCase
{
/**
* @var XmlSchemaDateHandler
*/
protected $handler;
/**
* @var SerializationContext
*/
protected $context;
/**
* @var XmlSerializationVisitor
*/
protected $visitor;
public function setUp(): void
{
$this->handler = new XmlSchemaDateHandler();
$this->context = SerializationContext::create();
$naming = new IdenticalPropertyNamingStrategy();
$cons = new UnserializeObjectConstructor();
$dispatcher = new EventDispatcher();
$handlerRegistry= new HandlerRegistry();
$navigator = class_exists('JMS\Serializer\GraphNavigator\DeserializationGraphNavigator')
? $this->initJmsv2($naming, $handlerRegistry, $cons, $dispatcher)
: $this->initJmsv1($naming, $handlerRegistry, $cons, $dispatcher)
;
$this->visitor->setNavigator($navigator);
}
private function initJmsv2($naming, $handlerRegistry, $cons, $dispatcher)
{
$accessor = new DefaultAccessorStrategy();
$this->visitor = new XmlSerializationVisitor();
$metadataFactory = new MetadataFactory(new AnnotationDriver(new AnnotationReader(), $naming));
return new GraphNavigator\SerializationGraphNavigator($metadataFactory, $handlerRegistry, $accessor, $dispatcher);
}
private function initJmsv1($naming, $handlerRegistry, $cons, $dispatcher)
{
$this->visitor = new XmlSerializationVisitor($naming);
$metadataFactory = new MetadataFactory(new AnnotationDriver(new AnnotationReader()));
return new GraphNavigator($metadataFactory, $handlerRegistry, $cons, $dispatcher);
}
/**
* @dataProvider getSerializeDateTime
* @param \DateTime $date
*/
public function testSerializeDateTime(\DateTime $date, $expected)
{
$ret = $this->handler->serializeDateTime($this->visitor, $date, [], $this->context);
$actual = $ret ? $ret->nodeValue : $this->visitor->getCurrentNode()->nodeValue;
$this->assertEquals($expected, $actual);
}
public function getSerializeDateTime()
{
return [
[new \DateTime('2015-01-01 12:00+00:00'), '2015-01-01T12:00:00+00:00'],
[new \DateTime('2015-01-01 12:00:56+00:00'), '2015-01-01T12:00:56+00:00'],
[new \DateTime('2015-01-01 12:00:56+00:00'), '2015-01-01T12:00:56+00:00'],
[new \DateTime('2015-01-01 12:00:56+20:00'), '2015-01-01T12:00:56+20:00'],
[new \DateTime('2015-01-01 12:00:56', new \DateTimeZone("Europe/London")), '2015-01-01T12:00:56+00:00'],
[new \DateTime('2015-01-01 12:00:56+00:00', new \DateTimeZone("Europe/London")), '2015-01-01T12:00:56+00:00'],
[new \DateTime('2015-01-01 12:00:56', new \DateTimeZone("Europe/Rome")), '2015-01-01T12:00:56+01:00'],
];
}
/**
* @dataProvider getSerializeDate
* @param \DateTime $date
* @param string $expected
*/
public function testSerializeDate(\DateTime $date, $expected)
{
$ret = $this->handler->serializeDate($this->visitor, $date, [], $this->context);
$actual = $ret ? $ret->nodeValue : $this->visitor->getCurrentNode()->nodeValue;
$this->assertEquals($expected, $actual);
}
public function getSerializeDate()
{
return [
[new \DateTime('2015-01-01 12:00'), '2015-01-01'],
[new \DateTime('2015-01-01 12:00:56'), '2015-01-01'],
[new \DateTime('2015-01-01 12:00:56+00:00'), '2015-01-01'],
[new \DateTime('2015-01-01 12:00:56+20:00'), '2015-01-01'],
[new \DateTime('2015-01-01 12:00:56', new \DateTimeZone("Europe/London")), '2015-01-01'],
];
}
}