Mercurial > hg > isophonics-drupal-site
comparison vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
35 { | 35 { |
36 /** | 36 /** |
37 * Used to match very simple id methods that don't need | 37 * Used to match very simple id methods that don't need |
38 * to be decorated since the identifier is known. | 38 * to be decorated since the identifier is known. |
39 */ | 39 */ |
40 const PATTERN_MATCH_ID_METHOD = '((public\s+)?(function\s+%s\s*\(\)\s*)\s*{\s*return\s*\$this->%s;\s*})i'; | 40 const PATTERN_MATCH_ID_METHOD = '((public\s+)?(function\s+%s\s*\(\)\s*)\s*(?::\s*\??\s*\\\\?[a-z_\x7f-\xff][\w\x7f-\xff]*(?:\\\\[a-z_\x7f-\xff][\w\x7f-\xff]*)*\s*)?{\s*return\s*\$this->%s;\s*})i'; |
41 | 41 |
42 /** | 42 /** |
43 * The namespace that contains all proxy classes. | 43 * The namespace that contains all proxy classes. |
44 * | 44 * |
45 * @var string | 45 * @var string |
785 $identifier = lcfirst(substr($name, 3)); | 785 $identifier = lcfirst(substr($name, 3)); |
786 $fieldType = $class->getTypeOfField($identifier); | 786 $fieldType = $class->getTypeOfField($identifier); |
787 $cast = in_array($fieldType, ['integer', 'smallint']) ? '(int) ' : ''; | 787 $cast = in_array($fieldType, ['integer', 'smallint']) ? '(int) ' : ''; |
788 | 788 |
789 $methods .= ' if ($this->__isInitialized__ === false) {' . "\n"; | 789 $methods .= ' if ($this->__isInitialized__ === false) {' . "\n"; |
790 $methods .= ' return ' . $cast . ' parent::' . $method->getName() . "();\n"; | 790 $methods .= ' '; |
791 $methods .= $this->shouldProxiedMethodReturn($method) ? 'return ' : ''; | |
792 $methods .= $cast . ' parent::' . $method->getName() . "();\n"; | |
791 $methods .= ' }' . "\n\n"; | 793 $methods .= ' }' . "\n\n"; |
792 } | 794 } |
793 | 795 |
794 $invokeParamsString = implode(', ', $this->getParameterNamesForInvoke($method->getParameters())); | 796 $invokeParamsString = implode(', ', $this->getParameterNamesForInvoke($method->getParameters())); |
795 $callParamsString = implode(', ', $this->getParameterNamesForParentCall($method->getParameters())); | 797 $callParamsString = implode(', ', $this->getParameterNamesForParentCall($method->getParameters())); |
796 | 798 |
797 $methods .= "\n \$this->__initializer__ " | 799 $methods .= "\n \$this->__initializer__ " |
798 . "&& \$this->__initializer__->__invoke(\$this, " . var_export($name, true) | 800 . "&& \$this->__initializer__->__invoke(\$this, " . var_export($name, true) |
799 . ", [" . $invokeParamsString . "]);" | 801 . ", [" . $invokeParamsString . "]);" |
800 . "\n\n return parent::" . $name . '(' . $callParamsString . ');' | 802 . "\n\n " |
803 . ($this->shouldProxiedMethodReturn($method) ? 'return ' : '') | |
804 . "parent::" . $name . '(' . $callParamsString . ');' | |
801 . "\n" . ' }' . "\n"; | 805 . "\n" . ' }' . "\n"; |
802 } | 806 } |
803 | 807 |
804 return $methods; | 808 return $methods; |
805 } | 809 } |
933 * | 937 * |
934 * @return string|null | 938 * @return string|null |
935 */ | 939 */ |
936 private function getParameterType(ClassMetadata $class, \ReflectionMethod $method, \ReflectionParameter $parameter) | 940 private function getParameterType(ClassMetadata $class, \ReflectionMethod $method, \ReflectionParameter $parameter) |
937 { | 941 { |
938 | 942 if (method_exists($parameter, 'hasType')) { |
939 // We need to pick the type hint class too | 943 if ( ! $parameter->hasType()) { |
944 return ''; | |
945 } | |
946 | |
947 return $this->formatType($parameter->getType(), $parameter->getDeclaringFunction(), $parameter); | |
948 } | |
949 | |
950 // For PHP 5.x, we need to pick the type hint in the old way (to be removed for PHP 7.0+) | |
940 if ($parameter->isArray()) { | 951 if ($parameter->isArray()) { |
941 return 'array'; | 952 return 'array'; |
942 } | 953 } |
943 | 954 |
944 if ($parameter->isCallable()) { | 955 if ($parameter->isCallable()) { |
945 return 'callable'; | 956 return 'callable'; |
946 } | |
947 | |
948 if (method_exists($parameter, 'hasType') && $parameter->hasType() && $parameter->getType()->isBuiltin()) { | |
949 return (string) $parameter->getType(); | |
950 } | 957 } |
951 | 958 |
952 try { | 959 try { |
953 $parameterClass = $parameter->getClass(); | 960 $parameterClass = $parameter->getClass(); |
954 | 961 |
1010 * | 1017 * |
1011 * @return string | 1018 * @return string |
1012 */ | 1019 */ |
1013 private function getMethodReturnType(\ReflectionMethod $method) | 1020 private function getMethodReturnType(\ReflectionMethod $method) |
1014 { | 1021 { |
1015 if (! (method_exists($method, 'hasReturnType') && $method->hasReturnType())) { | 1022 if ( ! method_exists($method, 'hasReturnType') || ! $method->hasReturnType()) { |
1016 return ''; | 1023 return ''; |
1017 } | 1024 } |
1018 | 1025 |
1019 $returnType = $method->getReturnType(); | 1026 return ': ' . $this->formatType($method->getReturnType(), $method); |
1020 | 1027 } |
1021 if ($returnType->isBuiltin()) { | 1028 |
1022 return ': ' . $returnType; | 1029 /** |
1023 } | 1030 * @param \ReflectionMethod $method |
1024 | 1031 * |
1025 $nameLower = strtolower((string) $returnType); | 1032 * @return bool |
1033 */ | |
1034 private function shouldProxiedMethodReturn(\ReflectionMethod $method) | |
1035 { | |
1036 if ( ! method_exists($method, 'hasReturnType') || ! $method->hasReturnType()) { | |
1037 return true; | |
1038 } | |
1039 | |
1040 return 'void' !== strtolower($this->formatType($method->getReturnType(), $method)); | |
1041 } | |
1042 | |
1043 /** | |
1044 * @param \ReflectionType $type | |
1045 * @param \ReflectionMethod $method | |
1046 * @param \ReflectionParameter|null $parameter | |
1047 * | |
1048 * @return string | |
1049 */ | |
1050 private function formatType( | |
1051 \ReflectionType $type, | |
1052 \ReflectionMethod $method, | |
1053 \ReflectionParameter $parameter = null | |
1054 ) { | |
1055 $name = method_exists($type, 'getName') ? $type->getName() : (string) $type; | |
1056 $nameLower = strtolower($name); | |
1026 | 1057 |
1027 if ('self' === $nameLower) { | 1058 if ('self' === $nameLower) { |
1028 return ': \\' . $method->getDeclaringClass()->getName(); | 1059 $name = $method->getDeclaringClass()->getName(); |
1029 } | 1060 } |
1030 | 1061 |
1031 if ('parent' === $nameLower) { | 1062 if ('parent' === $nameLower) { |
1032 return ': \\' . $method->getDeclaringClass()->getParentClass()->getName(); | 1063 $name = $method->getDeclaringClass()->getParentClass()->getName(); |
1033 } | 1064 } |
1034 | 1065 |
1035 return ': \\' . (string) $returnType; | 1066 if ( ! $type->isBuiltin() && ! class_exists($name) && ! interface_exists($name)) { |
1067 if (null !== $parameter) { | |
1068 throw UnexpectedValueException::invalidParameterTypeHint( | |
1069 $method->getDeclaringClass()->getName(), | |
1070 $method->getName(), | |
1071 $parameter->getName() | |
1072 ); | |
1073 } | |
1074 | |
1075 throw UnexpectedValueException::invalidReturnTypeHint( | |
1076 $method->getDeclaringClass()->getName(), | |
1077 $method->getName() | |
1078 ); | |
1079 } | |
1080 | |
1081 if ( ! $type->isBuiltin()) { | |
1082 $name = '\\' . $name; | |
1083 } | |
1084 | |
1085 if ($type->allowsNull() | |
1086 && (null === $parameter || ! $parameter->isDefaultValueAvailable() || null !== $parameter->getDefaultValue()) | |
1087 ) { | |
1088 $name = '?' . $name; | |
1089 } | |
1090 | |
1091 return $name; | |
1036 } | 1092 } |
1037 } | 1093 } |