Skip to content

Commit d2b8d2e

Browse files
committed
meta
1 parent 246773e commit d2b8d2e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Meta.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Swaggest\JsonSchema;
4+
5+
6+
abstract class Meta
7+
{
8+
/**
9+
* @param Schema $schema
10+
* @return null|static
11+
*/
12+
public static function get(Schema $schema)
13+
{
14+
return $schema->getMeta(get_called_class());
15+
}
16+
}

src/Schema.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,20 @@ public function setProperty($name, Schema $schema)
455455
return $this;
456456
}
457457

458+
/** @var Meta[] */
459+
private $metaItems = array();
460+
public function meta(Meta $meta)
461+
{
462+
$this->metaItems[get_class($meta)] = $meta;
463+
return $this;
464+
}
465+
466+
public function getMeta($className)
467+
{
468+
if (isset($this->metaItems[$className])) {
469+
return $this->metaItems[$className];
470+
}
471+
return null;
472+
}
473+
458474
}

0 commit comments

Comments
 (0)