This repository was archived by the owner on Jun 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClassExample.php
More file actions
83 lines (74 loc) · 2.95 KB
/
Copy pathClassExample.php
File metadata and controls
83 lines (74 loc) · 2.95 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* @author stev leibelt <artodeto@bazzline.net>
* @since 2014-05-24
*/
require_once 'AbstractExample.php';
require_once __DIR__ . '/../vendor/autoload.php';
/**
* Class ClassExample
* @package Net\Bazzline\Component\CodeGenerator\Example
*/
class ClassExample extends AbstractExample
{
/**
* @return string
*/
function demonstrate()
{
$blockFactory = $this->getBlockGeneratorFactory();
$classFactory = $this->getClassGeneratorFactory();
$constantFactory = $this->getConstantGeneratorFactory();
$documentationFactory = $this->getDocumentationGeneratorFactory();
$methodFactory = $this->getMethodGeneratorFactory();
$propertyFactory = $this->getPropertyGeneratorFactory();
$traitFactory = $this->getTraitGeneratorFactory();
$myConstant = $constantFactory->create();
$myConstant->setName('MY_CONSTANT');
$myConstant->setValue('foobar');
$myProperty = $propertyFactory->create();
$myProperty->setDocumentation($documentationFactory->create());
$myProperty->markAsProtected();
$myProperty->setName('myProperty');
$myProperty->setValue(12345678.90);
$myProperty->addTypeHint('float');
$myMethod = $methodFactory->create();
$myMethod->setDocumentation($documentationFactory->create());
$myMethod->markAsPublic();
$myMethod->markAsFinal();
$myMethod->setName('myMethod');
$myMethod->addParameter('foo', null, 'Foo');
$myMethod->addParameter('bar', 'null', 'Bar');
$myMethodBody = $blockFactory->create();
$myMethodBody
->add('$foobar = $foo->toString();')
->add('')
->add('if (!is_null($bar)) {')
->startIndention()
->add('$foobar .= $bar->toString();')
->stopIndention()
->add('}')
->add('')
->add('return $foobar');
$myMethod->setBody($myMethodBody, 'string');
$myTrait = $traitFactory->create();
$myTrait->setDocumentation($documentationFactory->create());
$myTrait->setName('myTrait');
$myClass = $classFactory->create();
$myClass->setDocumentation($documentationFactory->create());
$myClass->setNamespace('My\Namespace');
$myClass->setName('MyClass');
$myClass->markAsFinal();
$myClass->setExtends('Foo\Bar', true);
$myClass->addImplements('Bar\FooInterface', true);
$myClass->addConstant($myConstant);
$myClass->addMethod($myMethod);
$myClass->addProperty($myProperty);
$myClass->addTrait($myTrait);
$myClass->getDocumentation()->setAuthor('stev leibelt', 'artodeto@bazzline.net');
$myClass->getDocumentation()->setVersion('0.8.15', 'available since 2014-05-24');
echo $myClass->generate() . PHP_EOL;
}
}
$example = new ClassExample();
$example->demonstrate();