-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSection.php
60 lines (50 loc) · 1.36 KB
/
Section.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace In\Blueprint;
use Illuminate\Support\Collection;
abstract class Section
{
/**
* Get an annotation by its type.
*
* @param string $type
*
* @return mixed
*/
protected function getAnnotationByType($type)
{
return array_first($this->annotations, function ($key, $annotation) use ($type) {
$type = sprintf('In\\Blueprint\\Annotation\\%s', $type);
return is_object($annotation) ? $annotation instanceof $type : $key instanceof $type;
});
}
/**
* Get a sections parameter annotations.
*
* @return \Illuminate\Support\Collection
*/
public function getParameters()
{
$parameters = new Collection;
if ($annotation = $this->getAnnotationByType('Parameters')) {
foreach ($annotation->value as $parameter) {
$parameters[] = $parameter;
}
}
return $parameters;
}
/**
* Get a sections attribute annotations.
*
* @return \Illuminate\Support\Collection
*/
public function getAttributes()
{
$attributes = new Collection;
if ($annotation = $this->getAnnotationByType('Attributes')) {
foreach ($annotation->value as $attribute) {
$attributes[] = $attribute;
}
}
return $attributes;
}
}