Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Merge 138051e into 7b86550
Browse files Browse the repository at this point in the history
  • Loading branch information
kleijnweb committed Aug 24, 2018
2 parents 7b86550 + 138051e commit 6c19eca
Show file tree
Hide file tree
Showing 77 changed files with 994 additions and 208 deletions.
14 changes: 8 additions & 6 deletions src/Description/Builder/Builder.php
Expand Up @@ -11,6 +11,7 @@
use KleijnWeb\PhpApi\Descriptions\Description\Description;
use KleijnWeb\PhpApi\Descriptions\Description\Document\Document;
use KleijnWeb\PhpApi\Descriptions\Description\Schema\SchemaFactory;
use KleijnWeb\PhpApi\Descriptions\Hydrator\ClassNameResolver;

/**
* @author John Kleijn <john@kleijnweb.nl>
Expand Down Expand Up @@ -38,14 +39,15 @@ abstract class Builder
protected $schemaFactory;

/**
* OpenApiBuilder constructor.
*
* @param Document $document
* @var ClassNameResolver
*/
public function __construct(Document $document)
protected $classNameResolver;

public function __construct(Document $document, ClassNameResolver $classNameResolver = null)
{
$this->document = $document;
$this->schemaFactory = new SchemaFactory();
$this->document = $document;
$this->schemaFactory = new SchemaFactory();
$this->classNameResolver = $classNameResolver;
}

abstract public function build(): Description;
Expand Down
25 changes: 16 additions & 9 deletions src/Description/Builder/OpenApiBuilder.php
Expand Up @@ -69,16 +69,23 @@ public function build(): Description
}
});

foreach ($typeDefinitions as $name => $schema) {
$type = new ComplexType($name, $schema);
$schema->setComplexType($type);
$complexTypes[] = $type;
}

$description->accept(new ClosureVisitor($description, function () use (&$complexTypes) {
/** @noinspection PhpUndefinedFieldInspection */
$this->complexTypes = $complexTypes;
}));
if (null !== $this->classNameResolver) {
foreach ($typeDefinitions as $name => $schema) {
$type = new ComplexType(
$name,
$schema,
$this->classNameResolver->resolve($name)
);
$schema->setComplexType($type);
$complexTypes[] = $type;
}

$description->accept(new ClosureVisitor($description, function () use (&$complexTypes) {
/** @noinspection PhpUndefinedFieldInspection */
$this->complexTypes = $complexTypes;
}));
}

return $description;
}
Expand Down
68 changes: 62 additions & 6 deletions src/Description/ComplexType.php
Expand Up @@ -26,15 +26,71 @@ class ComplexType
private $schema;

/**
* ComplexType constructor.
* @var ComplexType[]
*/
private $parents = [];

/**
* @var ComplexType[]
*/
private $children = [];

/**
* @var null|string
*/
private $className;

public function __construct(string $name, ObjectSchema $schema, string $className)
{
$this->name = $name;
$this->schema = $schema;
$this->className = $className;
}

/**
* @param ComplexType $child
*
* @param string $name
* @param ObjectSchema $schema
* @return ComplexType
*/
public function addChild(ComplexType $child): ComplexType
{
$this->children[] = $child;
return $this;
}

/**
* @param ComplexType $parent
*
* @return ComplexType
*/
public function addParent(ComplexType $parent): ComplexType
{
$this->parents[] = $parent;
return $this;
}

/**
* @return ComplexType[]
*/
public function getParents(): array
{
return $this->parents;
}

/**
* @return ComplexType[]
*/
public function getChildren(): array
{
return $this->children;
}

/**
* @return null|string
*/
public function __construct(string $name, ObjectSchema $schema)
public function getClassName()
{
$this->name = $name;
$this->schema = $schema;
return $this->className;
}

/**
Expand Down
20 changes: 15 additions & 5 deletions src/Description/DescriptionFactory.php
Expand Up @@ -12,6 +12,7 @@
use KleijnWeb\PhpApi\Descriptions\Description\Builder\RamlBuilder;
use KleijnWeb\PhpApi\Descriptions\Description\Document\Definition\RefResolver\RefResolver;
use KleijnWeb\PhpApi\Descriptions\Description\Document\Document;
use KleijnWeb\PhpApi\Descriptions\Hydrator\ClassNameResolver;

/**
* @author John Kleijn <john@kleijnweb.nl>
Expand All @@ -26,14 +27,21 @@ class DescriptionFactory
*/
private $type;

/**
* @var ClassNameResolver
*/
private $classNameResolver;

/**
* DescriptionFactory constructor.
*
* @param string $type
* @param string $type
* @param ClassNameResolver|null $classNameResolver
*/
public function __construct(string $type = self::BUILDER_OPEN_API)
public function __construct(string $type = self::BUILDER_OPEN_API, ClassNameResolver $classNameResolver = null)
{
$this->type = $type;
$this->type = $type;
$this->classNameResolver = $classNameResolver;
}

/**
Expand All @@ -51,7 +59,8 @@ public function create(string $uri, \stdClass $definition): Description
new Document(
$uri,
(new RefResolver($definition, $uri))->resolve()
)
),
$this->classNameResolver
)
)->build();
case self::BUILDER_RAML:
Expand All @@ -60,7 +69,8 @@ public function create(string $uri, \stdClass $definition): Description
new Document(
$uri,
$definition
)
),
$this->classNameResolver
)
)->build();
default:
Expand Down
Expand Up @@ -84,6 +84,7 @@ public function unresolve(): \stdClass
* @param object|array $current
* @param \stdClass $document
* @param string $uri
* @throws InvalidReferenceException
*/
private function resolveRecursively(&$current, \stdClass $document = null, string $uri = null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Description/Schema/ObjectSchema.php
Expand Up @@ -127,9 +127,9 @@ public function hasComplexType(): bool
}

/**
* @return ComplexType
* @return ComplexType|null
*/
public function getComplexType(): ComplexType
public function getComplexType()
{
return $this->complexType;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/ClassNameResolver.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/DateTimeSerializer.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/Exception/ClassNotFoundException.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/Exception/DateTimeNotParsableException.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/Exception/UnsupportedException.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/ProcessorBuilder.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/Processors/AnyProcessor.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/Processors/ArrayProcessor.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/Processors/Factory/AnyFactory.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/Processors/Factory/ArrayFactory.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
23 changes: 4 additions & 19 deletions src/Hydrator/Processors/Factory/ComplexTypeFactory.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -10,7 +10,6 @@

use KleijnWeb\PhpApi\Descriptions\Description\Schema\ObjectSchema;
use KleijnWeb\PhpApi\Descriptions\Description\Schema\Schema;
use KleijnWeb\PhpApi\Descriptions\Hydrator\ClassNameResolver;
use KleijnWeb\PhpApi\Descriptions\Hydrator\ProcessorBuilder;
use KleijnWeb\PhpApi\Descriptions\Hydrator\Processors\Object\ComplexTypePropertyProcessor;
use KleijnWeb\PhpApi\Descriptions\Hydrator\Processors\Object\ObjectProcessor;
Expand All @@ -22,20 +21,6 @@ class ComplexTypeFactory extends ObjectFactory
{
const PRIORITY = 400;

/**
* @var ClassNameResolver
*/
protected $classNameResolver;

/**
* DateTimeFactory constructor.
* @param ClassNameResolver $classNameResolver
*/
public function __construct(ClassNameResolver $classNameResolver)
{
$this->classNameResolver = $classNameResolver;
}

/**
* @param Schema $schema
* @return bool
Expand All @@ -57,12 +42,12 @@ public function getPriority(): int
/**
* @param ObjectSchema $schema
* @param ProcessorBuilder $builder
*
* @return ObjectProcessor
* @throws \ReflectionException
*/
protected function instantiate(ObjectSchema $schema, ProcessorBuilder $builder): ObjectProcessor
{
$className = $this->classNameResolver->resolve($schema->getComplexType()->getName());

return new ComplexTypePropertyProcessor($schema, $className);
return new ComplexTypePropertyProcessor($schema);
}
}
2 changes: 1 addition & 1 deletion src/Hydrator/Processors/Factory/DateTimeFactory.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/Processors/Factory/Factory.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/Processors/Factory/FactoryQueue.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/Processors/Factory/ObjectFactory.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Hydrator/Processors/Factory/ScalarFactory.php
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* This file is part of the KleijnWeb\PhpApi\Descriptions\Hydrator package.
* This file is part of the KleijnWeb\PhpApi\Descriptions package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down

0 comments on commit 6c19eca

Please sign in to comment.