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

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kleijnweb committed Aug 23, 2018
1 parent 7b86550 commit 57db3e8
Show file tree
Hide file tree
Showing 63 changed files with 747 additions and 134 deletions.
13 changes: 10 additions & 3 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 All @@ -37,15 +38,21 @@ abstract class Builder
*/
protected $schemaFactory;

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

/**
* OpenApiBuilder constructor.
*
* @param Document $document
*/
public function __construct(Document $document)
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
8 changes: 7 additions & 1 deletion src/Description/Builder/OpenApiBuilder.php
Expand Up @@ -18,6 +18,7 @@
use KleijnWeb\PhpApi\Descriptions\Description\Schema\Schema;
use KleijnWeb\PhpApi\Descriptions\Description\Visitor\ClosureVisitor;
use KleijnWeb\PhpApi\Descriptions\Description\Visitor\ClosureVisitorScope;
use KleijnWeb\PhpApi\Descriptions\Hydrator\ClassNameResolver;

/**
* @author John Kleijn <john@kleijnweb.nl>
Expand Down Expand Up @@ -70,7 +71,12 @@ public function build(): Description
});

foreach ($typeDefinitions as $name => $schema) {
$type = new ComplexType($name, $schema);
$type = new ComplexType(
$name,
$schema,
$this->classNameResolver->resolve($schema->getComplexType()->getName())
);

$schema->setComplexType($type);
$complexTypes[] = $type;
}
Expand Down
69 changes: 66 additions & 3 deletions src/Description/ComplexType.php
Expand Up @@ -25,16 +25,79 @@ class ComplexType
*/
private $schema;

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

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

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

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

/**
* @param ComplexType $child
*
* @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
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
22 changes: 4 additions & 18 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 @@ -22,20 +22,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 +43,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
@@ -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 57db3e8

Please sign in to comment.