Skip to content

Commit e8f1899

Browse files
committed
Initial engine design
0 parents  commit e8f1899

24 files changed

+808
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "php-soap/engine",
3+
"description": "SOAP engine design",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"Soap\\Engine\\": "src/"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "Toon Verwerft",
14+
"email": "toonverwerft@gmail.com"
15+
}
16+
],
17+
"require": {
18+
"php": "^7.4 || ^8.0"
19+
}
20+
}

src/Decoder.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Soap\Engine;
4+
5+
use Soap\Engine\HttpBinding\SoapResponse;
6+
7+
interface Decoder
8+
{
9+
/**
10+
* @return mixed
11+
*/
12+
public function decode(string $method, SoapResponse $response);
13+
}

src/Driver.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare( strict_types=1 );
4+
5+
namespace Soap\Engine;
6+
7+
use Soap\Engine\Metadata\MetadataProvider;
8+
9+
interface Driver extends Encoder, Decoder, MetadataProvider
10+
{
11+
}

src/Encoder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Soap\Engine;
4+
5+
use Soap\Engine\HttpBinding\SoapRequest;
6+
7+
interface Encoder
8+
{
9+
public function encode(string $method, array $arguments): SoapRequest;
10+
}

src/Engine.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Soap\Engine;
6+
7+
use Soap\Engine\Metadata\MetadataProvider;
8+
9+
interface Engine extends MetadataProvider
10+
{
11+
/**
12+
* @return mixed
13+
*/
14+
public function request(string $method, array $arguments);
15+
}

src/Exception/MetadataException.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Soap\Engine\Exception;
6+
7+
class MetadataException extends RuntimeException
8+
{
9+
public static function typeNotFound(string $name): self
10+
{
11+
return new self('No SOAP type found with name '.$name.'.');
12+
}
13+
14+
public static function methodNotFound(string $name): self
15+
{
16+
return new self('No SOAP method found with name '.$name.'.');
17+
}
18+
}

src/Exception/RuntimeException.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Soap\Engine\Exception;
6+
7+
use Throwable;
8+
9+
abstract class RuntimeException extends \RuntimeException
10+
{
11+
protected function __construct($message = "", $code = 0, Throwable $previous = null)
12+
{
13+
parent::__construct($message, $code, $previous);
14+
}
15+
}

src/HttpBinding/SoapRequest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Soap\Engine\HttpBinding;
4+
5+
class SoapRequest
6+
{
7+
private string $request;
8+
private string $location;
9+
private string $action;
10+
private int $version;
11+
private int $oneWay;
12+
13+
public function __construct(string $request, string $location, string $action, int $version, int $oneWay = 0)
14+
{
15+
$this->request = $request;
16+
$this->location = $location;
17+
$this->action = $action;
18+
$this->version = $version;
19+
$this->oneWay = $oneWay;
20+
}
21+
22+
public function getRequest(): string
23+
{
24+
return $this->request;
25+
}
26+
27+
public function getLocation(): string
28+
{
29+
return $this->location;
30+
}
31+
32+
public function getAction(): string
33+
{
34+
return $this->action;
35+
}
36+
37+
public function getVersion(): int
38+
{
39+
return $this->version;
40+
}
41+
42+
public function isSOAP11(): bool
43+
{
44+
return $this->getVersion() === SOAP_1_1;
45+
}
46+
47+
public function isSOAP12(): bool
48+
{
49+
return $this->getVersion() === SOAP_1_2;
50+
}
51+
52+
public function getOneWay(): int
53+
{
54+
return $this->oneWay;
55+
}
56+
}

src/HttpBinding/SoapResponse.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Soap\Engine\HttpBinding;
4+
5+
class SoapResponse
6+
{
7+
private string $payload;
8+
9+
public function __construct(string $payload)
10+
{
11+
$this->payload = $payload;
12+
}
13+
14+
public function getPayload(): string
15+
{
16+
return $this->payload;
17+
}
18+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Soap\Engine\Metadata\Collection;
6+
7+
use ArrayIterator;
8+
use Countable;
9+
use IteratorAggregate;
10+
use Soap\Engine\Exception\MetadataException;
11+
use Soap\Engine\Metadata\Model\Method;
12+
13+
final class MethodCollection implements IteratorAggregate, Countable
14+
{
15+
/**
16+
* @var Method[]
17+
*/
18+
private array $methods;
19+
20+
public function __construct(Method ...$methods)
21+
{
22+
$this->methods = $methods;
23+
}
24+
25+
public function getIterator(): ArrayIterator
26+
{
27+
return new ArrayIterator($this->methods);
28+
}
29+
30+
public function count(): int
31+
{
32+
return count($this->methods);
33+
}
34+
35+
public function map(callable $callback): array
36+
{
37+
return array_map($callback, $this->methods);
38+
}
39+
40+
public function fetchByName(string $name): Method
41+
{
42+
foreach ($this->methods as $method) {
43+
if ($name === $method->getName()) {
44+
return $method;
45+
}
46+
}
47+
48+
throw MetadataException::methodNotFound($name);
49+
}
50+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Soap\Engine\Metadata\Collection;
6+
7+
use ArrayIterator;
8+
use Countable;
9+
use IteratorAggregate;
10+
use Soap\Engine\Metadata\Model\Parameter;
11+
12+
final class ParameterCollection implements IteratorAggregate, Countable
13+
{
14+
/**
15+
* @var Parameter[]
16+
*/
17+
private array $parameters;
18+
19+
public function __construct(Parameter ...$parameters)
20+
{
21+
$this->parameters = $parameters;
22+
}
23+
24+
/**
25+
* @return ArrayIterator|Parameter[]
26+
*/
27+
public function getIterator(): ArrayIterator
28+
{
29+
return new ArrayIterator($this->parameters);
30+
}
31+
32+
public function count(): int
33+
{
34+
return count($this->parameters);
35+
}
36+
37+
public function map(callable $callback): array
38+
{
39+
return array_map($callback, $this->parameters);
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Soap\Engine\Metadata\Collection;
6+
7+
use ArrayIterator;
8+
use Countable;
9+
use IteratorAggregate;
10+
use Soap\Engine\Metadata\Model\Property;
11+
12+
final class PropertyCollection implements IteratorAggregate, Countable
13+
{
14+
/**
15+
* @var Property[]
16+
*/
17+
private array $properties;
18+
19+
public function __construct(Property ...$properties)
20+
{
21+
$this->properties = $properties;
22+
}
23+
24+
/**
25+
* @return ArrayIterator|Property[]
26+
*/
27+
public function getIterator(): ArrayIterator
28+
{
29+
return new ArrayIterator($this->properties);
30+
}
31+
32+
public function count(): int
33+
{
34+
return count($this->properties);
35+
}
36+
37+
public function map(callable $callback): array
38+
{
39+
return array_map($callback, $this->properties);
40+
}
41+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Soap\Engine\Metadata\Collection;
6+
7+
use ArrayIterator;
8+
use Countable;
9+
use IteratorAggregate;
10+
use Soap\Engine\Exception\MetadataException;
11+
use Soap\Engine\Metadata\Model\Type;
12+
13+
final class TypeCollection implements IteratorAggregate, Countable
14+
{
15+
/**
16+
* @var Type[]
17+
*/
18+
private array $types;
19+
20+
public function __construct(Type ...$types)
21+
{
22+
$this->types = $types;
23+
}
24+
25+
/**
26+
* @return ArrayIterator|Type[]
27+
*/
28+
public function getIterator(): ArrayIterator
29+
{
30+
return new ArrayIterator($this->types);
31+
}
32+
33+
public function count(): int
34+
{
35+
return count($this->types);
36+
}
37+
38+
public function map(callable $callback): array
39+
{
40+
return array_map($callback, $this->types);
41+
}
42+
43+
public function filter(callable $filter): self
44+
{
45+
return new self(...array_filter(
46+
$this->types,
47+
$filter
48+
));
49+
}
50+
51+
public function reduce(callable $reducer, $initial = null)
52+
{
53+
return array_reduce(
54+
$this->types,
55+
$reducer,
56+
$initial
57+
);
58+
}
59+
60+
public function fetchFirstByName(string $name): Type
61+
{
62+
foreach ($this->types as $type) {
63+
if ($name === $type->getName()) {
64+
return $type;
65+
}
66+
}
67+
68+
throw MetadataException::typeNotFound($name);
69+
}
70+
}

0 commit comments

Comments
 (0)