1: <?php
2:
3: namespace Chromabits\Nucleus\Meditation;
4:
5: use Chromabits\Nucleus\Control\Maybe;
6: use Chromabits\Nucleus\Data\ArrayMap;
7:
8: /**
9: * Class FormSpec.
10: *
11: * @author Eduardo Trujillo <ed@chromabits.com>
12: * @package Chromabits\Nucleus\Meditation
13: */
14: class FormSpec extends TypedSpec
15: {
16: const ANNOTATION_LABEL = 'label';
17:
18: const ANNOTATION_DESCRIPTION = 'description';
19:
20: /**
21: * Set the label for a field.
22: *
23: * @param string $fieldName
24: * @param string $label
25: *
26: * @return static
27: */
28: public function withFieldLabel($fieldName, $label)
29: {
30: return $this->withFieldAnnotation(
31: $fieldName,
32: static::ANNOTATION_LABEL,
33: $label
34: );
35: }
36:
37: /**
38: * Set the description for a field.
39: *
40: * @param string $fieldName
41: * @param string $description
42: *
43: * @return static
44: */
45: public function withFieldDescription($fieldName, $description)
46: {
47: return $this->withFieldAnnotation(
48: $fieldName,
49: static::ANNOTATION_DESCRIPTION,
50: $description
51: );
52: }
53:
54: /**
55: * Get a field's label.
56: *
57: * @param string $fieldName
58: *
59: * @return Maybe
60: */
61: public function getFieldLabel($fieldName)
62: {
63: return $this->getFieldAnnotation($fieldName, static::ANNOTATION_LABEL);
64: }
65:
66: /**
67: * Get a field's description.
68: *
69: * @param string $fieldName
70: *
71: * @return Maybe
72: */
73: public function getFieldDescription($fieldName)
74: {
75: return $this->getFieldAnnotation(
76: $fieldName,
77: static::ANNOTATION_DESCRIPTION
78: );
79: }
80:
81: /**
82: * Get the labels for all fields.
83: *
84: * @return ArrayMap
85: */
86: public function getLabels()
87: {
88: return $this->getAnnotation(static::ANNOTATION_LABEL);
89: }
90:
91: /**
92: * Get the descriptions for all fields.
93: *
94: * @return ArrayMap
95: */
96: public function getDescriptions()
97: {
98: return $this->getAnnotation(static::ANNOTATION_DESCRIPTION);
99: }
100: }