Skip to content

Commit b50a286

Browse files
committed
add in meta generation logic by label & description
1 parent b808948 commit b50a286

File tree

7 files changed

+207
-38
lines changed

7 files changed

+207
-38
lines changed

main/Base/LightMetaProperty.class.php

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,35 @@ class LightMetaProperty implements Stringable
4646
)
4747
);
4848

49-
private $name = null;
50-
private $columnName = null;
49+
private $name = null;
50+
private $columnName = null;
5151

52-
private $type = null;
53-
private $className = null;
52+
private $type = null;
53+
private $className = null;
5454

55-
private $size = null;
55+
private $size = null;
5656

57-
private $min = null;
58-
private $max = null;
57+
private $min = null;
58+
private $max = null;
5959

60-
private $required = false;
61-
private $generic = false;
62-
private $inner = false;
60+
private $required = false;
61+
private $generic = false;
62+
private $inner = false;
6363

6464
/// @see MetaRelation
65-
private $relationId = null;
65+
private $relationId = null;
6666

6767
/// @see FetchStrategy
68-
private $strategyId = null;
68+
private $strategyId = null;
6969

70-
private $getter = null;
71-
private $setter = null;
72-
private $dropper = null;
70+
private $getter = null;
71+
private $setter = null;
72+
private $dropper = null;
7373

74-
private $identifier = null;
74+
private $identifier = null;
75+
76+
private $label = null;
77+
private $description = null;
7578

7679
/**
7780
* @return LightMetaProperty
@@ -89,10 +92,13 @@ public static function create()
8992
public static function fill(
9093
LightMetaProperty $property,
9194
$name, $columnName, $type, $className, $size,
92-
$required, $generic, $inner, $relationId, $strategyId
95+
$required, $generic, $inner, $relationId, $strategyId, $label=null, $description=null
9396
)
9497
{
9598
$property->name = $name;
99+
100+
$property->label = $label;
101+
$property->description = $description;
96102

97103
$methodSuffix = ucfirst($name);
98104
$property->getter = 'get'.$methodSuffix;
@@ -309,6 +315,12 @@ public function makePrimitive($name)
309315

310316
if ($this->required)
311317
$prm->required();
318+
319+
if($this->label)
320+
$prm->setLabel($this->label);
321+
322+
if($this->description)
323+
$prm->setDescription($this->description);
312324

313325
return $prm;
314326
}
@@ -505,6 +517,18 @@ final public function toString()
505517
? $this->strategyId
506518
: 'null'
507519
)
520+
.', '
521+
.(
522+
$this->label
523+
? '\''.$this->label.'\''
524+
: 'null'
525+
)
526+
.', '
527+
.(
528+
$this->description
529+
? '\''.$this->description.'\''
530+
: 'null'
531+
)
508532
.')';
509533
}
510534

meta/classes/MetaClassProperty.class.php

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@
1414
**/
1515
class MetaClassProperty
1616
{
17-
private $class = null;
17+
private $class = null;
1818

19-
private $name = null;
20-
private $columnName = null;
19+
private $name = null;
20+
private $columnName = null;
2121

22-
private $type = null;
23-
private $size = null;
22+
private $type = null;
23+
private $size = null;
2424

25-
private $required = false;
26-
private $identifier = false;
25+
private $required = false;
26+
private $identifier = false;
2727

28-
private $relation = null;
28+
private $relation = null;
2929

30-
private $strategy = null;
30+
private $strategy = null;
31+
32+
private $label = null;
33+
private $description = null;
3134

3235
public function __construct(
3336
$name,
@@ -250,6 +253,44 @@ public function getFetchStrategyId()
250253

251254
return null;
252255
}
256+
257+
/**
258+
* @param $label
259+
* @return MetaClassProperty
260+
*/
261+
public function setLabel($label)
262+
{
263+
$this->label = $label;
264+
265+
return $this;
266+
}
267+
268+
/**
269+
* @return null|string
270+
*/
271+
public function getLabel()
272+
{
273+
return $this->label;
274+
}
275+
276+
/**
277+
* @param $description
278+
* @return MetaClassProperty
279+
*/
280+
public function setDescription($description)
281+
{
282+
$this->description = $description;
283+
284+
return $this;
285+
}
286+
287+
/**
288+
* @return null|string
289+
*/
290+
public function getDescription()
291+
{
292+
return $this->description;
293+
}
253294

254295
public function toMethods(
255296
MetaClass $class,
@@ -423,7 +464,9 @@ public function toLightProperty(MetaClass $holder)
423464
$this->getType()->isGeneric(),
424465
$inner,
425466
$this->getRelationId(),
426-
$this->getFetchStrategyId()
467+
$this->getFetchStrategyId(),
468+
$this->getLabel(),
469+
$this->getDescription()
427470
)
428471
);
429472
}

meta/classes/MetaConfiguration.class.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ private function addSource(SimpleXMLElement $source)
786786
/**
787787
* @return MetaClassProperty
788788
**/
789-
private function makeProperty($name, $type, MetaClass $class, $size)
789+
private function makeProperty($name, $type, MetaClass $class, $size, $label=null, $description=null)
790790
{
791791
Assert::isFalse(
792792
strpos($name, '_'),
@@ -823,6 +823,9 @@ private function makeProperty($name, $type, MetaClass $class, $size)
823823
'size is required for "'.$property->getName().'"'
824824
);
825825
}
826+
827+
$property->setLabel($label);
828+
$property->setDescription($description);
826829

827830
return $property;
828831
}
@@ -1120,7 +1123,9 @@ private function processClasses(SimpleXMLElement $xml, $metafile, $generate)
11201123
(string) $xmlProperty['name'],
11211124
(string) $xmlProperty['type'],
11221125
$class,
1123-
(string) $xmlProperty['size']
1126+
(string) $xmlProperty['size'],
1127+
(string) $xmlProperty['label'],
1128+
(string) $xmlProperty['description']
11241129
);
11251130

11261131
if (isset($xmlProperty['column'])) {

meta/dtd/meta.dtd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
required (true|false) "false"
3939
relation (OneToOne|OneToMany|ManyToMany) #IMPLIED
4040
fetch (lazy|cascade) #IMPLIED
41+
label CDATA #IMPLIED
42+
description CDATA #IMPLIED
4143
>
4244

4345
<!ELEMENT pattern EMPTY>

meta/types/BasePropertyType.class.php

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,29 @@ public function toGetter(
6666
$name = $property->getName();
6767

6868
$methodName = 'get'.ucfirst($property->getName());
69-
69+
70+
$doc = '/**'."\n";
71+
$doced = null;
72+
73+
if($label = $property->getLabel()) {
74+
$doc .= ' * '.$label."\n";
75+
$doced = true;
76+
}
77+
78+
if($desc = $property->getDescription()) {
79+
$doc.=" *\n";
80+
$doc.=' * '.$desc."\n";
81+
$doced = true;
82+
}
83+
84+
$doc .= "**/";
85+
86+
if($doced===null)
87+
$doc = '';
88+
7089
return <<<EOT
7190
91+
{$doc}
7292
public function {$methodName}()
7393
{
7494
return \$this->{$name};
@@ -85,13 +105,31 @@ public function toSetter(
85105
{
86106
$name = $property->getName();
87107
$methodName = 'set'.ucfirst($name);
88-
108+
109+
$doc = '/**'."\n";
110+
$doced = false;
111+
112+
if($label = $property->getLabel()) {
113+
$doc .= ' * '.$label."\n";
114+
}
115+
116+
if($desc = $property->getDescription()) {
117+
$doc.=" *\n";
118+
$doc.=' * '.$desc."\n";
119+
}
120+
121+
if($holder) {
122+
$doc .= ' * @return '.$holder->getClass()->getName()."\n";
123+
} else {
124+
$doc .= ' * @return '.$class->getName()."\n";
125+
}
126+
127+
$doc .= "**/";
128+
89129
if ($holder) {
90130
return <<<EOT
91131
92-
/**
93-
* @return {$holder->getClass()->getName()}
94-
**/
132+
{$doc}
95133
public function {$methodName}(\${$name})
96134
{
97135
\$this->{$holder->getName()}->{$methodName}(\${$name});
@@ -103,9 +141,7 @@ public function {$methodName}(\${$name})
103141
} else {
104142
return <<<EOT
105143
106-
/**
107-
* @return {$class->getName()}
108-
**/
144+
{$doc}
109145
public function {$methodName}(\${$name})
110146
{
111147
\$this->{$name} = \${$name};

test/main/ProtoTest.class.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/***************************************************************************
3+
* Copyright (C) by Georgiy T. Kutsurua *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify *
6+
* it under the terms of the GNU Lesser General Public License as *
7+
* published by the Free Software Foundation; either version 3 of the *
8+
* License, or (at your option) any later version. *
9+
***************************************************************************/
10+
11+
class ProtoTest extends TestCase
12+
{
13+
14+
public function testGeneratePrimitive()
15+
{
16+
$name = 'email';
17+
$columnName = 'email';
18+
$type = 'string';
19+
$className=null;
20+
$size = 255;
21+
$required = true;
22+
$generic = true;
23+
$inner = false;
24+
$relationId = null;
25+
$strategyId = null;
26+
27+
$label = 'Label for email';
28+
$description = 'This is description for email';
29+
30+
$metProperty = LightMetaProperty::fill(
31+
new LightMetaProperty(),
32+
$name, $columnName, $type, $className, $size,
33+
$required, $generic, $inner, $relationId, $strategyId, $label, $description
34+
);
35+
36+
$prm = $metProperty->makePrimitive($name);
37+
38+
$this->assertEquals(
39+
$size,
40+
$prm->getMax()
41+
);
42+
43+
$this->assertEquals(
44+
$label,
45+
$prm->getLabel()
46+
);
47+
48+
$this->assertEquals(
49+
$description,
50+
$prm->getDescription()
51+
);
52+
53+
$this->assertEquals(
54+
$name,
55+
$prm->getName()
56+
);
57+
}
58+
59+
}

test/meta/config.meta.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<class name="Credentials" type="final">
99
<properties>
10-
<property name="nickname" type="String" size="255" required="true" />
10+
<property name="nickname" type="String" size="255" required="true" label="Nick name" description="This is description for nick name" />
1111
<property name="password" type="FixedLengthString" size="40" required="true" />
1212
</properties>
1313

0 commit comments

Comments
 (0)