‪TYPO3CMS  10.4
Method.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 
26 class ‪Method
27 {
31  private ‪$name;
32 
36  private ‪$definition;
37 
41  private ‪$className;
42 
46  private ‪$parameters = [];
47 
53  public function ‪__construct(string ‪$name, array ‪$definition, string ‪$className)
54  {
55  $this->name = ‪$name;
56  $this->className = ‪$className;
57 
58  $defaults = [
59  'params' => [],
60  'public' => false,
61  'protected' => false,
62  'private' => false,
63  'injectMethod' => false,
64  'static' => false,
65  ];
66 
67  foreach ($defaults as $key => $defaultValue) {
68  if (!isset(‪$definition[$key])) {
69  ‪$definition[$key] = $defaultValue;
70  }
71  }
72 
73  $this->definition = ‪$definition;
74 
75  foreach ($this->definition['params'] as $parameterName => $parameterDefinition) {
76  $this->parameters[$parameterName] = new ‪MethodParameter($parameterName, $parameterDefinition);
77  }
78  }
79 
83  public function ‪getName(): string
84  {
85  return ‪$this->name;
86  }
87 
91  public function ‪getParameters(): array
92  {
93  return ‪$this->parameters;
94  }
95 
101  public function ‪getFirstParameter(): ‪MethodParameter
102  {
103  $position = 0;
104 
105  ‪$parameters = array_filter($this->‪getParameters(), function (‪MethodParameter $parameter) use ($position) {
106  return $parameter->‪getPosition() === $position;
107  });
108 
109  $parameter = reset(‪$parameters);
110 
111  if (!$parameter instanceof MethodParameter) {
112  throw NoSuchMethodParameterException::createForParameterPosition(
113  $this->className,
114  $this->name,
115  $position
116  );
117  }
118 
119  return $parameter;
120  }
121 
128  public function ‪getParameter(string $parameterName): MethodParameter
129  {
130  if (!isset($this->parameters[$parameterName])) {
131  throw NoSuchMethodParameterException::createForParameterName(
132  $this->className,
133  $this->name,
134  $parameterName
135  );
136  }
137 
138  return $this->parameters[$parameterName];
139  }
140 
144  public function ‪isPublic(): bool
145  {
146  return $this->definition['public'];
147  }
148 
152  public function ‪isProtected(): bool
153  {
154  return $this->definition['protected'];
155  }
156 
160  public function ‪isPrivate(): bool
161  {
162  return $this->definition['private'];
163  }
164 
168  public function ‪isInjectMethod(): bool
169  {
170  return $this->definition['injectMethod'];
171  }
172 
176  public function ‪isStatic(): bool
177  {
178  return $this->definition['static'];
179  }
180 }
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\isProtected
‪bool isProtected()
Definition: Method.php:148
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\getParameter
‪MethodParameter getParameter(string $parameterName)
Definition: Method.php:124
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\isPublic
‪bool isPublic()
Definition: Method.php:140
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Exception\NoSuchMethodParameterException
Definition: NoSuchMethodParameterException.php:24
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\isPrivate
‪bool isPrivate()
Definition: Method.php:156
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\$parameters
‪array $parameters
Definition: Method.php:42
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\$definition
‪array $definition
Definition: Method.php:34
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\isInjectMethod
‪bool isInjectMethod()
Definition: Method.php:164
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\MethodParameter
Definition: MethodParameter.php:25
‪TYPO3\CMS\Extbase\Reflection\ClassSchema
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\getParameters
‪array MethodParameter[] getParameters()
Definition: Method.php:87
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\getFirstParameter
‪MethodParameter getFirstParameter()
Definition: Method.php:97
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\$name
‪string $name
Definition: Method.php:30
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\__construct
‪__construct(string $name, array $definition, string $className)
Definition: Method.php:49
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method
Definition: Method.php:27
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\getName
‪string getName()
Definition: Method.php:79
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\$className
‪string $className
Definition: Method.php:38
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Method\isStatic
‪bool isStatic()
Definition: Method.php:172
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\MethodParameter\getPosition
‪int getPosition()
Definition: MethodParameter.php:138