Skip to content

Commit ce0307c

Browse files
committed
Merge branch 'release/1.0.0'
2 parents 6eec50f + f61a868 commit ce0307c

29 files changed

+8435
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.idea
2+
vendor/
3+
composer.lock
4+
composer.phar
5+
phpunit.xml
6+
wsdltophp.yml
7+
bin/
8+
tests/resources/generated

.php_cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude('vendor')
5+
->in(__DIR__);
6+
7+
return PhpCsFixer\Config::create()
8+
->setUsingCache(false)
9+
->setRules(array(
10+
'@PSR2' => true,
11+
'binary_operator_spaces' => true,
12+
'no_whitespace_in_blank_line' => true,
13+
'ternary_operator_spaces' => true,
14+
'cast_spaces' => true,
15+
'trailing_comma_in_multiline_array' => true
16+
))
17+
->setFinder($finder);

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
language: php
2+
3+
sudo: false
4+
5+
php:
6+
- 5.3
7+
- 5.4
8+
- 5.5
9+
- 5.6
10+
- 7.0
11+
- 7.1
12+
13+
before_install:
14+
- composer self-update
15+
16+
install:
17+
- composer install
18+
19+
script:
20+
- ./vendor/phpunit/phpunit/phpunit --coverage-text --coverage-clover=coverage.clover
21+
22+
after_script:
23+
- wget https://scrutinizer-ci.com/ocular.phar
24+
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# CHANGELOG
2+
3+
## 1.0.0
4+
- Initial release after exporting source code from the [PackageGenerator](https://github.com/WsdlToPhp/PackageGenerator) project

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2012-2017 Mikaël DELSOL
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# WsdlToPhp Package Generator
2+
[![License](https://poser.pugx.org/wsdltophp/domhandler/license)](https://packagist.org/packages/wsdltophp/domhandler)
3+
[![Latest Stable Version](https://poser.pugx.org/wsdltophp/domhandler/version.png)](https://packagist.org/packages/wsdltophp/domhandler)
4+
[![Build Status](https://travis-ci.org/WsdlToPhp/DomHandler.svg)](https://travis-ci.org/WsdlToPhp/DomHandler)
5+
[![PHP 7 ready](http://php7ready.timesplinter.ch/WsdlToPhp/DomHandler/badge.svg)](https://travis-ci.org/WsdlToPhp/DomHandler)
6+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/WsdlToPhp/DomHandler/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/WsdlToPhp/DomHandler/?branch=develop)
7+
[![Code Coverage](https://scrutinizer-ci.com/g/WsdlToPhp/DomHandler/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/WsdlToPhp/DomHandler/?branch=develop)
8+
[![StyleCI](https://styleci.io/repos/87977980/shield)](https://styleci.io/repos/87977980)
9+
10+
DomHandler uses the [decorator design pattern](https://en.wikipedia.org/wiki/Decorator_pattern) in order to ease DOM handling.
11+
12+
The source code has been originally created into the [PackageGenerator](https://github.com/WsdlToPhp/PackageGenerator) project but it felt that it had the possibility to live by itself and to evolve independtly from the PackageGenerator project if necessary.

composer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "wsdltophp/domhandler",
3+
"description": "Decorative design pattern to ease DOM handling",
4+
"type": "library",
5+
"keywords" : ["xml","dom","xpath","php"],
6+
"homepage" : "https://github.com/WsdlToPhp/DomHandler",
7+
"license" : "MIT",
8+
"authors" : [
9+
{
10+
"name": "Mikaël DELSOL",
11+
"email": "[email protected]",
12+
"homepage": "https://www.wsdltophp.com",
13+
"role": "Owner"
14+
}
15+
],
16+
"support" : {
17+
"email" : "[email protected]"
18+
},
19+
"require": {
20+
"php" : ">=5.3.3"
21+
},
22+
"require-dev": {
23+
"phpunit/phpunit": "~4.8",
24+
"friendsofphp/php-cs-fixer": "~2.0"
25+
},
26+
"autoload": {
27+
"psr-4": {
28+
"WsdlToPhp\\DomHandler\\": "src",
29+
"WsdlToPhp\\DomHandler\\Tests\\": "tests"
30+
}
31+
}
32+
}

phpunit.xml.dist

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
5+
backupGlobals="false"
6+
colors="true"
7+
bootstrap="vendor/autoload.php">
8+
<php>
9+
<ini name="error_reporting" value="-1" />
10+
</php>
11+
<testsuites>
12+
<testsuite name="full">
13+
<directory>./tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
17+
<filter>
18+
<whitelist>
19+
<directory>./</directory>
20+
<exclude>
21+
<directory>./tests</directory>
22+
<directory>./vendor</directory>
23+
</exclude>
24+
</whitelist>
25+
</filter>
26+
</phpunit>

src/AbstractAttributeHandler.php

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
3+
namespace WsdlToPhp\DomHandler;
4+
5+
class AbstractAttributeHandler extends AbstractNodeHandler
6+
{
7+
/**
8+
* @var string
9+
*/
10+
const DEFAULT_VALUE_TYPE = 'string';
11+
/**
12+
* @var string
13+
*/
14+
const ATTRIBUTE_NAMESPACE = 'namespace';
15+
/**
16+
* @var string
17+
*/
18+
const ATTRIBUTE_NAME = 'name';
19+
/**
20+
* @var string
21+
*/
22+
const ATTRIBUTE_REF = 'ref';
23+
/**
24+
* @var string
25+
*/
26+
const ATTRIBUTE_VALUE = 'value';
27+
/**
28+
* @var string
29+
*/
30+
const ATTRIBUTE_TYPE = 'type';
31+
/**
32+
* @var string
33+
*/
34+
const ATTRIBUTE_ABSTRACT = 'abstract';
35+
/**
36+
* @var string
37+
*/
38+
const ATTRIBUTE_MAX_OCCURS = 'maxOccurs';
39+
/**
40+
* @var string
41+
*/
42+
const ATTRIBUTE_MIN_OCCURS = 'minOccurs';
43+
/**
44+
* @var string
45+
*/
46+
const ATTRIBUTE_NILLABLE = 'nillable';
47+
/**
48+
* @var string
49+
*/
50+
const VALUE_UNBOUNDED = 'unbounded';
51+
/**
52+
* @var string
53+
*/
54+
const DEFAULT_OCCURENCE_VALUE = 1;
55+
/**
56+
* @see \WsdlToPhp\DomHandler\AbstractNodeHandler::getNode()
57+
* @return \DOMAttr
58+
*/
59+
public function getNode()
60+
{
61+
return parent::getNode();
62+
}
63+
/**
64+
* @return \DOMAttr
65+
*/
66+
public function getAttribute()
67+
{
68+
return $this->getNode();
69+
}
70+
/**
71+
* Tries to get attribute type on the same node
72+
* in order to return the value of the attribute in its type
73+
* @return string|null
74+
*/
75+
public function getType()
76+
{
77+
$type = null;
78+
if (($parent = $this->getParent()) instanceof ElementHandler && $parent->hasAttribute(self::ATTRIBUTE_TYPE)) {
79+
$type = $parent->getAttribute(self::ATTRIBUTE_TYPE)->getValue(false, false);
80+
}
81+
return $type;
82+
}
83+
/**
84+
* @param bool $withNamespace
85+
* @param bool $withinItsType
86+
* @param string $asType
87+
* @return mixed
88+
*/
89+
public function getValue($withNamespace = false, $withinItsType = true, $asType = self::DEFAULT_VALUE_TYPE)
90+
{
91+
$value = $this->getAttribute()->value;
92+
if ($withNamespace === false && !empty($value)) {
93+
$value = implode('', array_slice(explode(':', $value), -1, 1));
94+
}
95+
if ($value !== null && $withinItsType === true) {
96+
$value = self::getValueWithinItsType($value, empty($asType) ? $this->getType() : $asType);
97+
}
98+
return $value;
99+
}
100+
/**
101+
* @return null|string
102+
*/
103+
public function getValueNamespace()
104+
{
105+
$value = $this->getAttribute()->value;
106+
$namespace = null;
107+
if (strpos($value, ':') !== false) {
108+
$namespace = implode('', array_slice(explode(':', $value), 0, -1));
109+
}
110+
return $namespace;
111+
}
112+
113+
/**
114+
* Returns the value with good type
115+
* @param mixed $value the value
116+
* @param string $knownType the value
117+
* @return mixed
118+
*/
119+
public static function getValueWithinItsType($value, $knownType = null)
120+
{
121+
if (is_int($value) || (!is_null($value) && in_array($knownType, array(
122+
'time',
123+
'positiveInteger',
124+
'unsignedLong',
125+
'unsignedInt',
126+
'short',
127+
'long',
128+
'int',
129+
'integer',
130+
), true))) {
131+
return intval($value);
132+
} elseif (is_float($value) || (!is_null($value) && in_array($knownType, array(
133+
'float',
134+
'double',
135+
'decimal',
136+
), true))) {
137+
return floatval($value);
138+
} elseif (is_bool($value) || (!is_null($value) && in_array($knownType, array(
139+
'bool',
140+
'boolean',
141+
), true))) {
142+
return ($value === 'true' || $value === true || $value === 1 || $value === '1');
143+
}
144+
return $value;
145+
}
146+
}

0 commit comments

Comments
 (0)