1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
exactparameter.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Engine\AutoWire;
4
5use Bitrix\Main\Error;
6use Bitrix\Main\Result;
7
9{
10 private string $parameterName;
11
12 public function __construct(string $className, string $parameterName, \Closure $constructor)
13 {
14 if (!$this->validateConstructor($constructor))
15 {
16 throw new BinderArgumentException('$constructor closure must have one argument to bind class name.');
17 }
18
19 parent::__construct($className, $constructor);
20 $this->parameterName = $parameterName;
21 }
22
23 protected function validateConstructor(\Closure $constructor)
24 {
25 $reflectionFunction = new \ReflectionFunction($constructor);
26
27 return $reflectionFunction->getNumberOfParameters() >= 1;
28 }
29
30 public function constructValue(\ReflectionParameter $parameter, Result $captureResult, $newThis = null)
31 {
32 return $this->callConstructor(
33 $this->getConstructor(),
34 $captureResult->getData(),
35 $newThis,
36 );
37 }
38
39 public function captureData(\ReflectionParameter $parameter, array $sourceParameters, array $autoWiredParameters = [])
40 {
41 $result = new Result();
42
43 if (!$this->needToMapExternalData())
44 {
45 return $result;
46 }
47
48 $binder = Binder::buildForFunction($this->getConstructor());
49 $binder->setAutoWiredParameters($autoWiredParameters);
50
51 $reflectionClass = $this->buildReflectionClass($parameter);
52 if (!$reflectionClass)
53 {
54 throw new BinderArgumentException("Could not retrieve \\ReflectionClass for {$parameter->getName()}.");
55 }
56
57 array_unshift($sourceParameters, ['className' => $reflectionClass->getName()]);
58 $binder->setSourcesParametersToMap($sourceParameters);
59 try
60 {
61 $capturedParameters = $binder->getArgs();
62 $result->setData($capturedParameters);
63 }
65 {
66 $result->addError(new Error($e->getMessage()));
67 }
68
69 return $result;
70 }
71
72 public function match(\ReflectionParameter $parameter)
73 {
74 return
75 parent::match($parameter) &&
76 $parameter->getName() === $this->getParameterName()
77 ;
78 }
79
83 public function getParameterName()
84 {
85 return $this->parameterName;
86 }
87
88 public function getPriority()
89 {
90 return parent::getPriority() + 1;
91 }
92}
static buildForFunction($callable, $configuration=[])
Определения binder.php:48
match(\ReflectionParameter $parameter)
Определения exactparameter.php:72
validateConstructor(\Closure $constructor)
Определения exactparameter.php:23
constructValue(\ReflectionParameter $parameter, Result $captureResult, $newThis=null)
Определения exactparameter.php:30
captureData(\ReflectionParameter $parameter, array $sourceParameters, array $autoWiredParameters=[])
Определения exactparameter.php:39
__construct(string $className, string $parameterName, \Closure $constructor)
Определения exactparameter.php:12
callConstructor(\Closure $constructor, array $params, $newThis=null)
Определения parameter.php:67
buildReflectionClass(\ReflectionParameter $parameter)
Определения parameter.php:135
Определения error.php:15
getData()
Определения result.php:148
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14