Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InterfaceGenerator.php
Go to the documentation of this file.
1 <?php
7 
11 class InterfaceGenerator extends \Magento\Framework\Code\Generator\ClassGenerator
12 {
16  public function generate()
17  {
18  if (!$this->isSourceDirty()) {
19  $output = $this->getSourceContent();
20  if (!empty($output)) {
21  return $output;
22  }
23  }
24  $output = '';
25  if (!$this->getName()) {
26  return $output;
27  }
28 
29  $output .= $this->generateDirectives();
30  if (null !== ($docBlock = $this->getDocBlock())) {
31  $docBlock->setIndentation('');
32  $output .= $docBlock->generate();
33  }
34  $output .= 'interface ' . $this->getName();
35  if (!empty($this->extendedClass)) {
36  $output .= ' extends \\' . ltrim($this->extendedClass, '\\');
37  }
38 
39  $output .= self::LINE_FEED . '{' . self::LINE_FEED . self::LINE_FEED
40  . $this->generateMethods() . self::LINE_FEED . '}' . self::LINE_FEED;
41 
42  return $output;
43  }
44 
50  protected function createMethodGenerator()
51  {
52  return new \Magento\Framework\Code\Generator\InterfaceMethodGenerator();
53  }
54 
60  protected function generateMethods()
61  {
62  $output = '';
63  $methods = $this->getMethods();
64  if (!empty($methods)) {
65  foreach ($methods as $method) {
66  $output .= $method->generate() . self::LINE_FEED;
67  }
68  }
69  return $output;
70  }
71 
77  protected function generateDirectives()
78  {
79  $output = '';
80  $namespace = $this->getNamespaceName();
81  if (null !== $namespace) {
82  $output .= 'namespace ' . $namespace . ';' . self::LINE_FEED . self::LINE_FEED;
83  }
84 
85  $uses = $this->getUses();
86  if (!empty($uses)) {
87  foreach ($uses as $use) {
88  $output .= 'use ' . $use . ';' . self::LINE_FEED;
89  }
90  $output .= self::LINE_FEED;
91  }
92  return $output;
93  }
94 }
$methods
Definition: billing.phtml:71
$method
Definition: info.phtml:13