How to use getPromise method of or class

Best Prophecy code snippet using or.getPromise

ReferenceExecutor.php

Source:ReferenceExecutor.php Github

copy

Full Screen

...444 $result = $this->resolveField($parentType, $sourceValue, $fieldNodes, $fieldPath);445 if ($result === self::$UNDEFINED) {446 return $results;447 }448 $promise = $this->getPromise($result);449 if ($promise) {450 return $promise->then(static function ($resolvedResult) use ($responseName, $results) {451 $results[$responseName] = $resolvedResult;452 return $results;453 });454 }455 $results[$responseName] = $result;456 return $results;457 },458 []459 );460 if ($this->isPromise($result)) {461 return $result->then(static function ($resolvedResults) {462 return self::fixResultsIfEmptyArray($resolvedResults);463 });464 }465 return self::fixResultsIfEmptyArray($result);466 }467 /**468 * Resolves the field on the given source object. In particular, this469 * figures out the value that the field returns by calling its resolve function,470 * then calls completeValue to complete promises, serialize scalars, or execute471 * the sub-selection-set for objects.472 *473 * @param object|null $source474 * @param FieldNode[] $fieldNodes475 * @param mixed[] $path476 *477 * @return mixed[]|Exception|mixed|null478 */479 private function resolveField(ObjectType $parentType, $source, $fieldNodes, $path)480 {481 $exeContext = $this->exeContext;482 $fieldNode = $fieldNodes[0];483 $fieldName = $fieldNode->name->value;484 $fieldDef = $this->getFieldDef($exeContext->schema, $parentType, $fieldName);485 if (! $fieldDef) {486 return self::$UNDEFINED;487 }488 $returnType = $fieldDef->getType();489 // The resolve function's optional third argument is a collection of490 // information about the current execution state.491 $info = new ResolveInfo(492 $fieldName,493 $fieldNodes,494 $returnType,495 $parentType,496 $path,497 $exeContext->schema,498 $exeContext->fragments,499 $exeContext->rootValue,500 $exeContext->operation,501 $exeContext->variableValues502 );503 if ($fieldDef->resolveFn !== null) {504 $resolveFn = $fieldDef->resolveFn;505 } elseif ($parentType->resolveFieldFn !== null) {506 $resolveFn = $parentType->resolveFieldFn;507 } else {508 $resolveFn = $this->exeContext->fieldResolver;509 }510 // The resolve function's optional third argument is a context value that511 // is provided to every resolve function within an execution. It is commonly512 // used to represent an authenticated user, or request-specific caches.513 $context = $exeContext->contextValue;514 // Get the resolve function, regardless of if its result is normal515 // or abrupt (error).516 $result = $this->resolveOrError(517 $fieldDef,518 $fieldNode,519 $resolveFn,520 $source,521 $context,522 $info523 );524 $result = $this->completeValueCatchingError(525 $returnType,526 $fieldNodes,527 $info,528 $path,529 $result530 );531 return $result;532 }533 /**534 * This method looks up the field on the given type definition.535 * It has special casing for the two introspection fields, __schema536 * and __typename. __typename is special because it can always be537 * queried as a field, even in situations where no other fields538 * are allowed, like on a Union. __schema could get automatically539 * added to the query type, but that would require mutating type540 * definitions, which would cause issues.541 *542 * @param string $fieldName543 *544 * @return FieldDefinition545 */546 private function getFieldDef(Schema $schema, ObjectType $parentType, $fieldName)547 {548 static $schemaMetaFieldDef, $typeMetaFieldDef, $typeNameMetaFieldDef;549 $schemaMetaFieldDef = $schemaMetaFieldDef ?: Introspection::schemaMetaFieldDef();550 $typeMetaFieldDef = $typeMetaFieldDef ?: Introspection::typeMetaFieldDef();551 $typeNameMetaFieldDef = $typeNameMetaFieldDef ?: Introspection::typeNameMetaFieldDef();552 if ($fieldName === $schemaMetaFieldDef->name && $schema->getQueryType() === $parentType) {553 return $schemaMetaFieldDef;554 }555 if ($fieldName === $typeMetaFieldDef->name && $schema->getQueryType() === $parentType) {556 return $typeMetaFieldDef;557 }558 if ($fieldName === $typeNameMetaFieldDef->name) {559 return $typeNameMetaFieldDef;560 }561 $tmp = $parentType->getFields();562 return $tmp[$fieldName] ?? null;563 }564 /**565 * Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`566 * function. Returns the result of resolveFn or the abrupt-return Error object.567 *568 * @param FieldDefinition $fieldDef569 * @param FieldNode $fieldNode570 * @param callable $resolveFn571 * @param mixed $source572 * @param mixed $context573 * @param ResolveInfo $info574 *575 * @return Throwable|Promise|mixed576 */577 private function resolveOrError($fieldDef, $fieldNode, $resolveFn, $source, $context, $info)578 {579 try {580 // Build hash of arguments from the field.arguments AST, using the581 // variables scope to fulfill any variable references.582 $args = Values::getArgumentValues(583 $fieldDef,584 $fieldNode,585 $this->exeContext->variableValues586 );587 return $resolveFn($source, $args, $context, $info);588 } catch (Exception $error) {589 return $error;590 } catch (Throwable $error) {591 return $error;592 }593 }594 /**595 * This is a small wrapper around completeValue which detects and logs errors596 * in the execution context.597 *598 * @param FieldNode[] $fieldNodes599 * @param string[] $path600 * @param mixed $result601 *602 * @return mixed[]|Promise|null603 */604 private function completeValueCatchingError(605 Type $returnType,606 $fieldNodes,607 ResolveInfo $info,608 $path,609 $result610 ) {611 $exeContext = $this->exeContext;612 // If the field type is non-nullable, then it is resolved without any613 // protection from errors.614 if ($returnType instanceof NonNull) {615 return $this->completeValueWithLocatedError(616 $returnType,617 $fieldNodes,618 $info,619 $path,620 $result621 );622 }623 // Otherwise, error protection is applied, logging the error and resolving624 // a null value for this field if one is encountered.625 try {626 $completed = $this->completeValueWithLocatedError(627 $returnType,628 $fieldNodes,629 $info,630 $path,631 $result632 );633 $promise = $this->getPromise($completed);634 if ($promise) {635 return $promise->then(636 null,637 function ($error) use ($exeContext) {638 $exeContext->addError($error);639 return $this->exeContext->promises->createFulfilled(null);640 }641 );642 }643 return $completed;644 } catch (Error $err) {645 // If `completeValueWithLocatedError` returned abruptly (threw an error), log the error646 // and return null.647 $exeContext->addError($err);648 return null;649 }650 }651 /**652 * This is a small wrapper around completeValue which annotates errors with653 * location information.654 *655 * @param FieldNode[] $fieldNodes656 * @param string[] $path657 * @param mixed $result658 *659 * @return mixed[]|mixed|Promise|null660 *661 * @throws Error662 */663 public function completeValueWithLocatedError(664 Type $returnType,665 $fieldNodes,666 ResolveInfo $info,667 $path,668 $result669 ) {670 try {671 $completed = $this->completeValue(672 $returnType,673 $fieldNodes,674 $info,675 $path,676 $result677 );678 $promise = $this->getPromise($completed);679 if ($promise) {680 return $promise->then(681 null,682 function ($error) use ($fieldNodes, $path) {683 return $this->exeContext->promises->createRejected(Error::createLocatedError(684 $error,685 $fieldNodes,686 $path687 ));688 }689 );690 }691 return $completed;692 } catch (Exception $error) {693 throw Error::createLocatedError($error, $fieldNodes, $path);694 } catch (Throwable $error) {695 throw Error::createLocatedError($error, $fieldNodes, $path);696 }697 }698 /**699 * Implements the instructions for completeValue as defined in the700 * "Field entries" section of the spec.701 *702 * If the field type is Non-Null, then this recursively completes the value703 * for the inner type. It throws a field error if that completion returns null,704 * as per the "Nullability" section of the spec.705 *706 * If the field type is a List, then this recursively completes the value707 * for the inner type on each item in the list.708 *709 * If the field type is a Scalar or Enum, ensures the completed value is a legal710 * value of the type by calling the `serialize` method of GraphQL type711 * definition.712 *713 * If the field is an abstract type, determine the runtime type of the value714 * and then complete based on that type715 *716 * Otherwise, the field type expects a sub-selection set, and will complete the717 * value by evaluating all sub-selections.718 *719 * @param FieldNode[] $fieldNodes720 * @param string[] $path721 * @param mixed $result722 *723 * @return mixed[]|mixed|Promise|null724 *725 * @throws Error726 * @throws Throwable727 */728 private function completeValue(729 Type $returnType,730 $fieldNodes,731 ResolveInfo $info,732 $path,733 &$result734 ) {735 $promise = $this->getPromise($result);736 // If result is a Promise, apply-lift over completeValue.737 if ($promise) {738 return $promise->then(function (&$resolved) use ($returnType, $fieldNodes, $info, $path) {739 return $this->completeValue($returnType, $fieldNodes, $info, $path, $resolved);740 });741 }742 if ($result instanceof Exception || $result instanceof Throwable) {743 throw $result;744 }745 // If field type is NonNull, complete for inner type, and throw field error746 // if result is null.747 if ($returnType instanceof NonNull) {748 $completed = $this->completeValue(749 $returnType->getWrappedType(),750 $fieldNodes,751 $info,752 $path,753 $result754 );755 if ($completed === null) {756 throw new InvariantViolation(757 'Cannot return null for non-nullable field ' . $info->parentType . '.' . $info->fieldName . '.'758 );759 }760 return $completed;761 }762 // If result is null-like, return null.763 if ($result === null) {764 return null;765 }766 // If field type is List, complete each item in the list with the inner type767 if ($returnType instanceof ListOfType) {768 return $this->completeListValue($returnType, $fieldNodes, $info, $path, $result);769 }770 // Account for invalid schema definition when typeLoader returns different771 // instance than `resolveType` or $field->getType() or $arg->getType()772 if ($returnType !== $this->exeContext->schema->getType($returnType->name)) {773 $hint = '';774 if ($this->exeContext->schema->getConfig()->typeLoader) {775 $hint = sprintf(776 'Make sure that type loader returns the same instance as defined in %s.%s',777 $info->parentType,778 $info->fieldName779 );780 }781 throw new InvariantViolation(782 sprintf(783 'Schema must contain unique named types but contains multiple types named "%s". %s ' .784 '(see http://webonyx.github.io/graphql-php/type-system/#type-registry).',785 $returnType,786 $hint787 )788 );789 }790 // If field type is Scalar or Enum, serialize to a valid value, returning791 // null if serialization is not possible.792 if ($returnType instanceof LeafType) {793 return $this->completeLeafValue($returnType, $result);794 }795 if ($returnType instanceof AbstractType) {796 return $this->completeAbstractValue($returnType, $fieldNodes, $info, $path, $result);797 }798 // Field type must be Object, Interface or Union and expect sub-selections.799 if ($returnType instanceof ObjectType) {800 return $this->completeObjectValue($returnType, $fieldNodes, $info, $path, $result);801 }802 throw new RuntimeException(sprintf('Cannot complete value of unexpected type "%s".', $returnType));803 }804 /**805 * @param mixed $value806 *807 * @return bool808 */809 private function isPromise($value)810 {811 return $value instanceof Promise || $this->exeContext->promises->isThenable($value);812 }813 /**814 * Only returns the value if it acts like a Promise, i.e. has a "then" function,815 * otherwise returns null.816 *817 * @param mixed $value818 *819 * @return Promise|null820 */821 private function getPromise($value)822 {823 if ($value === null || $value instanceof Promise) {824 return $value;825 }826 if ($this->exeContext->promises->isThenable($value)) {827 $promise = $this->exeContext->promises->convertThenable($value);828 if (! $promise instanceof Promise) {829 throw new InvariantViolation(sprintf(830 '%s::convertThenable is expected to return instance of GraphQL\Executor\Promise\Promise, got: %s',831 get_class($this->exeContext->promises),832 Utils::printSafe($promise)833 ));834 }835 return $promise;836 }837 return null;838 }839 /**840 * Similar to array_reduce(), however the reducing callback may return841 * a Promise, in which case reduction will continue after each promise resolves.842 *843 * If the callback does not return a Promise, then this function will also not844 * return a Promise.845 *846 * @param mixed[] $values847 * @param Promise|mixed|null $initialValue848 *849 * @return mixed[]850 */851 private function promiseReduce(array $values, callable $callback, $initialValue)852 {853 return array_reduce(854 $values,855 function ($previous, $value) use ($callback) {856 $promise = $this->getPromise($previous);857 if ($promise) {858 return $promise->then(static function ($resolved) use ($callback, $value) {859 return $callback($resolved, $value);860 });861 }862 return $callback($previous, $value);863 },864 $initialValue865 );866 }867 /**868 * Complete a list value by completing each item in the list with the869 * inner type870 *871 * @param FieldNode[] $fieldNodes872 * @param mixed[] $path873 * @param mixed $result874 *875 * @return mixed[]|Promise876 *877 * @throws Exception878 */879 private function completeListValue(ListOfType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)880 {881 $itemType = $returnType->getWrappedType();882 Utils::invariant(883 is_array($result) || $result instanceof Traversable,884 'User Error: expected iterable, but did not find one for field ' . $info->parentType . '.' . $info->fieldName . '.'885 );886 $containsPromise = false;887 $i = 0;888 $completedItems = [];889 foreach ($result as $item) {890 $fieldPath = $path;891 $fieldPath[] = $i++;892 $completedItem = $this->completeValueCatchingError($itemType, $fieldNodes, $info, $fieldPath, $item);893 if (! $containsPromise && $this->getPromise($completedItem)) {894 $containsPromise = true;895 }896 $completedItems[] = $completedItem;897 }898 return $containsPromise ? $this->exeContext->promises->all($completedItems) : $completedItems;899 }900 /**901 * Complete a Scalar or Enum by serializing to a valid value, throwing if serialization is not possible.902 *903 * @param mixed $result904 *905 * @return mixed906 *907 * @throws Exception908 */909 private function completeLeafValue(LeafType $returnType, &$result)910 {911 try {912 return $returnType->serialize($result);913 } catch (Exception $error) {914 throw new InvariantViolation(915 'Expected a value of type "' . Utils::printSafe($returnType) . '" but received: ' . Utils::printSafe($result),916 0,917 $error918 );919 } catch (Throwable $error) {920 throw new InvariantViolation(921 'Expected a value of type "' . Utils::printSafe($returnType) . '" but received: ' . Utils::printSafe($result),922 0,923 $error924 );925 }926 }927 /**928 * Complete a value of an abstract type by determining the runtime object type929 * of that value, then complete the value for that type.930 *931 * @param FieldNode[] $fieldNodes932 * @param mixed[] $path933 * @param mixed[] $result934 *935 * @return mixed936 *937 * @throws Error938 */939 private function completeAbstractValue(AbstractType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)940 {941 $exeContext = $this->exeContext;942 $runtimeType = $returnType->resolveType($result, $exeContext->contextValue, $info);943 if ($runtimeType === null) {944 $runtimeType = self::defaultTypeResolver($result, $exeContext->contextValue, $info, $returnType);945 }946 $promise = $this->getPromise($runtimeType);947 if ($promise) {948 return $promise->then(function ($resolvedRuntimeType) use (949 $returnType,950 $fieldNodes,951 $info,952 $path,953 &$result954 ) {955 return $this->completeObjectValue(956 $this->ensureValidRuntimeType(957 $resolvedRuntimeType,958 $returnType,959 $info,960 $result961 ),962 $fieldNodes,963 $info,964 $path,965 $result966 );967 });968 }969 return $this->completeObjectValue(970 $this->ensureValidRuntimeType(971 $runtimeType,972 $returnType,973 $info,974 $result975 ),976 $fieldNodes,977 $info,978 $path,979 $result980 );981 }982 /**983 * If a resolveType function is not given, then a default resolve behavior is984 * used which attempts two strategies:985 *986 * First, See if the provided value has a `__typename` field defined, if so, use987 * that value as name of the resolved type.988 *989 * Otherwise, test each possible type for the abstract type by calling990 * isTypeOf for the object being coerced, returning the first type that matches.991 *992 * @param mixed|null $value993 * @param mixed|null $context994 *995 * @return ObjectType|Promise|null996 */997 private function defaultTypeResolver($value, $context, ResolveInfo $info, AbstractType $abstractType)998 {999 // First, look for `__typename`.1000 if ($value !== null &&1001 (is_array($value) || $value instanceof ArrayAccess) &&1002 isset($value['__typename']) &&1003 is_string($value['__typename'])1004 ) {1005 return $value['__typename'];1006 }1007 if ($abstractType instanceof InterfaceType && $info->schema->getConfig()->typeLoader) {1008 Warning::warnOnce(1009 sprintf(1010 'GraphQL Interface Type `%s` returned `null` from its `resolveType` function ' .1011 'for value: %s. Switching to slow resolution method using `isTypeOf` ' .1012 'of all possible implementations. It requires full schema scan and degrades query performance significantly. ' .1013 ' Make sure your `resolveType` always returns valid implementation or throws.',1014 $abstractType->name,1015 Utils::printSafe($value)1016 ),1017 Warning::WARNING_FULL_SCHEMA_SCAN1018 );1019 }1020 // Otherwise, test each possible type.1021 $possibleTypes = $info->schema->getPossibleTypes($abstractType);1022 $promisedIsTypeOfResults = [];1023 foreach ($possibleTypes as $index => $type) {1024 $isTypeOfResult = $type->isTypeOf($value, $context, $info);1025 if ($isTypeOfResult === null) {1026 continue;1027 }1028 $promise = $this->getPromise($isTypeOfResult);1029 if ($promise) {1030 $promisedIsTypeOfResults[$index] = $promise;1031 } elseif ($isTypeOfResult) {1032 return $type;1033 }1034 }1035 if (! empty($promisedIsTypeOfResults)) {1036 return $this->exeContext->promises->all($promisedIsTypeOfResults)1037 ->then(static function ($isTypeOfResults) use ($possibleTypes) {1038 foreach ($isTypeOfResults as $index => $result) {1039 if ($result) {1040 return $possibleTypes[$index];1041 }1042 }1043 return null;1044 });1045 }1046 return null;1047 }1048 /**1049 * Complete an Object value by executing all sub-selections.1050 *1051 * @param FieldNode[] $fieldNodes1052 * @param mixed[] $path1053 * @param mixed $result1054 *1055 * @return mixed[]|Promise|stdClass1056 *1057 * @throws Error1058 */1059 private function completeObjectValue(ObjectType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)1060 {1061 // If there is an isTypeOf predicate function, call it with the1062 // current result. If isTypeOf returns false, then raise an error rather1063 // than continuing execution.1064 $isTypeOf = $returnType->isTypeOf($result, $this->exeContext->contextValue, $info);1065 if ($isTypeOf !== null) {1066 $promise = $this->getPromise($isTypeOf);1067 if ($promise) {1068 return $promise->then(function ($isTypeOfResult) use (1069 $returnType,1070 $fieldNodes,1071 $path,1072 &$result1073 ) {1074 if (! $isTypeOfResult) {1075 throw $this->invalidReturnTypeError($returnType, $result, $fieldNodes);1076 }1077 return $this->collectAndExecuteSubfields(1078 $returnType,1079 $fieldNodes,1080 $path,1081 $result1082 );1083 });1084 }1085 if (! $isTypeOf) {1086 throw $this->invalidReturnTypeError($returnType, $result, $fieldNodes);1087 }1088 }1089 return $this->collectAndExecuteSubfields(1090 $returnType,1091 $fieldNodes,1092 $path,1093 $result1094 );1095 }1096 /**1097 * @param mixed[] $result1098 * @param FieldNode[] $fieldNodes1099 *1100 * @return Error1101 */1102 private function invalidReturnTypeError(1103 ObjectType $returnType,1104 $result,1105 $fieldNodes1106 ) {1107 return new Error(1108 'Expected value of type "' . $returnType->name . '" but got: ' . Utils::printSafe($result) . '.',1109 $fieldNodes1110 );1111 }1112 /**1113 * @param FieldNode[] $fieldNodes1114 * @param mixed[] $path1115 * @param mixed[] $result1116 *1117 * @return mixed[]|Promise|stdClass1118 *1119 * @throws Error1120 */1121 private function collectAndExecuteSubfields(1122 ObjectType $returnType,1123 $fieldNodes,1124 $path,1125 &$result1126 ) {1127 $subFieldNodes = $this->collectSubFields($returnType, $fieldNodes);1128 return $this->executeFields($returnType, $result, $path, $subFieldNodes);1129 }1130 private function collectSubFields(ObjectType $returnType, $fieldNodes) : ArrayObject1131 {1132 if (! isset($this->subFieldCache[$returnType])) {1133 $this->subFieldCache[$returnType] = new SplObjectStorage();1134 }1135 if (! isset($this->subFieldCache[$returnType][$fieldNodes])) {1136 // Collect sub-fields to execute to complete this value.1137 $subFieldNodes = new ArrayObject();1138 $visitedFragmentNames = new ArrayObject();1139 foreach ($fieldNodes as $fieldNode) {1140 if (! isset($fieldNode->selectionSet)) {1141 continue;1142 }1143 $subFieldNodes = $this->collectFields(1144 $returnType,1145 $fieldNode->selectionSet,1146 $subFieldNodes,1147 $visitedFragmentNames1148 );1149 }1150 $this->subFieldCache[$returnType][$fieldNodes] = $subFieldNodes;1151 }1152 return $this->subFieldCache[$returnType][$fieldNodes];1153 }1154 /**1155 * Implements the "Evaluating selection sets" section of the spec1156 * for "read" mode.1157 *1158 * @param mixed|null $source1159 * @param mixed[] $path1160 * @param ArrayObject $fields1161 *1162 * @return Promise|stdClass|mixed[]1163 */1164 private function executeFields(ObjectType $parentType, $source, $path, $fields)1165 {1166 $containsPromise = false;1167 $finalResults = [];1168 foreach ($fields as $responseName => $fieldNodes) {1169 $fieldPath = $path;1170 $fieldPath[] = $responseName;1171 $result = $this->resolveField($parentType, $source, $fieldNodes, $fieldPath);1172 if ($result === self::$UNDEFINED) {1173 continue;1174 }1175 if (! $containsPromise && $this->getPromise($result)) {1176 $containsPromise = true;1177 }1178 $finalResults[$responseName] = $result;1179 }1180 // If there are no promises, we can just return the object1181 if (! $containsPromise) {1182 return self::fixResultsIfEmptyArray($finalResults);1183 }1184 // Otherwise, results is a map from field name to the result1185 // of resolving that field, which is possibly a promise. Return1186 // a promise that will return this same map, but with any1187 // promises replaced with the values they resolved to.1188 return $this->promiseForAssocArray($finalResults);1189 }...

Full Screen

Full Screen

Statement.php

Source:Statement.php Github

copy

Full Screen

...138 }139 /**140 * @return Promise A promise object that allow to decouple your execution from async execution141 */142 public function getPromise()143 {144 return $this->promise;145 }146 /**147 * Get service result if define148 *149 * @return mixed150 *151 * @throws \Symfony\Component\HttpKernel\Exception\HttpException152 */153 public function getResult()154 {155 if (!$this->getResponse() && !$this->hasError()) {156 throw new RequestNotSentException($this->request, "Request has not been sent yet");157 }158 if (!$this->hasError()) {159 return $this->getResponse()->getResult();160 } else {161 throw $this->getError();162 }163 }164 /**165 * @return EventDispatcherInterface event dispatcher for internal http transactions events166 */167 public function getEventDispatcher()168 {169 return $this->eventDispatcher;170 }171 /**172 * Set value for $request173 *174 * @param Request $value value to set to request175 * @return Object instance for method chaining176 */177 protected function setRequest(Request $value)178 {179 $this->request = $value;180 return $this;181 }182 /**183 * Get value for $request184 * @return Request Service Request185 */186 public function getRequest()187 {188 return $this->request;189 }190 /**191 * Set value for $response192 *193 * @param Response $response value to set to response194 * @return Object instance for method chaining195 */196 public function setResponse(Response $response)197 {198 $this->response = $response;199 if ($this->response->hasError()) {200 $this->setError($this->response->getError());201 } else {202 $this->deferred->resolve($response->getResult());203 }204 return $this;205 }206 /**207 * @param string $json a json string, if omitted, request params will be used to built json string208 * @return self209 */210 public function json($json = null)211 {212 $this->request->headers->set('content-type', 'application/json');213 $this->request->headers->set('charset', 'utf-8');214 $this->request->headers->set('accept', 'application/json');215 if ($this->request->getMethod() !== "GET") {216 $requestPayload = $this->request->request->all();217 if (func_num_args() === 0) {218 if (empty($requestPayload)) {219 $requestPayload = (object) $requestPayload;220 }221 $json = json_encode($requestPayload);222 } elseif (is_string($json)) {223 $json = (string) $json;224 } else {225 $json = json_encode(null);226 }227 $this->request->setContent($json);228 }229 return $this;230 }231 /**232 * Get value for $response233 * @return Response Service response234 */235 public function getResponse()236 {237 return $this->response;238 }239 /**240 * Set value for $error241 *242 * @param HttpException $value value to set to error243 * @return Object instance for method chaining244 */245 public function setError(HttpException $value)246 {247 $this->error = $value;248 $this->deferred->reject($this->error);249 return $this;250 }251 /**252 * Get value for $error253 * @return HttpException Error254 */255 public function getError()256 {257 return $this->error;258 }259 /**260 * If service has error261 *262 * @return boolean true if has error, false otherwise263 */264 public function hasError()265 {266 return (bool)$this->error;267 }268 /**269 * Get unique id for this service270 * @return string string representation of current service271 */272 public function getUid()273 {274 return md5(spl_object_hash($this));275 }276 /**277 * @param Kernel $httpKernel278 * @return mixed279 * @throws Error280 * @throws Exception281 */282 public function execute(Kernel $httpKernel = null)283 {284 $this->sent = true;285 $http = $httpKernel ? $httpKernel : $this->httpKernel;286 $http->execute([$this]);287 if ($this->hasError()) {288 throw $this->getError();289 }290 return $this;291 }292 /**293 * @return boolean294 */295 public function isSent()296 {297 return $this->sent;298 }299 /**300 * @param boolean $sent301 */302 public function setSent($sent)303 {304 $this->sent = $sent;305 }306 /**307 * @param string $key multi-part form item key name308 * @param string $filepath path to file309 * @param string|null $mimetype file mimetype, if none provided, will be guess from filepath310 * @param string|null $clientName optionnal client filename, if none provided, basename of filepath will be used311 */312 public function attachFile($key, $filepath, $mimetype = null, $clientName = null)313 {314 $clientName = $clientName ? $clientName : basename($filepath);315 $file = new File($filepath, true);316 $file = new UploadedFile(317 $file->getRealPath(),318 $clientName,319 $file->getMimeType(),320 0);321 $this->getRequest()->files->set($key, $file);322 }323 /**324 * A callbackto call on completed transaction, ethier on success or failure325 *326 * @param callable $callable callable proxyied to getPromise()->then($callable) to call on completed transaction, ethier on success or failure327 * @return self328 */329 public function onSuccess(callable $callable)330 {331 $this->getPromise()->then($callable);332 return $this;333 }334 /**335 * Assign a callback on error336 *337 * @param callable $callable callable proxyied to getPromise()->otherwise($callable) to call on completed transaction, ethier on success or failure338 * @return self339 */340 public function onError(callable $callable)341 {342 $this->getPromise()->then(null, $callable);343 return $this;344 }345 /**346 * Assign a callback on progress notification347 *348 * @param callable $callable callable proxyied to getPromise()->progress($callable) to call on completed transaction, ethier on success or failure349 * @return self350 */351 public function onProgress(callable $callable)352 {353 $this->getPromise()->then(null, null, $callable);354 return $this;355 }356 /**357 * Assign a callback to on completed transaction, ethier on success or failure358 *359 * @param callable $callable callable proxyied to getPromise()->then($callable) to call on completed transaction, ethier on success or failure360 * @return self361 */362 public function onFinish(callable $callable)363 {364 $this->getPromise()->always($callable);365 return $this;366 }367 /**368 * @param string $consumerKey369 * @param string $consumerSecret370 */371 public function authorizeOAuth($consumerKey, $consumerSecret)372 {373 return $this;374 }375 /**376 * @param string $key The key377 * @param string|array $values The value or an array of values378 * @param bool $replace Whether to replace the actual value or not (true by default)...

Full Screen

Full Screen

getPromise

Using AI Code Generation

copy

Full Screen

1$or = new or();2$or->getPromise();3$or = new or();4$or->getPromise();5$or = new or();6$or->getPromise();7$or = new or();8$or->getPromise();9$or = new or();10$or->getPromise();11$or = new or();12$or->getPromise();13$or = new or();14$or->getPromise();15$or = new or();16$or->getPromise();17$or = new or();18$or->getPromise();19$or = new or();20$or->getPromise();21$or = new or();22$or->getPromise();23$or = new or();24$or->getPromise();25$or = new or();26$or->getPromise();27$or = new or();28$or->getPromise();29$or = new or();30$or->getPromise();31$or = new or();32$or->getPromise();33$or = new or();34$or->getPromise();

Full Screen

Full Screen

getPromise

Using AI Code Generation

copy

Full Screen

1$or = new OrClass();2$promises = $or->getPromise();3$and = new AndClass();4$promises = $and->getPromise();5$xor = new XorClass();6$promises = $xor->getPromise();7 (8 (9 (10 (11 (12 (13 (14 (15 (

Full Screen

Full Screen

getPromise

Using AI Code Generation

copy

Full Screen

1require_once 'or.php';2$or = new or();3$or->getPromise();4{5 public function getPromise()6 {7 $promise = new Promise();8 $promise->then(function ($value) {9 echo $value;10 });11 $promise->resolve("Hello World");12 }13}14{15 private $callback;16 public function then($callback)17 {18 $this->callback = $callback;19 }20 public function resolve($value)21 {22 $callback = $this->callback;23 $callback($value);24 }25}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Prophecy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger getPromise code on LambdaTest Cloud Grid

Execute automation tests with getPromise on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful