Make sure the person - document (CNPJ/CPF) already exists

@param $documentNumber
@return string
@throws \GuzzleHttp\Exception\GuzzleException
760382
public function document($documentNumber)
    {
        $data = $this->execute(
            self::HTTP_GET,
            self::DOMUSERP_API_PEDIDOVENDA . '/pessoas/documento',
            ['query' => ['num' => $documentNumber]]
        );

        return $data;
    }
1238954
public static function document($doc, $prepend = false)
    {
        $document = Validation::document($doc);
        if ($document['type'] == 1) {
            return ($prepend ? 'CPF: ' : '') . self::cpf($document['valid']);
        } elseif ($document['type'] == 2) {
            return ($prepend ? 'CNPJ: ' : '') . self::cnpj($document['valid']);
        }
        return $document['valid'] ?? $doc;
    }
1081754
public function getOffsetFor($objectNumber)
    {
        foreach ($this->getReaders() as $reader) {
            $offset = $reader->getOffsetFor($objectNumber);
            if ($offset !== false) {
                return $offset;
            }
        }

        return false;
    }
317642
protected function getDocument($key)
    {
        if (!$this->documentExists($key)) {
            return null;
        }

        return $this->convertDocument($this->documents[$key]);
    }
33896
public function validateCreateDocument()
    {
        $this->_documentMustHavePrimaryData();
        $this->_primaryDataMustHaveType();
        $this->_primaryDataMayHaveUuid();
        $this->_primaryDataMayHaveRelationships();

        if ($this->_errorCollection->count() === 0) {
            return;
        }

        throw new ValidationException($this->_getErrorCollectionEntity());
    }
674408
private static function createInitialDocumentObject($postValues, $documentType)
    {
        $documentObj = new Document();
        $documentObj->title = $postValues['title'];
        $documentObj->slug = StringUtil::slugify($postValues['title']);
        $documentObj->type = 'document';
        $documentObj->documentType = $documentType->title;
        $documentObj->documentTypeSlug = $documentType->slug;
        $documentObj->state = isset($postValues['state']) ? 'published' : 'unpublished';
        $documentObj->lastModificationDate = time();
        $documentObj->creationDate = isset($postValues['creationDate']) ? (int)$postValues['creationDate'] : time();
        $documentObj->lastModifiedBy = $_SESSION['cloudcontrol']->username;

        return $documentObj;
    }
1135758
public function perform($targetDocument)
    {
        $pointer = new Pointer($targetDocument);
        $rootGet = array();
        $value = $this->getValue();

        try {
            $get = $pointer->get($this->getPath());
        } catch (NonexistentValueReferencedException $e) {
            $get = null;
        }

        $pointerParts = $this->getPointerParts();

        $rootPointer = $pointerParts[0];

        if (count($pointerParts) >= 2) {
            try {
                $rootGet = $pointer->get(Pointer::POINTER_CHAR . implode('/', array_slice($pointerParts, 0, -1)));
            } catch (NonexistentValueReferencedException $e) {
                return $targetDocument;
            }
        }

        $targetDocument = json_decode($targetDocument);

        $lastPointerPart = $pointerParts[count($pointerParts) - 1];
        $replacementValue = $this->getReplacementValue();

        if ($get === null && $lastPointerPart !== Pointer::LAST_ARRAY_ELEMENT_CHAR) {
            if (ctype_digit($lastPointerPart) && $lastPointerPart > count($rootGet)) {
                if ($rootPointer == $lastPointerPart && is_array($targetDocument)) {
                    if ((int) $lastPointerPart <= count($targetDocument) + 1) {
                        array_splice($targetDocument, $lastPointerPart, 0, $replacementValue);
                    }
                }
                return json_encode($targetDocument, JSON_UNESCAPED_UNICODE);
            }
            if (count($pointerParts) === 1) {
                if (is_array($targetDocument)) {
                    $targetDocument[$pointerParts[0]] = $value;
                } else {
                    $targetDocument->{$pointerParts[0]} = $value;
                }
            } elseif (count($pointerParts) > 1) {
                $augmentedDocument = &$targetDocument;
                foreach ($pointerParts as $pointerPart) {
                    if (is_array($augmentedDocument)) {
                        $augmentedDocument = &$augmentedDocument[$pointerPart];
                    } else {
                        $augmentedDocument = &$augmentedDocument->{$pointerPart};
                    }
                }
                $augmentedDocument = $value;
            }
        } else {
            $additionIndex = array_pop($pointerParts);
            $arrayEntryPath = '/' . implode('/', $pointerParts);

            try {
                $targetArray = $pointer->get($arrayEntryPath);
            } catch (NonexistentValueReferencedException $e) {
                $targetArray = null;
            }

            if (is_array($targetArray)) {
                if ($lastPointerPart === Pointer::LAST_ARRAY_ELEMENT_CHAR) {
                    $targetArray[] = $value;
                } else {
                    if (is_numeric($additionIndex)) {
                        array_splice($targetArray, $additionIndex, 0, $replacementValue);
                    } else {
                        $targetArray[$additionIndex] = $value;
                    }
                }
            }

            if (is_object($targetArray)) {
                $targetArray->{$additionIndex} = $value;
            }

            if (is_array($targetArray) || is_object($targetArray)) {
                $augmentedDocument = &$targetDocument;
                foreach ($pointerParts as $pointerPart) {
                    if (is_array($augmentedDocument)) {
                        $augmentedDocument = &$augmentedDocument[$pointerPart];
                    } else {
                        $augmentedDocument = &$augmentedDocument->{$pointerPart};
                    }
                }
                $augmentedDocument = $targetArray;
            }

            if ($targetArray === null) {
                if (is_numeric($additionIndex) && count($targetDocument) > 0) {
                    array_splice($targetDocument, $additionIndex, 0, $replacementValue);
                } else {
                    $targetDocument->{$additionIndex} = $value;
                }
            }
        }

        return json_encode($targetDocument, JSON_UNESCAPED_UNICODE);
    }
195989
public function getLinksCount($pageNumber)
    {

        $strURI = Product::$baseProductUri . '/pdf/' . $this->getFileName() . '/pages/' . $pageNumber . '/links';
        $signedURI = Utils::sign($strURI);
        $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
        $json = json_decode($responseStream);
        return count($json->Links->List);
    }
1102273
public function setDocumentFileName($documentFileName)
    {
        $this->documentFileName = $documentFileName;

        if ($documentFileName) {
            $this->setDocument('/uploads/documents/'.$documentFileName);
            if ( ! $this->link) {
                $this->link = '/uploads/documents/'.$documentFileName;
            }
        } else {
            // Remove deleted file from database
            if ($this->link == $this->document) {
                $this->link = null;
            }
            $this->setDocument(null);
        }

        return $this;
    }
1368068
public function enableShardingForDbByDocumentName($documentName)
    {
        $dbName = $this->dm->getDocumentDatabase($documentName)->getName();
        $adminDb = $this->dm->getConnection()->selectDatabase('admin');
        $result = $adminDb->command(array('enableSharding' => $dbName));

        if ($result['ok'] != 1 && $result['errmsg'] !== 'already enabled') {
            throw MongoDBException::failedToEnableSharding($dbName, $result['errmsg']);
        }
    }
1140024
public static function newDocument($path = '/', $documentType = '')
    {
        if (self::isLoggedIn()) {
            $return = self::getAssetsIfNotIncluded();
            return $return . '<a title="New Document" data-href="' . self::newDocumentLink($path,
                    $documentType) . '" class="ccEditDocumentButton ccNewDocumentButton"></a>';
        } else {
            return '';
        }
    }
635559
public function normalizePageNumber($pageNumber)
    {
        $pageNumber = (int) $pageNumber;

        if ($pageNumber < 1) {
            $pageNumber = 1;
        }

        $pageCount = $this->count();

        if ($pageCount > 0 && $pageNumber > $pageCount) {
            $pageNumber = $pageCount;
        }

        return $pageNumber;
    }
436353
private int getNumDoc(String docID) {
    if (goneContext != null ) {
      removeDoc(docID);
    }
    for (int i = 0; i < documents.size(); i++) {
      if (documents.get(i).getDocID().equals(docID)) {  //  document exist
        if(!testMode && documents.get(i).getXComponent() == null) {
          XComponent xComponent = OfficeTools.getCurrentComponent(xContext);
          if (xComponent == null) {
            MessageHandler.printToLogFile("Error: Document (ID: " + docID + ") has no XComponent -> Internal space will not be deleted when document disposes");
          } else {
            try {
              xComponent.addEventListener(xEventListener);
            } catch (Throwable t) {
              MessageHandler.printToLogFile("Error: Document (ID: " + docID + ") has no XComponent -> Internal space will not be deleted when document disposes");
              xComponent = null;
            }
            if(xComponent != null) {
              documents.get(i).setXComponent(xContext, xComponent);
              MessageHandler.printToLogFile("Fixed: XComponent set for Document (ID: " + docID + ")");
            }
          }
        }
        return i;
      }
    }
    //  Add new document
    XComponent xComponent = null;
    if (!testMode) {              //  xComponent == null for test cases 
      xComponent = OfficeTools.getCurrentComponent(xContext);
      if (xComponent == null) {
        MessageHandler.printToLogFile("Error: Document (ID: " + docID + ") has no XComponent -> Internal space will not be deleted when document disposes");
      } else {
        try {
          xComponent.addEventListener(xEventListener);
        } catch (Throwable t) {
          MessageHandler.printToLogFile("Error: Document (ID: " + docID + ") has no XComponent -> Internal space will not be deleted when document disposes");
          xComponent = null;
        }
      }
    }
    documents.add(new SingleDocument(xContext, config, docID, xComponent));
    setMenuTextForSwitchOff(xContext);
    if (debugMode) {
      MessageHandler.printToLogFile("Document " + docNum + " created; docID = " + docID);
    }
    return documents.size() - 1;
  }
560961
public static function checkPhoneNumber($phoneNumber) {
        $phoneNumber = self::cleanPhoneNumber($phoneNumber);

        if (!empty($phoneNumber) && strlen($phoneNumber) > self::$_inputFldMaxLength['PhoneNumber']) {
            $errorMessage = 'The value for phone number can be no more than ' . self::$_inputFldMaxLength['PhoneNumber'] . ' characters, Please try again after making corrections';
            throw new HpsInvalidRequestException(
            HpsExceptionCodes::INVALID_PHONE_NUMBER, $errorMessage
            );
        }
        return $phoneNumber;
    }
202614
public function generate(DocumentManager $dm, object $document)
    {
        $uuid = $this->generateV4();
        return $this->generateV5($uuid, $this->salt ?: php_uname('n'));
    }
1345012
public function setDocumento($documento)
    {
        $documento = substr(Util::onlyNumbers($documento), -14);
        if (!in_array(strlen($documento), [10, 11, 14, 0])) {
            throw new \Exception('Documento inválido');
        }
        $this->documento = $documento;
    }
377480
public function getDocument($input)
    {
        $nodeMap = new JsonObject();
        $nodeMap->{'-' . JsonLD::DEFAULT_GRAPH} = new JsonObject();
        $this->generateNodeMap($nodeMap, $input);

        // We need to keep track of blank nodes as they are renamed when
        // inserted into the Document
        $nodes = array();

        if (null === $this->documentFactory) {
            $this->documentFactory = new DefaultDocumentFactory();
        }

        $document = $this->documentFactory->createDocument($this->baseIri);

        foreach ($nodeMap as $graphName => &$nodes) {
            $graphName = substr($graphName, 1);
            if (JsonLD::DEFAULT_GRAPH === $graphName) {
                $graph = $document->getGraph();
            } else {
                $graph = $document->createGraph($graphName);
            }

            foreach ($nodes as $id => &$item) {
                $node = $graph->createNode($item->{'@id'}, true);
                unset($item->{'@id'});

                // Process node type as it needs to be handled differently than
                // other properties
                // TODO Could this be avoided by enforcing rdf:type instead of @type?
                if (property_exists($item, '@type')) {
                    foreach ($item->{'@type'} as $type) {
                        $node->addType($graph->createNode($type), true);
                    }
                    unset($item->{'@type'});
                }

                foreach ($item as $property => $values) {
                    foreach ($values as $value) {
                        if (property_exists($value, '@value')) {
                            $node->addPropertyValue($property, Value::fromJsonLd($value));
                        } elseif (property_exists($value, '@id')) {
                            $node->addPropertyValue(
                                $property,
                                $graph->createNode($value->{'@id'}, true)
                            );
                        } else {
                            // TODO Handle lists
                            throw new \Exception('Lists are not supported by getDocument() yet');
                        }
                    }
                }
            }
        }


        unset($nodeMap);

        return $document;
    }