Skip to content

Commit

Permalink
Merge pull request swaggest#29 from swaggest/meta-refactoring
Browse files Browse the repository at this point in the history
meta refactoring, schema exporter interface resolves swaggest#22
  • Loading branch information
vearutop authored Mar 20, 2018
2 parents 99da151 + f2c34af commit f03e5a6
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 36 deletions.
6 changes: 2 additions & 4 deletions src/AbstractMeta.php → src/Meta/AbstractMeta.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

namespace Swaggest\JsonSchema;
namespace Swaggest\JsonSchema\Meta;

use Swaggest\JsonSchema\Meta\Meta;
use Swaggest\JsonSchema\Meta\MetaHolder;

abstract class AbstractMeta implements Meta
abstract class AbstractMeta
{
/**
* @param MetaHolder $schema
Expand Down
12 changes: 0 additions & 12 deletions src/Meta/Meta.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Meta/MetaHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

interface MetaHolder
{
public function addMeta(Meta $meta);
public function addMeta($meta, $name = null);

public function getMeta($name);

Expand Down
16 changes: 9 additions & 7 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Swaggest\JsonSchema\Exception\ObjectException;
use Swaggest\JsonSchema\Exception\StringException;
use Swaggest\JsonSchema\Exception\TypeException;
use Swaggest\JsonSchema\Meta\Meta;
use Swaggest\JsonSchema\Meta\MetaHolder;
use Swaggest\JsonSchema\Path\PointerUtil;
use Swaggest\JsonSchema\Structure\ClassStructure;
Expand Down Expand Up @@ -1179,19 +1178,22 @@ public function setProperty($name, $schema)
return $this;
}

/** @var Meta[] */
/** @var mixed[] */
private $metaItems = array();

public function addMeta(Meta $meta)
public function addMeta($meta, $name = null)
{
$this->metaItems[get_class($meta)] = $meta;
if ($name === null) {
$name = get_class($meta);
}
$this->metaItems[$name] = $meta;
return $this;
}

public function getMeta($className)
public function getMeta($name)
{
if (isset($this->metaItems[$className])) {
return $this->metaItems[$className];
if (isset($this->metaItems[$name])) {
return $this->metaItems[$name];
}
return null;
}
Expand Down
12 changes: 12 additions & 0 deletions src/SchemaExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Swaggest\JsonSchema;


interface SchemaExporter
{
/**
* @return Schema
*/
public function exportSchema();
}
7 changes: 0 additions & 7 deletions src/TODO.md

This file was deleted.

5 changes: 2 additions & 3 deletions src/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Swaggest\JsonSchema;

use Swaggest\JsonSchema\Meta\Meta;
use Swaggest\JsonSchema\Meta\MetaHolder;
use Swaggest\JsonSchema\Structure\Nested;

Expand Down Expand Up @@ -179,9 +178,9 @@ public function __isset($name)
throw new Exception('Unexpected isset: ' . $name);
}

public function addMeta(Meta $meta)
public function addMeta($meta, $name = null)
{
$this->originalSchema->addMeta($meta);
$this->originalSchema->addMeta($meta, $name);
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/Helper/DbId.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Swaggest\JsonSchema\Tests\Helper;

use Swaggest\JsonSchema\Constraint\Properties;
use Swaggest\JsonSchema\AbstractMeta;
use Swaggest\JsonSchema\Meta\AbstractMeta;
use Swaggest\JsonSchema\Schema;
use Swaggest\JsonSchema\Structure\ClassStructureContract;
use Swaggest\JsonSchema\Structure\ClassStructureTrait;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Helper/DbTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Swaggest\JsonSchema\Tests\Helper;

use Swaggest\JsonSchema\AbstractMeta;
use Swaggest\JsonSchema\Meta\AbstractMeta;
use Swaggest\JsonSchema\Schema;
use Swaggest\JsonSchema\Structure\ClassStructureContract;
use Swaggest\JsonSchema\Structure\ClassStructureTrait;
Expand Down

0 comments on commit f03e5a6

Please sign in to comment.